{"record":{"id":"afe5d475b9c6f87b","repo":"kubernetes/kops","slug":"error-detaching-instance-q-node-q-v","errorCode":null,"errorMessage":"error detaching instance %q, node %q: %v","messagePattern":"error detaching instance %q, node %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/instancegroups/instancegroups.go","lineNumber":638,"sourceCode":"\treturn false\n}\n\n// detachInstance detaches a Cloud Instance\nfunc (c *RollingUpdateCluster) detachInstance(u *cloudinstances.CloudInstance) error {\n\tid := u.ID\n\tnodeName := \"\"\n\tif u.Node != nil {\n\t\tnodeName = u.Node.Name\n\t}\n\tif nodeName != \"\" {\n\t\tklog.Infof(\"Detaching instance %q, node %q, in group %q.\", id, nodeName, u.CloudInstanceGroup.HumanName)\n\t} else {\n\t\tklog.Infof(\"Detaching instance %q, in group %q.\", id, u.CloudInstanceGroup.HumanName)\n\t}\n\n\tif err := c.Cloud.DetachInstance(u); err != nil {\n\t\tif nodeName != \"\" {\n\t\t\treturn fmt.Errorf(\"error detaching instance %q, node %q: %v\", id, nodeName, err)\n\t\t}\n\t\treturn fmt.Errorf(\"error detaching instance %q: %v\", id, err)\n\t}\n\n\treturn nil\n}\n\n// deleteInstance deletes an Cloud Instance.\nfunc (c *RollingUpdateCluster) deleteInstance(u *cloudinstances.CloudInstance) error {\n\tid := u.ID\n\tnodeName := \"\"\n\tif u.Node != nil {\n\t\tnodeName = u.Node.Name\n\t}\n\tif nodeName != \"\" {\n\t\tklog.Infof(\"Stopping instance %q, node %q, in group %q (this may take a while).\", id, nodeName, u.CloudInstanceGroup.HumanName)\n\t} else {\n\t\tklog.Infof(\"Stopping instance %q, in group %q (this may take a while).\", id, u.CloudInstanceGroup.HumanName)","sourceCodeStart":620,"sourceCodeEnd":656,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/instancegroups/instancegroups.go#L620-L656","documentation":"kOps detaches an instance from its cloud instance group (ASG/mig) before terminating or updating it. This error wraps a failure of the cloud provider's DetachInstance call for an instance that has an associated Kubernetes node name.","triggerScenarios":"c.Cloud.DetachInstance(u) errors (AWS: autoscaling detach_instances; GCP: mig removeInstances) while nodeName != \"\". Causes include the instance no longer belonging to the group, API throttling, or IAM permission failures.","commonSituations":"ASG modified externally between discovery and detach; AWS API rate limits during large rolls; missing autoscaling:DetachInstances IAM permission; instance in a transitional state.","solutions":["Re-run the rolling update; group membership state is re-discovered","Check cloud IAM permissions for detach operations","Look for external automation (ASG edits, cluster-autoscaler) conflicting with the roll","Retry after cloud API throttling subsides"],"exampleFix":"// before\n// IAM policy missing autoscaling detach\n// after\n{ \"Effect\": \"Allow\", \"Action\": [\"autoscaling:DetachInstances\"], \"Resource\": \"*\" }","handlingStrategy":"try-catch","validationCode":"// pre-flight: confirm instance still in group via cloud API before detach\nasg, err := autoscalingClient.DescribeAutoScalingGroups(...)\n// verify instanceIDs contains u.ID before calling DetachInstance","typeGuard":"func inGroup(u *cloudinstances.CloudInstance, memberIDs []string) bool {\n    return u != nil && u.ID != \"\" && contains(memberIDs, u.ID)\n}","tryCatchPattern":"if err := c.Cloud.DetachInstance(u); err != nil {\n    if isNotFound(err) || isAlreadyDetached(err) { return nil }\n    if isThrottling(err) { /* backoff and retry */ }\n    return fmt.Errorf(\"error detaching instance %q, node %q: %v\", id, nodeName, err)\n}","preventionTips":["Don't mutate ASGs/migs manually while a roll is running","Grant detach IAM permissions (autoscaling:DetachInstances, compute.instanceGroups RPC)","Retry rolls after cloud API throttling","Pause cluster-autoscaler during maintenance windows"],"tags":["cloud","detach","rolling-update","autoscaling"],"backgroundTag":"cloud-instance-detach-failed","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"}