{"record":{"id":"a04965c71673e9e6","repo":"kubernetes/kops","slug":"error-parsing-subnet-url-q-w","errorCode":null,"errorMessage":"error parsing subnet url %q: %w","messagePattern":"error parsing subnet url %q: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/network.go","lineNumber":122,"sourceCode":"\tif network == nil {\n\t\treturn used, nil\n\t}\n\n\tsubnetURLs := make(map[string]bool)\n\tfor _, subnet := range network.Subnetworks {\n\t\tsubnetURLs[subnet] = true\n\t}\n\tif len(subnetURLs) == 0 {\n\t\treturn used, nil\n\t}\n\n\tklog.Infof(\"scanning regions for subnetwork CIDR allocations\")\n\n\tregions := make(map[string]bool)\n\tfor subnetURL := range subnetURLs {\n\t\tu, err := ParseGoogleCloudURL(subnetURL)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error parsing subnet url %q: %w\", subnetURL, err)\n\t\t}\n\t\tregions[u.Region] = true\n\t}\n\n\tvar subnets []*compute.Subnetwork\n\tfor region := range regions {\n\t\tl, err := cloud.Compute().Subnetworks().List(ctx, cloud.Project(), region)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error listing Subnetworks in region %q: %w\", region, err)\n\t\t}\n\t\tsubnets = append(subnets, l...)\n\t}\n\n\tfor _, subnet := range subnets {\n\t\tif !subnetURLs[subnet.SelfLink] {\n\t\t\tcontinue\n\t\t}\n\t\tif err := used.MarkInUse(subnet.IpCidrRange); err != nil {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/network.go#L104-L140","documentation":"buildUsed iterates over the set of subnet self-link URLs known to the cluster and calls ParseGoogleCloudURL on each to extract the region. If a URL does not match the expected Google Cloud resource URL shape, this error is thrown with the offending URL. It means the cluster spec holds a subnet reference the URL parser cannot understand.","triggerScenarios":"A subnet ID in the cluster spec that is not a well-formed Google Cloud self-link (e.g. a bare subnet name, a malformed regional URL, or a URL from a different API version shape that ParseGoogleCloudURL does not recognize), passed during IP-alias or subnet assignment.","commonSituations":"Hand-editing subnet IDs in the cluster spec; subnet values written by an older kops version in a URL format no longer parsed; copy/paste errors truncating the self-link.","solutions":["Verify each spec subnet value is a valid full self-link like https://www.googleapis.com/compute/v1/projects/P/regions/R/subnetworks/N","Regenerate the cluster spec from a known-good state (kops get cluster -o yaml from a working cluster)","Check ParseGoogleCloudURL expectations in upup/pkg/fi/cloudup/gce and correct the URL format accordingly","If values came from an older version, run kops update cluster with a current kops to normalize the spec"],"exampleFix":"// before\nsubnets:\n  - id: my-subnet\n// after\nsubnets:\n  - id: https://www.googleapis.com/compute/v1/projects/my-project/regions/us-central1/subnetworks/my-subnet","handlingStrategy":"validation","validationCode":"func validateSubnetURLs(urls map[string]bool) error {\n\tfor u := range urls {\n\t\tif _, err := gce.ParseGoogleCloudURL(u); err != nil {\n\t\t\treturn fmt.Errorf(\"subnet %q is not a valid GCE URL: %w\", u, err)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"used, err := buildUsed(ctx, cluster, cloud)\nif err != nil {\n\tvar raw string\n\tif strings.Contains(err.Error(), \"error parsing subnet url\") {\n\t\tfmt.Sscanf(err.Error(), \"error parsing subnet url %q\", &raw) // inspect and fix spec\n\t}\n\treturn err\n}","preventionTips":["Store subnets as full canonical self-links, never bare names","Let kops generate subnet IDs instead of hand-editing the spec","Round-trip test ParseGoogleCloudURL on any programmatically generated subnet URL","Keep kops and the cluster spec version-aligned to avoid URL format drift"],"tags":["gce","subnet","url-parsing"],"backgroundTag":"invalid-resource-url","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"}