{"record":{"id":"4ddc24bb7ee84b72","repo":"kubernetes/kops","slug":"found-multiple-instances-with-id-v-managed-by-mig","errorCode":null,"errorMessage":"found multiple instances with id %v managed by mig %s","messagePattern":"found multiple instances with id (.+?) managed by mig (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/nodeidentity/gce/identify.go","lineNumber":267,"sourceCode":"\tif err := i.computeService.InstanceGroupManagers.ListManagedInstances(i.project, zone, mig.Name).Filter(filter).Pages(ctx, func(page *compute.InstanceGroupManagersListManagedInstancesResponse) error {\n\t\t// Post-filter... filters aren't implemented (b/27605549)\n\t\tfor _, instance := range page.ManagedInstances {\n\t\t\tif instance.Id != instanceID {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tmatches = append(matches, instance)\n\t\t}\n\t\treturn nil\n\t}); err != nil {\n\t\treturn nil, fmt.Errorf(\"error fetching GCE managed instance group members for %q: %v\", mig.Name, err)\n\t}\n\n\tif len(matches) == 0 {\n\t\treturn nil, fmt.Errorf(\"instance %v not managed by mig %s\", instanceID, mig.Name)\n\t}\n\tif len(matches) > 1 {\n\t\t// Should be impossible - shows that filters / post-filters are not working\n\t\treturn nil, fmt.Errorf(\"found multiple instances with id %v managed by mig %s\", instanceID, mig.Name)\n\t}\n\n\treturn matches[0], nil\n}\n\n// lastComponent returns the last component of a URL, i.e. anything after the last slash\n// If there is no slash, returns the whole string\nfunc lastComponent(s string) string {\n\tlastSlash := strings.LastIndex(s, \"/\")\n\tif lastSlash != -1 {\n\t\ts = s[lastSlash+1:]\n\t}\n\treturn s\n}\n\nfunc getMetadataValue(metadata *compute.Metadata, key string) string {\n\tvalue := \"\"\n\tif metadata != nil {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/nodeidentity/gce/identify.go#L249-L285","documentation":"After listing a MIG's members and filtering by instance ID, more than one instance matched. GCE guarantees instance IDs are unique within a project, so this indicates kops' filtering or post-filtering logic failed. The code comments explicitly note this should be impossible.","triggerScenarios":"len(matches) > 1 after post-filtering MIG ListInstances results by instance ID — e.g. the ID-based filter did not apply server-side and duplicate/unexpected entries came back, or corrupted/zero instance IDs bypassed the filter.","commonSituations":"GCE API behavioral change or bug returning duplicate member entries; upstream kops filter regression; extremely unusual project state (instance ID reuse after deletion, which GCE disallows).","solutions":["Upgrade kops to the latest patch — this is treated as an internal invariant violation","Inspect the MIG members for duplicate entries via gcloud and file a GCE support case if duplicates are real","Retry; a transient bad API response usually does not reproduce","File a kops issue with the MIG name and instance ID if it persists"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"func exactlyOne(matches []*compute.InstanceWithNamedPorts) (*compute.InstanceWithNamedPorts, bool) {\n  if len(matches) == 1 { return matches[0], true }\n  return nil, false\n}","tryCatchPattern":"inst, err := getManagedInstance(mig, id)\nif err != nil && strings.Contains(err.Error(), \"found multiple instances\") {\n  // invariant violation: report to kops, retry once\n}","preventionTips":["Keep kops up to date (this is an internal invariant error)","Monitor for GCE API anomalies via support channels","Log MIG name and instance ID for bug reports"],"tags":["gce","mig","invariant-violation","data-integrity"],"backgroundTag":"unexpected-duplicate-results","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"}