kubernetes/kops · error

instance id for cloud instance member cannot be empty

Error message

instance id for cloud instance member cannot be empty

What it means

CloudInstanceGroup.NewCloudInstance validates that a cloud instance has a non-empty instance ID before constructing the CloudInstance struct. An empty ID means the cloud provider returned a machine record without a usable identifier, which would break all downstream operations (drain, delete, cordoning).

Source

Thrown at pkg/cloudinstances/cloud_instance_group.go:46

// CloudInstanceGroup is the cloud backing of InstanceGroup.
type CloudInstanceGroup struct {
	// HumanName is a user-friendly name for the group
	HumanName     string
	InstanceGroup *kopsapi.InstanceGroup
	Ready         []*CloudInstance
	NeedUpdate    []*CloudInstance
	MinSize       int
	TargetSize    int
	MaxSize       int

	// Raw allows for the implementer to attach an object, for tracking additional state
	Raw interface{}
}

// NewCloudInstance creates a new CloudInstance
func (c *CloudInstanceGroup) NewCloudInstance(instanceId string, status string, node *v1.Node) (*CloudInstance, error) {
	if instanceId == "" {
		return nil, fmt.Errorf("instance id for cloud instance member cannot be empty")
	}
	cm := &CloudInstance{
		ID:                 instanceId,
		CloudInstanceGroup: c,
	}

	if status == CloudInstanceStatusUpToDate {
		c.Ready = append(c.Ready, cm)
	} else {
		c.NeedUpdate = append(c.NeedUpdate, cm)
	}

	cm.Status = status

	if node != nil {
		cm.Node = node
	} else {
		klog.V(8).Infof("unable to find node for instance: %s", instanceId)

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Filter provider instance records with empty IDs before calling NewCloudInstance.
  2. Log and skip the offending instance record instead of failing the whole group build.
  3. Check the provider API response for anomalies (pending deletion, partial creation) and refresh the listing.

Example fix

// before
ci, err := group.NewCloudInstance(instance.ID, instance.Status, node)
// after
if instance.ID == "" {
  klog.Warningf("skipping instance with empty ID in group %s", group.HumanName)
  continue
}
ci, err := group.NewCloudInstance(instance.ID, instance.Status, node)
Defensive patterns

Strategy: validation

Validate before calling

if instanceId == "" {
  return fmt.Errorf("provider returned instance with empty ID; skipping")
}

Try / catch

ci, err := group.NewCloudInstance(id, status, node)
if err != nil && strings.Contains(err.Error(), "cannot be empty") {
  klog.Warningf("skipping instance with empty ID")
  return nil
}

Prevention

When it happens

Trigger: Calling NewCloudInstance with "" as instanceId, typically from AWS/Azure/GCP instance-group builders (makeGroup, registerCloudInstances, buildCloudInstanceGroup) when the provider API returns an instance with a missing or empty ID field.

Common situations: ASG/LaunchTemplate entries in a transitional state; API responses with nil instance identifiers; karpenter-built groups where the membership record lacks an ID; partially deleted instances still visible in provider APIs.

Related errors


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