{"record":{"id":"5b017c3533a79c79","repo":"GoogleContainerTools/skaffold","slug":"getting-client-config-for-kubernetes-client-w","errorCode":null,"errorMessage":"getting client config for Kubernetes client: %w","messagePattern":"getting client config for Kubernetes client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/client/client.go","lineNumber":39,"sourceCode":"\n\t\"k8s.io/client-go/dynamic\"\n\t\"k8s.io/client-go/kubernetes\"\n\t_ \"k8s.io/client-go/plugin/pkg/client/auth\" // Initialize all known client auth plugins\n\n\t\"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubernetes/context\"\n)\n\n// for tests\nvar (\n\tClient        = getClientset\n\tDynamicClient = getDynamicClient\n\tDefaultClient = getDefaultClientset\n)\n\nfunc getClientset(kubeContext string) (kubernetes.Interface, error) {\n\tconfig, err := context.GetRestClientConfig(kubeContext)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting client config for Kubernetes client: %w\", err)\n\t}\n\treturn kubernetes.NewForConfig(config)\n}\n\nfunc getDynamicClient(kubeContext string) (dynamic.Interface, error) {\n\tconfig, err := context.GetRestClientConfig(kubeContext)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting client config for dynamic client: %w\", err)\n\t}\n\treturn dynamic.NewForConfig(config)\n}\n\nfunc getDefaultClientset() (kubernetes.Interface, error) {\n\tconfig, err := context.GetDefaultRestClientConfig()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting client config for Kubernetes client: %w\", err)\n\t}\n\treturn kubernetes.NewForConfig(config)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/client/client.go#L21-L57","documentation":"getClientset builds a Kubernetes typed clientset from a rest config produced by context.GetRestClientConfig(kubeContext). If that config construction fails (kubeconfig unreadable, context missing, in-cluster fallback failing), the wrapped error is returned. The result is memoized, so the first clientset request triggers it.","triggerScenarios":"GetClientset(kubeContext) when the kubeconfig file is missing/malformed, the named kubeContext has no cluster, or when no context and no kubeconfig exist and InClusterConfig() also fails (not running in a pod).","commonSituations":"Wrong KUBECONFIG path, invalid YAML in ~/.kube/config, referencing a context that was deleted, running a command expecting in-cluster credentials outside a cluster.","solutions":["Run `kubectl config get-contexts` to confirm the kubeContext exists and kubeconfig is valid","Fix KUBECONFIG / --kubeconfig to point at a readable kubeconfig","If no kubeconfig is intended, run inside a pod with a service account or provide valid in-cluster env"],"exampleFix":"// before: KUBECONFIG=/wrong/path -> config load fails\n// after\nexport KUBECONFIG=$HOME/.kube/config\nkubectl config current-context","handlingStrategy":"validation","validationCode":"rules := clientcmd.NewDefaultClientConfigLoadingRules()\nraw, err := rules.Load()\nif err != nil {\n    return fmt.Errorf(\"kubeconfig invalid: %w\", err)\n}\nif _, ok := raw.Contexts[kubeContext]; !ok {\n    return fmt.Errorf(\"kubeContext %q not found; run kubectl config get-contexts\", kubeContext)\n}","typeGuard":"func kubeContextExists(kubeContext string) bool {\n    raw, _ := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n        clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()\n    _, ok := raw.Contexts[kubeContext]\n    return ok\n}","tryCatchPattern":"clientset, err := client.GetClientset(kubeContext)\nif err != nil {\n    return fmt.Errorf(\"check KUBECONFIG and `kubectl config get-contexts` for %q: %w\", kubeContext, err)\n}","preventionTips":["Validate with `kubectl config get-contexts` before running Skaffold","Set KUBECONFIG explicitly when using non-default kubeconfig locations","Delete stale contexts after tearing clusters down"],"tags":["kubernetes","kubeconfig","client-config"],"backgroundTag":"invalid-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"}