{"record":{"id":"6631585e0ba333ff","repo":"kubernetes/kops","slug":"subnet-not-found-q","errorCode":null,"errorMessage":"subnet not found: %q","messagePattern":"subnet not found: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/model/context.go","lineNumber":84,"sourceCode":"\t// AdditionalObjects holds cluster-asssociated configuration objects, other than the Cluster and InstanceGroups.\n\tAdditionalObjects kubemanifest.ObjectList\n}\n\n// GatherSubnets maps the subnet names in an InstanceGroup to the ClusterSubnetSpec objects (which are stored on the Cluster)\nfunc (b *KopsModelContext) GatherSubnets(ig *kops.InstanceGroup) ([]*kops.ClusterSubnetSpec, error) {\n\tvar subnets []*kops.ClusterSubnetSpec\n\tvar subnetType kops.SubnetType\n\n\tfor _, subnetName := range ig.Spec.Subnets {\n\t\tvar matches []*kops.ClusterSubnetSpec\n\t\tfor i := range b.Cluster.Spec.Networking.Subnets {\n\t\t\tclusterSubnet := &b.Cluster.Spec.Networking.Subnets[i]\n\t\t\tif clusterSubnet.Name == subnetName {\n\t\t\t\tmatches = append(matches, clusterSubnet)\n\t\t\t}\n\t\t}\n\t\tif len(matches) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"subnet not found: %q\", subnetName)\n\t\t}\n\t\tif len(matches) > 1 {\n\t\t\treturn nil, fmt.Errorf(\"found multiple subnets with name: %q\", subnetName)\n\t\t}\n\t\tsubnets = append(subnets, matches[0])\n\n\t\t// @step: check the instance is not cross subnet types\n\t\tswitch subnetType {\n\t\tcase \"\":\n\t\t\tsubnetType = matches[0].Type\n\t\tdefault:\n\t\t\tif matches[0].Type != subnetType {\n\t\t\t\treturn nil, fmt.Errorf(\"found subnets of different types: %v\", strings.Join([]string{string(subnetType), string(matches[0].Type)}, \",\"))\n\t\t\t}\n\t\t}\n\t}\n\n\treturn subnets, nil","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/model/context.go#L66-L102","documentation":"NodeupModelContext looks up a subnet by name among the cluster's spec.networking.subnets. If no subnet in the cluster spec matches the requested subnetName, it returns this error; the caller cannot build node/instance-group configuration without a valid subnet reference. A similar sibling error fires when more than one subnet shares the name.","triggerScenarios":"Referencing a subnet name in an instance group (or topology/utility subnet lookup) that does not exist in cluster.spec.networking.subnets — typically a typo, a deleted subnet, or using a subnet from another cluster/zone.","commonSituations":"Renaming or deleting subnets in the cluster spec while instance groups still reference the old name; typos in `instancegroup.spec.subnets`; splitting a cluster across regions with mismatched subnet lists.","solutions":["List subnets with `kops get cluster -o yaml` and compare against the subnet name referenced by your instance group.","Fix the typo or update the instance group: `kops edit ig <name>` and set subnets to an existing subnet name.","If the subnet was removed, re-add it to spec.networking.subnets or delete/recreate the instance group in a valid subnet.","Ensure the referenced subnet name is unique in the spec (duplicate names trigger the 'found multiple subnets' error)."],"exampleFix":"// before (instance group yaml)\nsubnets: [\"us-east-1b\"]   # cluster only defines subnet \"us-east-1a\"\n// after\nsubnets: [\"us-east-1a\"]","handlingStrategy":"validation","validationCode":"func subnetExists(cluster *kops.Cluster, name string) bool {\n    for _, s := range cluster.Spec.Networking.Subnets {\n        if s.Name == name { return true }\n    }\n    return false\n}\n// call before applying instance groups referencing subnets","typeGuard":"func findSubnet(cluster *kops.Cluster, name string) *kops.ClusterSubnetSpec {\n    for i := range cluster.Spec.Networking.Subnets {\n        if cluster.Spec.Networking.Subnets[i].Name == name {\n            return &cluster.Spec.Networking.Subnets[i]\n        }\n    }\n    return nil\n}","tryCatchPattern":"subnets, err := modelContext.FindSubnets(c, nodeupConfig)\nif err != nil && strings.Contains(err.Error(), \"subnet not found\") {\n    return fmt.Errorf(\"instance group references missing subnet; run `kops get ig` and fix subnets: %w\", err)\n}","preventionTips":["After renaming/deleting subnets in the cluster spec, update every instance group's subnets list.","Keep subnet names unique within a cluster.","Script a pre-apply check that all instance group subnet names exist in spec.networking.subnets."],"tags":["subnet","instance-group","cluster-spec","lookup"],"backgroundTag":"subnet-not-found","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"}