Skip to content

An error occurred when executing stop. #50

@mori-chi

Description

@mori-chi

Describe the bug

The following error occurred when executing stop.
* googleapi: Error 400: Labels could not be set due to fingerprint mismatch; try again with the proper fingerprint: incorrect fingerprint supplied was "", the expected one is "1f7027a2"., failedPrecondition

To Reproduce

When {"command": "stop"} is published in Pub/Sub.

Known workaround

Modify the code.
operator/gke.go

func SetLabelNodePoolSize(ctx context.Context, projectID string, targetLabel string) error {
	s, err := container.NewService(ctx)
	if err != nil {
		return err
	}
	// get all clusters list
	clusters, err := container.NewProjectsLocationsClustersService(s).List("projects/" + projectID + "/locations/-").Do()
	if err != nil {
		return err
	}
	// filtering with target label
	for _, cluster := range filter(clusters.Clusters, targetLabel, "true") {
		labels := cluster.ResourceLabels
		fingerprint := cluster.LabelFingerprint //add
		for _, nodePool := range cluster.NodePools {
			nodeSizeLabel := "restore-size-" + nodePool.Name
                                    labels[nodeSizeLabel] = strconv.FormatInt(nodePool.InitialNodeCount, 10)
		}
		parseRegion := strings.Split(cluster.Location, "/")
		region := parseRegion[len(parseRegion)-1]
		name := "projects/" + projectID + "/locations/" + region + "/clusters/" + cluster.Name
		req := &container.SetLabelsRequest{
			ResourceLabels: labels,
			LabelFingerprint: fingerprint, //add
		}
		_, err := container.NewProjectsLocationsClustersService(s).SetResourceLabels(name, req).Do()
		if err != nil {
			return err
		}
	}
	return nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions