Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error occurred when executing stop. #50

Open
mori-chi opened this issue Feb 12, 2020 · 0 comments
Open

An error occurred when executing stop. #50

mori-chi opened this issue Feb 12, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@mori-chi
Copy link

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
}
@mori-chi mori-chi added the bug Something isn't working label Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant