{"record":{"id":"d1359f36318e68f9","repo":"kubernetes/kops","slug":"error-detaching-instance-q-v-d1359f","errorCode":null,"errorMessage":"error detaching instance %q: %v","messagePattern":"error detaching instance %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/awsup/aws_cloud.go","lineNumber":696,"sourceCode":"\tif id == \"\" {\n\t\treturn fmt.Errorf(\"id was not set on CloudInstance: %v\", i)\n\t}\n\n\tasg := i.CloudInstanceGroup.Raw.(*autoscalingtypes.AutoScalingGroup)\n\tif err := c.CreateTags(id, map[string]string{tagNameDetachedInstance: *asg.AutoScalingGroupName}); err != nil {\n\t\treturn fmt.Errorf(\"error tagging instance %q: %v\", id, err)\n\t}\n\n\t// TODO this also deregisters the instance from any ELB attached to the ASG. Do we care?\n\n\tinput := &autoscaling.DetachInstancesInput{\n\t\tAutoScalingGroupName:           aws.String(i.CloudInstanceGroup.HumanName),\n\t\tInstanceIds:                    []string{id},\n\t\tShouldDecrementDesiredCapacity: aws.Bool(false),\n\t}\n\n\tif _, err := c.Autoscaling().DetachInstances(ctx, input); err != nil {\n\t\treturn fmt.Errorf(\"error detaching instance %q: %v\", id, err)\n\t}\n\n\tklog.V(8).Infof(\"detached aws ec2 instance %q\", id)\n\n\treturn nil\n}\n\n// GetCloudGroups returns a groups of instances that back a kops instance groups\nfunc (c *awsCloudImplementation) GetCloudGroups(cluster *kops.Cluster, instancegroups []*kops.InstanceGroup, warnUnmatched bool, nodes []v1.Node) (map[string]*cloudinstances.CloudInstanceGroup, error) {\n\tctx := context.TODO()\n\n\tif c.spotinst != nil {\n\t\tsgroups, err := spotinst.GetCloudGroups(c.spotinst, cluster, instancegroups, warnUnmatched, nodes)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tif featureflag.SpotinstHybrid.Enabled() {","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/awsup/aws_cloud.go#L678-L714","documentation":"The subsequent DetachInstances call failed while removing the instance from its autoscaling group during rolling update; commonly the ASG name is stale (already deleted) or AWS rejects the detach because the instance is already detached.","triggerScenarios":"Thrown at upup/pkg/fi/cloudup/awsup/aws_cloud.go:696 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the ASG still exists and contains the instance","Re-run the rolling update; concurrent detachment can cause this transiently","Check autoscaling:DetachInstances permissions"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}