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

  1. Check HCLOUD_TOKEN validity and project membership
  2. Wait and retry on 429 rate-limit errors
  3. Confirm the cluster name yields a syntactically valid label selector value
  4. 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

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


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/be70df5dd7cfee7f. Report an issue: GitHub.