kubernetes/kops · error
error parsing subnet url %q: %w
Error message
error parsing subnet url %q: %w
What it means
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.
Source
Thrown at upup/pkg/fi/cloudup/gce/network.go:122
if network == nil {
return used, nil
}
subnetURLs := make(map[string]bool)
for _, subnet := range network.Subnetworks {
subnetURLs[subnet] = true
}
if len(subnetURLs) == 0 {
return used, nil
}
klog.Infof("scanning regions for subnetwork CIDR allocations")
regions := make(map[string]bool)
for subnetURL := range subnetURLs {
u, err := ParseGoogleCloudURL(subnetURL)
if err != nil {
return nil, fmt.Errorf("error parsing subnet url %q: %w", subnetURL, err)
}
regions[u.Region] = true
}
var subnets []*compute.Subnetwork
for region := range regions {
l, err := cloud.Compute().Subnetworks().List(ctx, cloud.Project(), region)
if err != nil {
return nil, fmt.Errorf("error listing Subnetworks in region %q: %w", region, err)
}
subnets = append(subnets, l...)
}
for _, subnet := range subnets {
if !subnetURLs[subnet.SelfLink] {
continue
}
if err := used.MarkInUse(subnet.IpCidrRange); err != nil {View on GitHub (pinned to 4c8573c808)
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
Example fix
// before subnets: - id: my-subnet // after subnets: - id: https://www.googleapis.com/compute/v1/projects/my-project/regions/us-central1/subnetworks/my-subnet
Defensive patterns
Strategy: validation
Validate before calling
func validateSubnetURLs(urls map[string]bool) error {
for u := range urls {
if _, err := gce.ParseGoogleCloudURL(u); err != nil {
return fmt.Errorf("subnet %q is not a valid GCE URL: %w", u, err)
}
}
return nil
} Try / catch
used, err := buildUsed(ctx, cluster, cloud)
if err != nil {
var raw string
if strings.Contains(err.Error(), "error parsing subnet url") {
fmt.Sscanf(err.Error(), "error parsing subnet url %q", &raw) // inspect and fix spec
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to parse subnet CIDR %q: %w
- unable to parse instance url %q
- error listing subnetworks: %v
- invalid google cloud URL (content after name): %q
- error listing Subnetworks in region %q: %w
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/a04965c71673e9e6.
Report an issue: GitHub.