{"record":{"id":"d038ecbfce1181ea","repo":"kubernetes/kops","slug":"error-resizing-instancegroupmanager-s-to-0-w","errorCode":null,"errorMessage":"error resizing InstanceGroupManager %s to 0: %w","messagePattern":"error resizing InstanceGroupManager (.+?) to 0: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/wrappers.go","lineNumber":61,"sourceCode":"\n\treturn c.WaitForOp(op)\n}\n\n// DeleteMIGInstances deletes the instances in the MIG in GCE\nfunc DeleteMIGInstances(c GCECloud, t *compute.InstanceGroupManager) error {\n\tklog.V(2).Infof(\"Deleting Instances in InstanceGroupManager %s\", t.SelfLink)\n\tu, err := ParseGoogleCloudURL(t.SelfLink)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\top, err := c.Compute().InstanceGroupManagers().Resize(u.Project, u.Zone, u.Name, 0)\n\tif err != nil {\n\t\tif IsNotFound(err) {\n\t\t\tklog.Infof(\"InstanceGroupManager not found, assuming deleted: %q\", t.SelfLink)\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\"error resizing InstanceGroupManager %s to 0: %w\", t.SelfLink, err)\n\t}\n\n\treturn c.WaitForOp(op)\n}\n\n// DeleteInstanceTemplate deletes the specified InstanceTemplate (by URL) in GCE\nfunc DeleteInstanceTemplate(c GCECloud, selfLink string) error {\n\tklog.V(2).Infof(\"Deleting GCE InstanceTemplate %s\", selfLink)\n\tu, err := ParseGoogleCloudURL(selfLink)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\top, err := c.Compute().InstanceTemplates().Delete(u.Project, u.Name)\n\tif err != nil {\n\t\tif IsNotFound(err) {\n\t\t\tklog.Infof(\"instancetemplate not found, assuming deleted: %q\", selfLink)\n\t\t\treturn nil","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/wrappers.go#L43-L79","documentation":"This error is returned by DeleteMIGInstances when InstanceGroupManagers().Resize(project, zone, name, 0) fails with anything other than 404 Not Found. Resizing a managed instance group to 0 is how kOps drains all instances from a MIG before deleting it. The googleapi error is wrapped with the MIG selfLink; a missing MIG is treated as success instead.","triggerScenarios":"Calling DeleteMIGInstances (from DeleteCloudGroup) where the Resize-to-0 call returns a non-NotFound error: resize rejected while another operation on the MIG is in progress, the MIG is regional (zonal resize endpoint mismatch), insufficient IAM permissions, or transient API failures.","commonSituations":"Cluster teardown where an earlier create/update operation on the MIG is still RUNNING (GCE rejects concurrent ops); autoscaler or another controller re-expanding the group during resize; regional (non-zonal) MIGs that don't accept the zonal resize call; service account missing resize permissions; API 5xx storms during bulk deletes.","solutions":["Inspect the wrapped googleapi error for the specific GCE status/operation conflict and wait for the in-flight operation to finish, then retry","Disable any autoscaler targeting the MIG (or delete the autoscaler) so it doesn't undo the resize to 0","Verify the MIG is zonal; if regional, use the regional resize endpoint or delete via the kOps path appropriate for regional MIGs","Check IAM roles (compute.instanceGroupManagerAdmin) for the service account","Re-run `kops delete cluster --yes`; the flow is resumable since 404s are skipped"],"exampleFix":"// before: assume resize failure means hard stop\nif err := DeleteMIGInstances(cloud, igm); err != nil {\n\tlog.Fatalf(\"teardown failed: %v\", err)\n}\n// after: wait for conflicting op, then retry resize\nif err := DeleteMIGInstances(cloud, igm); err != nil {\n\tif strings.Contains(err.Error(), \"already in progress\") {\n\t\twaitForOpCompletion(cloud, igm.SelfLink)\n\t\terr = DeleteMIGInstances(cloud, igm)\n\t}\n\tif err != nil {\n\t\tlog.Fatalf(\"teardown failed: %v\", err)\n\t}\n}","handlingStrategy":"retry","validationCode":"// Ensure the MIG is not autoscaled and has no in-flight op before resizing to 0\nautoscalers, err := cloud.Compute().Autoscalers().List(project, zone).Filter(fmt.Sprintf(\"target eq %s\", igm.SelfLink)).Do()\nif err != nil {\n\treturn err\n}\nif len(autoscalers.Items) > 0 {\n\treturn fmt.Errorf(\"delete autoscaler on %s before resizing to 0\", igm.Name)\n}","typeGuard":"func isGCEConflict(err error) bool {\n\tvar gerr *googleapi.Error\n\treturn errors.As(err, &gerr) && gerr.Code == 409\n}","tryCatchPattern":"err := gce.DeleteMIGInstances(cloud, igm)\nif err != nil {\n\tvar gerr *googleapi.Error\n\tswitch {\n\tcase errors.As(err, &gerr) && gerr.Code == 409:\n\t\t// wait for in-flight operation then retry resize\n\tcase errors.As(err, &gerr) && gerr.Code == 404:\n\t\t// already gone, proceed\n\tdefault:\n\t\treturn err\n\t}\n}","preventionTips":["Disable/delete any autoscaler attached to the MIG before resizing to 0","Ensure all prior MIG operations have completed before issuing a resize","Confirm the MIG is zonal; use regional endpoints for regional MIGs","Grant compute.instanceGroupManagerAdmin to the teardown service account"],"tags":["gce","compute-api","instance-group-manager","resize","wrapped-error"],"backgroundTag":"gce-api-delete-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"}