{"record":{"id":"d1a7aec9f0419677","repo":"GoogleContainerTools/skaffold","slug":"getting-k8s-configuration-w","errorCode":null,"errorMessage":"getting k8s configuration: %w","messagePattern":"getting k8s configuration: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/deploy/util/namespaces.go","lineNumber":39,"sourceCode":"\t\"sort\"\n\n\tkubectx \"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubernetes/context\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest\"\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/util\"\n)\n\n// GetAllPodNamespaces lists the namespaces that should be watched.\n// + The namespace passed on the command line\n// + Current kube context's namespace\n// + Namespaces referenced in Helm releases\nfunc GetAllPodNamespaces(configNamespace string, pipelines []latest.Pipeline) ([]string, error) {\n\tnsMap := make(map[string]bool)\n\n\tif configNamespace == \"\" {\n\t\t// Get current kube context's namespace\n\t\tconfig, err := kubectx.CurrentConfig()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"getting k8s configuration: %w\", err)\n\t\t}\n\n\t\tcontext, ok := config.Contexts[config.CurrentContext]\n\t\tif ok {\n\t\t\tnsMap[context.Namespace] = true\n\t\t} else {\n\t\t\tnsMap[\"\"] = true\n\t\t}\n\t} else {\n\t\tnsMap[configNamespace] = true\n\t}\n\n\t// Set additional namespaces each helm release referenced\n\thelmReleasesNamespaces, err := collectHelmReleasesNamespaces(pipelines)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"collecting helm releases namespaces: %w\", err)\n\t}\n\tfor _, namespace := range helmReleasesNamespaces {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/deploy/util/namespaces.go#L21-L57","documentation":"This error is returned by GetAllPodNamespaces when it cannot load the current Kubernetes client configuration (kubeconfig) to determine the namespace of the current context. Skaffold wraps the underlying kubectx.CurrentConfig() failure with this message so callers know the failure happened while resolving which namespaces to watch. It only fires when no explicit namespace was passed, meaning the tool must fall back to the kubeconfig.","triggerScenarios":"Calling GetAllPodNamespaces with configNamespace == \"\" while kubectx.CurrentConfig() fails — typically when KUBECONFIG points to a missing/invalid file, the kubeconfig contains malformed YAML, or no kubeconfig exists at ~/.kube/config.","commonSituations":"Running skaffold dev in a fresh container/CI environment without a kubeconfig; a stale or corrupted ~/.kube/config after switching clusters; KUBECONFIG env var set to a nonexistent path; a context with a missing or malformed namespace entry.","solutions":["Create or restore a valid kubeconfig (e.g. run `kubectl config view` to verify it parses, or re-run `gcloud container clusters get-credentials` / `az aks get-credentials`).","Pass an explicit namespace (e.g. `skaffold dev --namespace myns`) so GetAllPodNamespaces skips kubeconfig resolution entirely.","Fix the KUBECONFIG environment variable to point at an existing, valid kubeconfig file.","Check that the current context in the kubeconfig is well-formed (run `kubectl config current-context`)."],"exampleFix":"// before\nnamespaces, err := util.GetAllPodNamespaces(\"\", pipelines) // fails without kubeconfig\n// after\nnamespaces, err := util.GetAllPodNamespaces(\"mynamespace\", pipelines) // skips kubeconfig lookup","handlingStrategy":"validation","validationCode":"// Pre-flight check before calling GetAllPodNamespaces\nkubeconfig := os.Getenv(\"KUBECONFIG\")\nif kubeconfig == \"\" {\n\tkubeconfig = filepath.Join(os.Getenv(\"HOME\"), \".kube\", \"config\")\n}\nif _, err := os.Stat(kubeconfig); err != nil {\n\treturn fmt.Errorf(\"kubeconfig not found at %s: %w\", kubeconfig, err)\n}","typeGuard":null,"tryCatchPattern":"// Wrap the call and surface kubeconfig remediation advice\nnamespaces, err := util.GetAllPodNamespaces(configNamespace, pipelines)\nif err != nil && strings.Contains(err.Error(), \"getting k8s configuration\") {\n\tlog.Fatalf(\"k8s config unavailable: %v — run 'kubectl config view' or pass --namespace\", err)\n}","preventionTips":["Ensure a valid kubeconfig exists before running skaffold in CI or containers (mount or generate one).","Always pass an explicit --namespace when running in environments without a kubeconfig.","Validate with `kubectl config view` before invoking skaffold commands.","Avoid stale KUBECONFIG env vars pointing at removed files."],"tags":["kubernetes","kubeconfig","configuration","namespace"],"backgroundTag":"missing-kubeconfig","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}