{"record":{"id":"41e76490a06adb7a","repo":"kubernetes/kops","slug":"instance-id-for-cloud-instance-member-cannot-be-em","errorCode":null,"errorMessage":"instance id for cloud instance member cannot be empty","messagePattern":"instance id for cloud instance member cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cloudinstances/cloud_instance_group.go","lineNumber":46,"sourceCode":"// CloudInstanceGroup is the cloud backing of InstanceGroup.\ntype CloudInstanceGroup struct {\n\t// HumanName is a user-friendly name for the group\n\tHumanName     string\n\tInstanceGroup *kopsapi.InstanceGroup\n\tReady         []*CloudInstance\n\tNeedUpdate    []*CloudInstance\n\tMinSize       int\n\tTargetSize    int\n\tMaxSize       int\n\n\t// Raw allows for the implementer to attach an object, for tracking additional state\n\tRaw interface{}\n}\n\n// NewCloudInstance creates a new CloudInstance\nfunc (c *CloudInstanceGroup) NewCloudInstance(instanceId string, status string, node *v1.Node) (*CloudInstance, error) {\n\tif instanceId == \"\" {\n\t\treturn nil, fmt.Errorf(\"instance id for cloud instance member cannot be empty\")\n\t}\n\tcm := &CloudInstance{\n\t\tID:                 instanceId,\n\t\tCloudInstanceGroup: c,\n\t}\n\n\tif status == CloudInstanceStatusUpToDate {\n\t\tc.Ready = append(c.Ready, cm)\n\t} else {\n\t\tc.NeedUpdate = append(c.NeedUpdate, cm)\n\t}\n\n\tcm.Status = status\n\n\tif node != nil {\n\t\tcm.Node = node\n\t} else {\n\t\tklog.V(8).Infof(\"unable to find node for instance: %s\", instanceId)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/cloudinstances/cloud_instance_group.go#L28-L64","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Filter provider instance records with empty IDs before calling NewCloudInstance.","Log and skip the offending instance record instead of failing the whole group build.","Check the provider API response for anomalies (pending deletion, partial creation) and refresh the listing."],"exampleFix":"// before\nci, err := group.NewCloudInstance(instance.ID, instance.Status, node)\n// after\nif instance.ID == \"\" {\n  klog.Warningf(\"skipping instance with empty ID in group %s\", group.HumanName)\n  continue\n}\nci, err := group.NewCloudInstance(instance.ID, instance.Status, node)","handlingStrategy":"validation","validationCode":"if instanceId == \"\" {\n  return fmt.Errorf(\"provider returned instance with empty ID; skipping\")\n}","typeGuard":null,"tryCatchPattern":"ci, err := group.NewCloudInstance(id, status, node)\nif err != nil && strings.Contains(err.Error(), \"cannot be empty\") {\n  klog.Warningf(\"skipping instance with empty ID\")\n  return nil\n}","preventionTips":["Filter provider listings for empty/nil IDs before building CloudInstanceGroups.","Log skipped records so silent data loss is visible.","Refresh provider listings when transitional instances appear."],"tags":["cloudinstances","validation","aws","instance-id"],"backgroundTag":"missing-instance-id","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"}