{"record":{"id":"4c8301c527bd8452","repo":"kubernetes/kops","slug":"no-networking-mode-set-4c8301","errorCode":null,"errorMessage":"no networking mode set","messagePattern":"no networking mode set","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apis/kops/networking.go","lineNumber":102,"sourceCode":"\tLyftVPC    *LyftVPCNetworkingSpec    `json:\"lyftvpc,omitempty\"`\n\tGCP        *GCPNetworkingSpec        `json:\"gcp,omitempty\"`\n\tKindnet    *KindnetNetworkingSpec    `json:\"kindnet,omitempty\"`\n}\n\n// ConfiguredOptions returns the set of networking options that are configured (non-nil)\n// in the struct.  We only expect a single option to be configured.\nfunc (n *NetworkingSpec) ConfiguredOptions() sets.Set[string] {\n\toptions, err := reflectutils.FindSetFields(n, \"classic\", \"kubenet\", \"external\", \"cni\", \"weave\", \"flannel\", \"calico\", \"kubeRouter\", \"romana\", \"amazonVPC\", \"cilium\", \"lyftvpc\", \"gcp\", \"kindnet\")\n\tif err != nil {\n\t\tklog.Fatalf(\"error getting set fields: %v\", err)\n\t}\n\treturn options\n}\n\n// UsesKubenet returns true if our networking is derived from kubenet\nfunc (n *NetworkingSpec) UsesKubenet() bool {\n\tif n == nil {\n\t\tpanic(\"no networking mode set\")\n\t}\n\tif n.Kubenet != nil {\n\t\treturn true\n\t} else if n.GCP != nil {\n\t\t// GCP IP Alias networking is based on kubenet\n\t\treturn true\n\t} else if n.External != nil {\n\t\t// external is based on kubenet\n\t\treturn true\n\t}\n\n\treturn false\n}\n\n// ClassicNetworkingSpec is the specification of classic networking mode, integrated into kubernetes.\n// Support been removed since Kubernetes 1.4.\ntype ClassicNetworkingSpec struct{}\n","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/apis/kops/networking.go#L84-L120","documentation":"NetworkingSpec.UsesKubenet() panics when called on a nil *NetworkingSpec. Since Go allows calling methods on nil pointer receivers, the library guards here and panics with \"no networking mode set\" to signal that the cluster spec had no networking section, which would make the answer meaningless. Callers such as UsesCNI rely on this never being nil.","triggerScenarios":"Invoking n.UsesKubenet() (or UsesCNI) where n is a nil *NetworkingSpec — typically obtained from a partially constructed ClusterSpec, a decoded config missing the networking block, or code that dereferences spec.Networking without a nil check.","commonSituations":"Programmatically building a ClusterSpec and forgetting to set Networking, loading an old/minimal cluster manifest without a networking section, or unit tests constructing specs with only a few fields populated.","solutions":["Ensure the cluster spec always has a NetworkingSpec populated before calling UsesKubenet/UsesCNI.","Add a nil check in your code: if spec.Networking == nil { initialize or skip } before calling the method.","At cluster-creation/validation time, require a networking section so invalid specs fail early with a clear message.","Default to a known networking mode (e.g. Kubenet or CNI) when constructing specs programmatically."],"exampleFix":"// before\nusesKubenet := spec.Networking.UsesKubenet() // panics if nil\n// after\nif spec.Networking == nil {\n    spec.Networking = &kops.NetworkingSpec{}\n}\nusesKubenet := spec.Networking.UsesKubenet()","handlingStrategy":"type-guard","validationCode":"if spec == nil || spec.Networking == nil {\n    return false, fmt.Errorf(\"cluster spec has no networking section\")\n}","typeGuard":"func hasNetworking(spec *kops.ClusterSpec) bool {\n    return spec != nil && spec.Networking != nil\n}","tryCatchPattern":"// Go panics: recover only as a last resort\nfunc safeUsesKubenet(n *kops.NetworkingSpec) (result bool) {\n    defer func() {\n        if r := recover(); r != nil {\n            result = false\n        }\n    }()\n    return n.UsesKubenet()\n}","preventionTips":["Initialize NetworkingSpec when constructing ClusterSpec programmatically","Validate cluster specs at load time so missing sections fail early","Nil-check spec.Networking before any networking-method call","Keep cluster manifests complete — never omit the networking block"],"tags":["go","panic","nil-pointer","networking"],"backgroundTag":"nil-pointer-panic","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"}