{"record":{"id":"467a81e13a526d67","repo":"kubernetes/kops","slug":"error-getting-instance-group-for-mig-q","errorCode":null,"errorMessage":"error getting instance group for MIG %q","messagePattern":"error getting instance group for MIG %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/instancegroups.go","lineNumber":177,"sourceCode":"\t}\n\n\tfor _, zoneName := range zones {\n\t\tmigs, err := c.Compute().InstanceGroupManagers().List(ctx, project, zoneName)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error listing InstanceGroupManagers: %v\", err)\n\t\t}\n\t\tfor _, mig := range migs {\n\t\t\tname := mig.Name\n\n\t\t\tinstanceTemplate := instanceTemplates[mig.InstanceTemplate]\n\t\t\tif instanceTemplate == nil {\n\t\t\t\tklog.V(2).Infof(\"ignoring MIG %s with unmanaged InstanceTemplate: %s\", name, mig.InstanceTemplate)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tig, err := matchInstanceGroup(mig, cluster, instancegroups)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error getting instance group for MIG %q\", name)\n\t\t\t}\n\t\t\tif ig == nil {\n\t\t\t\tif warnUnmatched {\n\t\t\t\t\tklog.Warningf(\"Found MIG with no corresponding instance group %q\", name)\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tg := &cloudinstances.CloudInstanceGroup{\n\t\t\t\tHumanName:     mig.Name,\n\t\t\t\tInstanceGroup: ig,\n\t\t\t\tMinSize:       int(mig.TargetSize),\n\t\t\t\tTargetSize:    int(mig.TargetSize),\n\t\t\t\tMaxSize:       int(mig.TargetSize),\n\t\t\t\tRaw:           mig,\n\t\t\t}\n\t\t\tgroups[mig.Name] = g\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/instancegroups.go#L159-L195","documentation":"Returned by GetCloudGroups when matchInstanceGroup fails to map a GCE managed instance group to one of the cluster's kops InstanceGroup specs. Note the underlying matchInstanceGroup error is discarded — only the MIG name is reported — so this typically means the MIG's labels/tags do not correspond to any known instance group. This makes the cloud-group listing incomplete, so it is fatal.","triggerScenarios":"Calling GetCloudGroups when matchInstanceGroup(mig, cluster, instancegroups) returns an error — most often because multiple or zero kops instance groups ambiguously match, or because internal matching logic fails (e.g. bad group naming/labels on the MIG created outside kops).","commonSituations":"MIGs created or renamed manually in the GCP console, instance groups whose kops cluster tag was altered, cloning an instance group without updating its name/labels, or a cluster spec where two instance groups map to the same MIG.","solutions":["Re-run with klog V(2) and inspect matchInstanceGroup logic: compare the MIG name/labels against each kops InstanceGroup spec.","Check the MIG's name and labels/tags: it must follow kops naming (<cluster>-<igname> pattern) so it can be matched.","If the MIG is not kops-managed, delete it or exclude it from the cluster's zones.","Ensure the cluster spec's instanceGroups section matches the MIGs actually present (no stale or duplicate groups)."],"exampleFix":"// before\nreturn nil, fmt.Errorf(\"error getting instance group for MIG %q\", name)\n// after (preserve the cause for diagnosis)\nig, err := matchInstanceGroup(mig, cluster, instancegroups)\nif err != nil {\n    return nil, fmt.Errorf(\"error getting instance group for MIG %q: %v\", name, err)\n}","handlingStrategy":"validation","validationCode":"// before calling kops commands, confirm every MIG maps to exactly one kops IG\nfor _, mig := range migs {\n    matches := filterInstanceGroupsByNameOrLabels(instancegroups, mig.Name, mig.Labels)\n    if len(matches) != 1 {\n        log.Fatalf(\"MIG %s matches %d kops instance groups; fix the cluster spec\", mig.Name, len(matches))\n    }\n}","typeGuard":"func isManagedByKops(mig *compute.InstanceGroupManager, clusterName string) bool {\n    return mig != nil && strings.HasPrefix(mig.Name, clusterName+\"-\")\n}","tryCatchPattern":"cloudGroups, err := gceCloud.GetCloudGroups(ctx, cluster, warnUnmatched, instancegroups)\nif err != nil {\n    if strings.Contains(err.Error(), \"error getting instance group for MIG\") {\n        log.Warn(\"a MIG does not map to any kops instance group; inspect MIG names/labels or remove it\")\n    }\n    return err\n}","preventionTips":["Never create or rename MIGs manually in the GCP console; manage them only through kops.","Keep kops instance group names unique and let kops derive MIG names.","After copying an instance group spec, rename every field and run kops update cluster.","Audit MIG labels/tags periodically against the cluster spec."],"tags":["gce","gcp","instance-group","mismatch","kops"],"backgroundTag":"mig-instance-group-mismatch","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}