{"record":{"id":"f2834100cd6ba2f0","repo":"kubernetes/kops","slug":"error-listing-managedinstances-in-s-w","errorCode":null,"errorMessage":"error listing ManagedInstances in %s: %w","messagePattern":"error listing ManagedInstances in (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/wrappers.go","lineNumber":123,"sourceCode":"}\n\n// ListManagedInstances lists the specified InstanceGroupManagers in GCE\nfunc ListManagedInstances(c GCECloud, igm *compute.InstanceGroupManager) ([]*compute.ManagedInstance, error) {\n\tctx := context.Background()\n\tproject := c.Project()\n\n\tzoneName := LastComponent(igm.Zone)\n\n\t// TODO: Only select a subset of fields\n\t//\treq.Fields(\n\t//\t\tgoogleapi.Field(\"items/selfLink\"),\n\t//\t\tgoogleapi.Field(\"items/metadata/items[key='cluster-name']\"),\n\t//\t\tgoogleapi.Field(\"items/metadata/items[key='instance-template']\"),\n\t//\t)\n\n\tinstances, err := c.Compute().InstanceGroupManagers().ListManagedInstances(ctx, project, zoneName, igm.Name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing ManagedInstances in %s: %w\", igm.Name, err)\n\t}\n\n\treturn instances, nil\n}\n","sourceCodeStart":105,"sourceCodeEnd":128,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/wrappers.go#L105-L128","documentation":"This error is returned by ListManagedInstances when InstanceGroupManagers().ListManagedInstances(ctx, project, zone, name) fails for any reason. kOps uses this to enumerate the VMs belonging to a managed instance group (e.g. to build/refresh instance lists). Unlike the delete helpers, there is no not-found short-circuit, so any API failure — including the MIG having just been deleted — is surfaced wrapped with the MIG name.","triggerScenarios":"Calling listManagedInstances (instance refresh/validation paths) where the ListManagedInstances API call errors: the MIG was deleted concurrently, the igm.Zone/igm.Name no longer match an existing group, IAM denial, project mismatch between the cloud client and the igm object, or transient GCE API 5xx/timeout.","commonSituations":"kops rolling-update or validate running while a MIG is being resized/deleted elsewhere; igm struct built from a stale cloud group cache whose zone/name no longer exist; service account lacking compute.instanceGroupManagerViewer; cross-project confusion (client project != MIG's project); intermittent API failures on large lists.","solutions":["Check the wrapped googleapi error: 404 means the MIG no longer exists — treat as zero instances or re-list instance groups before proceeding","Verify the service account has compute.instanceGroupManagerViewer / compute.viewer roles","Re-fetch the InstanceGroupManager from the API rather than reusing a cached igm object to ensure zone/name are current","Confirm c.Project() matches the project the MIG belongs to","Retry on transient 5xx/timeouts with backoff"],"exampleFix":"// before: any failure aborts\ninstances, err := ListManagedInstances(cloud, igm)\nif err != nil {\n\treturn err\n}\n// after: tolerate a concurrently-deleted MIG\ninstances, err := ListManagedInstances(cloud, igm)\nif err != nil {\n\tif isNotFound(err) {\n\t\tklog.Infof(\"MIG %s gone; skipping managed instances\", igm.Name)\n\t\tinstances = nil\n\t} else {\n\t\treturn err\n\t}\n}","handlingStrategy":"type-guard","validationCode":"// Verify the MIG still exists (and zone matches the client project) before listing instances\nif _, err := cloud.Compute().InstanceGroupManagers().Get(cloud.Project(), lastComponent(igm.Zone), igm.Name).Do(); err != nil {\n\tif isNotFound(err) {\n\t\treturn nil // MIG gone: no managed instances to list\n\t}\n\treturn err\n}","typeGuard":"func migMissing(err error) bool {\n\tvar gerr *googleapi.Error\n\treturn errors.As(err, &gerr) && gerr.Code == 404\n}","tryCatchPattern":"instances, err := gce.ListManagedInstances(cloud, igm)\nif err != nil {\n\tvar gerr *googleapi.Error\n\tif errors.As(err, &gerr) && gerr.Code == 404 {\n\t\tinstances = nil // MIG deleted concurrently; nothing to list\n\t} else if errors.As(err, &gerr) && gerr.Code >= 500 {\n\t\t// transient; retry with backoff\n\t} else {\n\t\treturn nil, err\n\t}\n}","preventionTips":["Re-fetch the InstanceGroupManager from the API instead of using stale cached objects","Handle 404 as 'zero instances' in callers that run concurrently with teardown","Grant compute.instanceGroupManagerViewer (or compute.viewer) for list operations","Ensure cloud.Project() matches the MIG's project to avoid cross-project lookups","Add backoff/retry for 5xx and timeout errors on large groups"],"tags":["gce","compute-api","instance-group-manager","listing","wrapped-error"],"backgroundTag":"gce-api-list-failed","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"}