{"record":{"id":"61c4e40a233f9765","repo":"kubernetes/kops","slug":"error-listing-subnetworks-v","errorCode":null,"errorMessage":"error listing subnetworks: %v","messagePattern":"error listing subnetworks: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/resources/gce/gce.go","lineNumber":904,"sourceCode":"\t\treturn nil, err\n\t}\n\tsubnetworkUrls := make(map[string]bool)\n\tfor _, t := range templates {\n\t\tfor _, ni := range t.Properties.NetworkInterfaces {\n\t\t\tif ni.Subnetwork != \"\" {\n\t\t\t\tsubnetworkUrls[ni.Subnetwork] = true\n\t\t\t}\n\t\t}\n\t}\n\n\tc := d.gceCloud\n\n\tvar resourceTrackers []*resources.Resource\n\tctx := context.Background()\n\n\tsubnets, err := c.Compute().Subnetworks().List(ctx, c.Project(), c.Region())\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error listing subnetworks: %v\", err)\n\t}\n\n\tfor _, o := range subnets {\n\t\tif !d.matchesClusterName(o.Name) {\n\t\t\tklog.V(8).Infof(\"skipping Subnet with name %q\", o.Name)\n\t\t\tcontinue\n\t\t}\n\n\t\tif !subnetworkUrls[o.SelfLink] {\n\t\t\tklog.Warningf(\"skipping subnetwork %q because it didn't match any instance template\", o.SelfLink)\n\t\t\tcontinue\n\t\t}\n\n\t\tresourceTracker := &resources.Resource{\n\t\t\tName:    o.Name,\n\t\t\tID:      o.Name,\n\t\t\tType:    typeSubnet,\n\t\t\tDeleter: deleteSubnet,","sourceCodeStart":886,"sourceCodeEnd":922,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/resources/gce/gce.go#L886-L922","documentation":"Wraps a failure from Compute Subnetworks().List in listSubnets, which lists regional subnetworks and filters by cluster name during discovery. Any List failure aborts the discovery pass. This call requires compute.subnetworks.list in the given project/region; like the addresses path it formats with %v so the raw error text is preserved in the message only.","triggerScenarios":"c.Compute().Subnetworks().List(ctx, project, region) fails with 403 missing subnetworks.list, 429 quota, 5xx, or an invalid region (empty/mistyped c.Region() in the cluster spec).","commonSituations":"Region misconfiguration in the cluster spec; shared VPC where kops credentials lack subnet visibility in the host project; IAM role changes; transient GCP API outage during kops delete cluster.","solutions":["Verify the region in the cluster spec is correct and non-empty.","Grant compute.subnetworks.list (roles/compute.networkViewer) on the project — and the host project for shared VPC.","Retry on 429/5xx with backoff.","Confirm the correct project ID is configured in credentials/environment.","Check klog output for the raw error string to get the exact Google API status code."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// validate region and subnet visibility before discovery\nif region == \"\" {\n    return fmt.Errorf(\"region is empty in cluster spec\")\n}\nif _, err := computeService.Subnetworks.List(project, region).PageSize(1).Do(); err != nil {\n    if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 403 {\n        return fmt.Errorf(\"missing compute.subnetworks.list on %s/%s\", project, region)\n    }\n}","typeGuard":"func isGCEAPIError(err error) (*googleapi.Error, bool) {\n    var gerr *googleapi.Error\n    return gerr, errors.As(err, &gerr)\n}","tryCatchPattern":"if err := deleteCluster(ctx, c); err != nil {\n    var gerr *googleapi.Error\n    if errors.As(err, &gerr) && (gerr.Code == 429 || gerr.Code >= 500) {\n        // transient — retry with backoff\n    }\n    return err\n}","preventionTips":["Grant roles/compute.networkViewer so subnetworks.list works, including host projects for shared VPC","Validate the cluster spec's region before teardown; don't change region post-creation","Verify the project ID in credentials/environment matches the cluster","Retry on 429/5xx with backoff","Parse the %v raw error string for the exact GCP status code when debugging"],"tags":["gce","gcp","subnet","listing","api-error"],"backgroundTag":"gce-api-request-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"}