{"record":{"id":"1c063aaf19a84198","repo":"GoogleContainerTools/skaffold","slug":"getting-kubernetes-client-w-1c063a","errorCode":null,"errorMessage":"getting Kubernetes client: %w","messagePattern":"getting Kubernetes client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/sync/sync.go","lineNumber":335,"sourceCode":"\n\t\tif err := Perform(ctx, item.Image, item.Delete, s.deleteFileFn, *s.namespaces, s.kubectl.KubeContext); err != nil {\n\t\t\treturn fmt.Errorf(\"deleting files: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc Perform(ctx context.Context, image string, files syncMap, cmdFn func(context.Context, v1.Pod, v1.Container, syncMap) *exec.Cmd, namespaces []string, kubeContext string) error {\n\tif len(files) == 0 {\n\t\treturn nil\n\t}\n\n\terrs, ctx := errgroup.WithContext(ctx)\n\n\tclient, err := kubernetesclient.Client(kubeContext)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting Kubernetes client: %w\", err)\n\t}\n\n\tnumSynced := 0\n\tfor _, ns := range namespaces {\n\t\tpods, err := client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{\n\t\t\tFieldSelector: fmt.Sprintf(\"status.phase=%s\", v1.PodRunning),\n\t\t})\n\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"getting pods for namespace %q: %w\", ns, err)\n\t\t}\n\n\t\tif len(pods.Items) == 0 {\n\t\t\tlog.Entry(ctx).Warnf(\"no running pods found in namespace %q\", ns)\n\t\t\tcontinue\n\t\t}\n\n\t\tfor _, p := range pods.Items {","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/sync/sync.go#L317-L353","documentation":"Skaffold could not construct an authenticated Kubernetes clientset for the given kubeContext while preparing to sync files. `kubernetesclient.Client(kubeContext)` loads kubeconfig and builds a clientset; any config or connectivity resolution failure at that step is wrapped here. No pod operations have been attempted yet.","triggerScenarios":"`Perform` (called by sync and anonymous sync workers) calls `kubernetesclient.Client(kubeContext)` and it errors — invalid kubeContext name, missing/unreadable kubeconfig, or inability to resolve the cluster for that context.","commonSituations":"--kube-context typo; KUBECONFIG pointing to a missing file; context deleted from kubeconfig; running outside a cluster where in-cluster config is expected but unavailable.","solutions":["Check `kubectl config get-contexts` and pass a valid context via --kube-context","Verify KUBECONFIG env var points to an existing, readable kubeconfig","Test the context with `kubectl get pods --context <ctx>` to reproduce outside Skaffold","If running in-cluster, ensure the pod has a service account and cluster reachability"],"exampleFix":"// before\nskaffold dev --kube-context prod-clustr\n// after\nskaffold dev --kube-context prod-cluster","handlingStrategy":"validation","validationCode":"// validate kube context before calling Perform\nctxs, _ := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n    clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()\nif _, ok := ctxs.Contexts[kubeContext]; !ok {\n    return fmt.Errorf(\"kube context %q not found in kubeconfig\", kubeContext)\n}","typeGuard":"func hasContext(kubeContext string) bool {\n    cfg, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n        clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()\n    if err != nil { return false }\n    _, ok := cfg.Contexts[kubeContext]\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Pass --kube-context explicitly and verify with kubectl config get-contexts","Ensure KUBECONFIG file exists and is readable","Validate context with a cheap kubectl call before the dev loop","Use in-cluster config only where a service account exists"],"tags":["kubernetes","kubeconfig","client-init"],"backgroundTag":"kubeconfig-invalid-context","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"}