kubernetes/kops · error

failed to convert server ID %q to int: %w

Error message

failed to convert server ID %q to int: %w

What it means

DeleteInstance parses the CloudInstance ID string as an int64 Hetzner server ID before deleting; this error is thrown when strconv.ParseInt fails, meaning the instance ID is not a numeric Hetzner server ID.

Source

Thrown at upup/pkg/fi/cloudup/hetzner/cloud.go:254

	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)
	}

	return matches, nil
}

func (c *hetznerCloudImplementation) DNS() (dnsprovider.Interface, error) {
	// Hetzner LB has a stable internal IP and can use that instead of creating a record for api.internal.
	return nil, nil
}

func (c *hetznerCloudImplementation) DeleteInstance(instance *cloudinstances.CloudInstance) error {
	serverID, err := strconv.ParseInt(instance.ID, 10, 64)
	if err != nil {
		return fmt.Errorf("failed to convert server ID %q to int: %w", instance.ID, err)
	}

	err = deleteServer(c, serverID)

	return err
}

// deleteServer shuts down and deletes the given server
func deleteServer(c *hetznerCloudImplementation, id int64) error {
	client := c.ServerClient()
	ctx := context.TODO()

	server := &hcloud.Server{ID: id}
	_, _, err := client.Shutdown(ctx, server)
	if err != nil {
		return fmt.Errorf("failed to stop server %q: %w", strconv.FormatInt(id, 10), err)
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Ensure the CloudInstance ID is the numeric Hetzner server ID (from providerID hcloud://<id>)
  2. Fix whatever populated instance.ID (node providerID parsing) to extract only the numeric part
  3. Check for leading/trailing whitespace or prefix text in the ID and trim/strip it
  4. Verify kOps and hetzner cloud provider versions agree on ID format

Example fix

// before
serverID, err := strconv.ParseInt(instance.ID, 10, 64)
// after
id := strings.TrimPrefix(instance.ID, "hcloud://")
serverID, err := strconv.ParseInt(id, 10, 64)
if err != nil {
	return fmt.Errorf("failed to convert server ID %q to int: %w", id, err)
}
Defensive patterns

Strategy: validation

Validate before calling

serverID, err := strconv.ParseInt(strings.TrimSpace(strings.TrimPrefix(instance.ID, "hcloud://")), 10, 64)
if err != nil {
	return fmt.Errorf("instance ID %q is not a numeric Hetzner server ID", instance.ID)
}

Type guard

func isNumericServerID(id string) bool {
	_, err := strconv.ParseInt(id, 10, 64)
	return err == nil
}

Prevention

When it happens

Trigger: Calling DeleteInstance with a CloudInstance whose ID was populated from a non-Hetzner source (e.g. a node name, UUID, or an ID format change) instead of the numeric Hetzner server ID.

Common situations: Kubernetes node objects whose providerID/instance mapping does not carry the numeric Hetzner server ID, custom tooling building CloudInstance structs manually, or kOps/Hetzner provider-ID format changes after upgrades.

Related errors


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