{"record":{"id":"4a96d39a2adf3e39","repo":"kubernetes/kops","slug":"error-updating-instancetemplate-for-instancegroupm","errorCode":null,"errorMessage":"error updating InstanceTemplate for InstanceGroupManager: %v","messagePattern":"error updating InstanceTemplate for InstanceGroupManager: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gcetasks/instancegroupmanager.go","lineNumber":153,"sourceCode":"\t\t}\n\t} else {\n\t\tif changes.TargetPools != nil {\n\t\t\top, err := t.Cloud.Compute().InstanceGroupManagers().SetTargetPools(t.Cloud.Project(), *e.Zone, i.Name, i.TargetPools)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error updating TargetPools for InstanceGroupManager: %v\", err)\n\t\t\t}\n\n\t\t\tif err := t.Cloud.WaitForOp(op); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error updating TargetPools for InstanceGroupManager: %v\", err)\n\t\t\t}\n\n\t\t\tchanges.TargetPools = nil\n\t\t}\n\n\t\tif changes.InstanceTemplate != nil {\n\t\t\top, err := t.Cloud.Compute().InstanceGroupManagers().SetInstanceTemplate(t.Cloud.Project(), *e.Zone, i.Name, instanceTemplateURL)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error updating InstanceTemplate for InstanceGroupManager: %v\", err)\n\t\t\t}\n\n\t\t\tif err := t.Cloud.WaitForOp(op); err != nil {\n\t\t\t\treturn fmt.Errorf(\"error updating InstanceTemplate for InstanceGroupManager: %v\", err)\n\t\t\t}\n\n\t\t\tchanges.InstanceTemplate = nil\n\t\t}\n\n\t\tif changes.TargetSize != nil {\n\t\t\tnewSize := int64(0)\n\t\t\tif i.TargetSize != 0 {\n\t\t\t\tnewSize = int64(i.TargetSize)\n\t\t\t}\n\t\t\top, err := t.Cloud.Compute().InstanceGroupManagers().Resize(t.Cloud.Project(), *e.Zone, i.Name, newSize)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error resizing InstanceGroupManager: %v\", err)\n\t\t\t}","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gcetasks/instancegroupmanager.go#L135-L171","documentation":"kOps wraps a failure from the GCE Compute API SetInstanceTemplate call — or from waiting on its returned operation — while updating an existing InstanceGroupManager's instance template during `kops update cluster`. The underlying Google API error (wrapped via %v) carries the real cause. It is only reached when the MIG exists and the diff shows a changed InstanceTemplate.","triggerScenarios":"1) SetInstanceTemplate returns an API error: instanceTemplateURL invalid/unresolvable, template deleted, zone mismatch, permission denied, or MIG busy. 2) The call succeeds but Cloud.WaitForOp(op) fails because the rolling replacement of instances hit an error (e.g. new template's image/machineType is invalid, quota exceeded while creating instances).","commonSituations":"Upgrading Kubernetes version where the referenced InstanceTemplate was modified or deleted out-of-band; using a machine type or image not available in the zone; GCP quota exhausted when new instances launch; a concurrent MIG operation blocking the update.","solutions":["Run with -v=10 and inspect the wrapped Google API error / operation error for the concrete cause.","Confirm the instance template exists: `gcloud compute instance-templates list` and that e.InstanceTemplate.URL(project) points at it.","Validate the template's machineType/image are available in the MIG's zone; fix the spec and re-run `kops update cluster`.","Check quota in the region (`gcloud compute project-info describe`) if the op fails while creating instances.","Wait for any in-flight MIG operation to finish, then retry."],"exampleFix":"// before: template references unavailable machine type\n//   machineType: n2-standard-8  (not offered in us-west1-a)\n// after: pick an available type\n// kops edit cluster  # set machineType: n2-standard-4\n// kops update cluster <name> --yes","handlingStrategy":"try-catch","validationCode":"// Verify the instance template resolvable by kOps exists before updating\ntmplURL, err := igm.InstanceTemplate.URL(project)\nif err != nil {\n    return err\n}\nif _, err := computeService.InstanceTemplates.Get(project, lastPathComponent(tmplURL)).Do(); err != nil {\n    return fmt.Errorf(\"instance template %s not found: %w\", tmplURL, err)\n}","typeGuard":"func isGceNotFound(err error) bool {\n    var apiErr *googleapi.Error\n    return errors.As(err, &apiErr) && apiErr.Code == 404\n}","tryCatchPattern":"err := kopsUpdateCluster(...)\nvar apiErr *googleapi.Error\nif errors.As(err, &apiErr) {\n    if apiErr.Code == 404 {\n        // instance template missing: recreate via kops, then re-run update\n    } else if apiErr.Code == 409 {\n        // operation conflict: wait for in-flight op, retry\n    }\n}","preventionTips":["Confirm machine type and image in the instance template are available in the MIG's zone","Check regional CPU/IP quota before scaling upgrades","Do not delete instance templates backing a live MIG","Serialize kOps update runs; use `--dry-run` to preview template changes"],"tags":["gce","instance-template","instance-group-manager","google-compute-api"],"backgroundTag":"gce-operation-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"}