kubernetes/kops · error
failed to get servers matching label selector %q: %w
Error message
failed to get servers matching label selector %q: %w
What it means
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.
Source
Thrown at upup/pkg/fi/cloudup/hetzner/cloud.go:222
return matches, nil
}
func (c *hetznerCloudImplementation) GetServers(clusterName string) ([]*hcloud.Server, error) {
client := c.ServerClient()
labelSelector := TagKubernetesClusterName + "=" + clusterName
listOptions := hcloud.ListOpts{
PerPage: 50,
LabelSelector: labelSelector,
}
sortOptions := []string{
"created:desc",
}
serverListOptions := hcloud.ServerListOpts{ListOpts: listOptions, Sort: sortOptions}
matches, err := client.AllWithOpts(context.TODO(), serverListOptions)
if err != nil {
return nil, fmt.Errorf("failed to get servers matching label selector %q: %w", labelSelector, err)
}
return matches, nil
}
func (c *hetznerCloudImplementation) GetVolumes(clusterName string) ([]*hcloud.Volume, error) {
client := c.VolumeClient()
labelSelector := TagKubernetesClusterName + "=" + clusterName
listOptions := hcloud.ListOpts{
PerPage: 50,
LabelSelector: labelSelector,
}
volumeListOptions := hcloud.VolumeListOpts{ListOpts: listOptions}
matches, err := client.AllWithOpts(context.TODO(), volumeListOptions)
if err != nil {
return nil, fmt.Errorf("failed to get volumes matching label selector %q: %w", labelSelector, err)View on GitHub (pinned to 4c8573c808)
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
Defensive patterns
Strategy: retry
Validate before calling
if clusterName == "" || strings.ContainsAny(clusterName, " /,;") {
return fmt.Errorf("clusterName %q would form an invalid label selector", clusterName)
} Type guard
var hcloudErr *hcloud.Error
if errors.As(err, &hcloudErr) {
// inspect hcloudErr.Code
} Try / catch
servers, err := cloud.GetServers(clusterName)
for attempt := 0; attempt < 3 && err != nil; attempt++ {
time.Sleep(time.Duration(1<<attempt) * time.Second)
servers, err = cloud.GetServers(clusterName)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to list networks: %w
- failed to get firewalls matching label selector %q: %w
- failed to get load balancers matching label selector %q: %w
- failed to get volumes matching label selector %q: %w
- failed to find network %q: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/be70df5dd7cfee7f.
Report an issue: GitHub.