{"record":{"id":"be70df5dd7cfee7f","repo":"kubernetes/kops","slug":"failed-to-get-servers-matching-label-selector-q","errorCode":null,"errorMessage":"failed to get servers matching label selector %q: %w","messagePattern":"failed to get servers matching label selector %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/hetzner/cloud.go","lineNumber":222,"sourceCode":"\treturn matches, nil\n}\n\nfunc (c *hetznerCloudImplementation) GetServers(clusterName string) ([]*hcloud.Server, error) {\n\tclient := c.ServerClient()\n\n\tlabelSelector := TagKubernetesClusterName + \"=\" + clusterName\n\tlistOptions := hcloud.ListOpts{\n\t\tPerPage:       50,\n\t\tLabelSelector: labelSelector,\n\t}\n\tsortOptions := []string{\n\t\t\"created:desc\",\n\t}\n\tserverListOptions := hcloud.ServerListOpts{ListOpts: listOptions, Sort: sortOptions}\n\n\tmatches, err := client.AllWithOpts(context.TODO(), serverListOptions)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get servers matching label selector %q: %w\", labelSelector, err)\n\t}\n\n\treturn matches, nil\n}\n\nfunc (c *hetznerCloudImplementation) GetVolumes(clusterName string) ([]*hcloud.Volume, error) {\n\tclient := c.VolumeClient()\n\n\tlabelSelector := TagKubernetesClusterName + \"=\" + clusterName\n\tlistOptions := hcloud.ListOpts{\n\t\tPerPage:       50,\n\t\tLabelSelector: labelSelector,\n\t}\n\tvolumeListOptions := hcloud.VolumeListOpts{ListOpts: listOptions}\n\n\tmatches, err := client.AllWithOpts(context.TODO(), volumeListOptions)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get volumes matching label selector %q: %w\", labelSelector, err)","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/hetzner/cloud.go#L204-L240","documentation":"GetServers wraps errors from hcloud ServerClient.AllWithOpts when listing servers with the cluster label selector and created:desc sort. The request to Hetzner's /servers endpoint failed; the cause (auth, rate limit, network, invalid label selector) is wrapped via %w.","triggerScenarios":"Calling GetServers (directly or via findServerGroups/GetCloudGroups) when the API token is bad, the network is unavailable, rate limit exceeded, or Hetzner rejects the sort/label parameters.","commonSituations":"kOps rolling updates or instance deletion on Hetzner clusters with a revoked token; bursts of API calls from multiple kOps invocations tripping the rate limit; cluster name containing characters making the label selector invalid.","solutions":["Check HCLOUD_TOKEN validity and project membership","Wait and retry on 429 rate-limit errors","Confirm the cluster name yields a syntactically valid label selector value","Unwrap the error to identify the exact hcloud error code"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if clusterName == \"\" || strings.ContainsAny(clusterName, \" /,;\") {\n\treturn fmt.Errorf(\"clusterName %q would form an invalid label selector\", clusterName)\n}","typeGuard":"var hcloudErr *hcloud.Error\nif errors.As(err, &hcloudErr) {\n\t// inspect hcloudErr.Code\n}","tryCatchPattern":"servers, err := cloud.GetServers(clusterName)\nfor attempt := 0; attempt < 3 && err != nil; attempt++ {\n\ttime.Sleep(time.Duration(1<<attempt) * time.Second)\n\tservers, err = cloud.GetServers(clusterName)\n}","preventionTips":["Ensure cluster names produce valid label selector values","Avoid running multiple kOps operations concurrently against the same project","Retry list calls with exponential backoff","Keep the hcloud Go SDK up to date"],"tags":["hetzner","api","servers","network"],"backgroundTag":"hetzner-api-request-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}