{"record":{"id":"3d1f9ef07a0f6c0e","repo":"kubernetes/kops","slug":"cannot-parse-network-name-q-as-either-project-net","errorCode":null,"errorMessage":"cannot parse network name %q as either project/network or network","messagePattern":"cannot parse network name %q as either project/network or network","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/network.go","lineNumber":71,"sourceCode":"\t\treturn performSubnetAssignments(ctx, c, cloudObj)\n\t}\n}\n\n// ParseNameAndProjectFromNetworkID will take in the GCE-flavored network ID,\n// and return the project and name of the resource.  The permitted formats are\n// \"network-name\", or \"project-id/network-name\".  Empty string is also accepted.\nfunc ParseNameAndProjectFromNetworkID(networkID string) (string, string, error) {\n\tvar name, project string\n\tif networkID == \"\" {\n\t\treturn \"\", \"\", nil\n\t}\n\tname = networkID\n\t// If the network ID has a slash, then we take the part before the / as a project ID.\n\t// Otherwise, we assume the entire provided value is the network ID.\n\tif strings.Contains(name, \"/\") {\n\t\tnameParts := strings.Split(name, \"/\")\n\t\tif len(nameParts) > 2 {\n\t\t\treturn \"\", \"\", fmt.Errorf(\"cannot parse network name %q as either project/network or network\", name)\n\t\t}\n\t\tname = nameParts[1]\n\t\tproject = nameParts[0]\n\t}\n\treturn name, project, nil\n}\n\nfunc buildUsed(ctx context.Context, c *kops.Cluster, cloudObj fi.Cloud) (*subnet.CIDRMap, error) {\n\tnetworkName := c.Spec.Networking.NetworkID\n\tif networkName == \"\" {\n\t\tnetworkName = SafeClusterName(c.Name)\n\t}\n\n\tcloud := cloudObj.(GCECloud)\n\tnetworkName, projectName, err := ParseNameAndProjectFromNetworkID(networkName)\n\tif err != nil {\n\t\treturn nil, err\n\t}","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/network.go#L53-L89","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nnetworking:\n  networkID: https://www.googleapis.com/compute/v1/projects/my-project/global/networks/default\n// after\nnetworking:\n  networkID: my-project/default","handlingStrategy":"validation","validationCode":"func validNetworkID(id string) error {\n\tif id == \"\" { return nil }\n\tparts := strings.Split(id, \"/\")\n\tif len(parts) > 2 {\n\t\treturn fmt.Errorf(\"networkID must be 'name' or 'project/name', got %q\", id)\n\t}\n\treturn nil\n}","typeGuard":"func isFullSelfLink(id string) bool {\n\treturn strings.HasPrefix(id, \"http://\") || strings.HasPrefix(id, \"https://\") || strings.Count(id, \"/\") > 1\n}","tryCatchPattern":"name, project, err := gce.ParseNameAndProjectFromNetworkID(networkID)\nif err != nil {\n\treturn fmt.Errorf(\"spec.networking.networkID is invalid: %w; use 'name' or 'project/name'\", err)\n}","preventionTips":["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"],"tags":["gce","network","configuration","parsing"],"backgroundTag":"invalid-resource-id-format","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"}