{"record":{"id":"8e2fd52f1b14f3cb","repo":"kubernetes/kops","slug":"id-was-not-set-on-cloudinstance-v","errorCode":null,"errorMessage":"id was not set on CloudInstance: %v","messagePattern":"id was not set on CloudInstance: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_cloud.go","lineNumber":494,"sourceCode":"func (c *awsCloudImplementation) DeregisterInstance(i *cloudinstances.CloudInstance) error {\n\tctx := context.TODO()\n\n\tif c.spotinst != nil || i.CloudInstanceGroup.InstanceGroup.Spec.Manager == kops.InstanceManagerKarpenter {\n\t\treturn nil\n\t}\n\n\terr := deregisterInstance(ctx, c, i)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to deregister instance from loadBalancer before terminating: %v\", err)\n\t}\n\n\treturn nil\n}\n\nfunc deleteInstance(ctx context.Context, c AWSCloud, i *cloudinstances.CloudInstance) error {\n\tid := i.ID\n\tif id == \"\" {\n\t\treturn fmt.Errorf(\"id was not set on CloudInstance: %v\", i)\n\t}\n\n\trequest := &ec2.TerminateInstancesInput{\n\t\tInstanceIds: []string{id},\n\t}\n\n\tif _, err := c.EC2().TerminateInstances(ctx, request); err != nil {\n\t\tif AWSErrorCode(err) == \"InvalidInstanceID.NotFound\" {\n\t\t\tklog.V(2).Infof(\"Got InvalidInstanceID.NotFound error deleting instance %q; will treat as already-deleted\", id)\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"error deleting instance %q: %v\", id, err)\n\t\t}\n\t}\n\n\tklog.V(8).Infof(\"deleted aws ec2 instance %q\", id)\n\n\treturn nil\n}","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L476-L512","documentation":"deleteInstance() requires the CloudInstance struct to carry a non-empty EC2 instance ID because it is used verbatim in the ec2.TerminateInstances call. When i.ID is empty, kOps cannot terminate anything and returns this error instead of issuing an invalid API call. It indicates the CloudInstance was constructed from incomplete cloud data (e.g. an ASG member whose instance ID never got populated).","triggerScenarios":"DeleteInstance is invoked on a cloudinstances.CloudInstance whose ID field is \"\" — typically when instance discovery populated the group but not the individual instance record, or code built a CloudInstance manually without setting ID.","commonSituations":"Bugs in cloud instance enumeration; instances in a partially-created state; caller-supplied CloudInstance structs built by hand in custom tooling or tests without setting ID; races where the ASG reports a member before its instance ID is known.","solutions":["Check why the CloudInstance was created with an empty ID — fix the discovery/enumeration code that populated it","Only call DeleteInstance with CloudInstance objects obtained from the cloud provider's GetCloudGroup/instance listing, not hand-built ones","Add a pre-call guard skipping instances with empty IDs and log them for investigation","Upgrade kOps — if caused by an upstream enumeration bug, a newer version may already fix it"],"exampleFix":"// before\nfor _, i := range group.CloudInstances {\n\t_ = cloud.DeleteInstance(i)\n}\n// after\nfor _, i := range group.CloudInstances {\n\tif i.ID == \"\" {\n\t\tklog.Warningf(\"skipping instance with no ID in group %s\", group.HumanName)\n\t\tcontinue\n\t}\n\t_ = cloud.DeleteInstance(i)\n}","handlingStrategy":"validation","validationCode":"if inst == nil || inst.ID == \"\" {\n\tklog.Warningf(\"skipping CloudInstance with empty ID: %+v\", inst)\n\treturn nil\n}\n_ = cloud.DeleteInstance(inst)","typeGuard":"func hasID(i *cloudinstances.CloudInstance) bool {\n\treturn i != nil && i.ID != \"\"\n}","tryCatchPattern":"if err := cloud.DeleteInstance(inst); err != nil {\n\tif strings.Contains(err.Error(), \"id was not set\") {\n\t\tklog.Warningf(\"instance record incomplete (%v); refreshing group state\", err)\n\t\treturn refreshAndRetry(inst)\n\t}\n\treturn err\n}","preventionTips":["Only pass CloudInstance objects produced by the provider's discovery APIs","Never construct CloudInstance structs by hand in scripts/tests without setting ID","Log and audit any CloudInstance with empty ID at discovery time"],"tags":["aws","ec2","instance-termination","invalid-input"],"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"}