kubernetes/kops · error
cannot parse network name %q as either project/network or ne
Error message
cannot parse network name %q as either project/network or network
What it means
ParseNameAndProjectFromNetworkID accepts a GCE network ID in only two forms: 'network-name' or 'project-id/network-name'. If the value contains more than one slash (three or more slash-separated parts), the format is unparseable and this error is thrown. Callers like buildUsed, LinkToNetwork, Find, and GetApiIngressStatus depend on it to resolve the network resource.
Source
Thrown at upup/pkg/fi/cloudup/gce/network.go:71
return performSubnetAssignments(ctx, c, cloudObj)
}
}
// ParseNameAndProjectFromNetworkID will take in the GCE-flavored network ID,
// and return the project and name of the resource. The permitted formats are
// "network-name", or "project-id/network-name". Empty string is also accepted.
func ParseNameAndProjectFromNetworkID(networkID string) (string, string, error) {
var name, project string
if networkID == "" {
return "", "", nil
}
name = networkID
// If the network ID has a slash, then we take the part before the / as a project ID.
// Otherwise, we assume the entire provided value is the network ID.
if strings.Contains(name, "/") {
nameParts := strings.Split(name, "/")
if len(nameParts) > 2 {
return "", "", fmt.Errorf("cannot parse network name %q as either project/network or network", name)
}
name = nameParts[1]
project = nameParts[0]
}
return name, project, nil
}
func buildUsed(ctx context.Context, c *kops.Cluster, cloudObj fi.Cloud) (*subnet.CIDRMap, error) {
networkName := c.Spec.Networking.NetworkID
if networkName == "" {
networkName = SafeClusterName(c.Name)
}
cloud := cloudObj.(GCECloud)
networkName, projectName, err := ParseNameAndProjectFromNetworkID(networkName)
if err != nil {
return nil, err
}View on GitHub (pinned to 4c8573c808)
Solutions
- Change networkID to just the network name, e.g. 'default'
- Or use the two-part form 'project-id/network-name', e.g. 'my-project/default'
- Strip the URL prefix programmatically before assigning networkID in the cluster spec
Example fix
// before networking: networkID: https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default // after networking: networkID: my-project/default
Defensive patterns
Strategy: validation
Validate before calling
func validNetworkID(id string) error {
if id == "" { return nil }
parts := strings.Split(id, "/")
if len(parts) > 2 {
return fmt.Errorf("networkID must be 'name' or 'project/name', got %q", id)
}
return nil
} Type guard
func isFullSelfLink(id string) bool {
return strings.HasPrefix(id, "http://") || strings.HasPrefix(id, "https://") || strings.Count(id, "/") > 1
} Try / catch
name, project, err := gce.ParseNameAndProjectFromNetworkID(networkID)
if err != nil {
return fmt.Errorf("spec.networking.networkID is invalid: %w; use 'name' or 'project/name'", err)
} Prevention
- Never paste full GCE self-links into networkID; use 'name' or 'project/name' only
- Validate cluster specs with 'kops validate' / spec linting before apply
- Sanitize or strip URL prefixes programmatically when importing configs from the GCP console
- Document the accepted networkID formats for cluster spec authors
When it happens
Trigger: Setting spec.networking.networkID to a full GCE self-link such as 'https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default', or 'projects/my-project/global/networks/default' — anything with two or more slashes.
Common situations: Pasting the network's full REST self-link or URI from the GCP console into the kops cluster spec instead of just the name or project/name pair.
Related errors
- failed to parse subnet CIDR %q: %w
- Error too many '=' (%d) in %s
- unable to parse KubernetesVersion %q: %w
- error parsing configuration: %v
- providerID %q did not match our project %q
AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05).
Data as JSON: /api/errors/3d1f9ef07a0f6c0e.
Report an issue: GitHub.