{"record":{"id":"995ea8de260d93a7","repo":"GoogleContainerTools/skaffold","slug":"failed-to-get-cluster-info-for-kubecontext-s","errorCode":null,"errorMessage":"failed to get cluster info for kubeContext: `%s`","messagePattern":"failed to get cluster info for kubeContext: `(.+?)`","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/kubernetes/context/context.go","lineNumber":81,"sourceCode":"// create a RESTClient with an in-cluster config.\nfunc GetDefaultRestClientConfig() (*restclient.Config, error) {\n\treturn getRestClientConfig(kubeContext, kubeConfigFile)\n}\n\n// GetRestClientConfig returns a REST client config for API calls against the Kubernetes API for the given context.\nfunc GetRestClientConfig(kubeContext string) (*restclient.Config, error) {\n\treturn getRestClientConfig(kubeContext, kubeConfigFile)\n}\n\n// GetClusterInfo returns the Cluster information for the given kubeContext\nfunc GetClusterInfo(kctx string) (*clientcmdapi.Cluster, error) {\n\trawConfig, err := getCurrentConfig()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tc, found := rawConfig.Clusters[kctx]\n\tif !found {\n\t\treturn nil, fmt.Errorf(\"failed to get cluster info for kubeContext: `%s`\", kctx)\n\t}\n\treturn c, nil\n}\n\nfunc getRestClientConfig(kctx string, kcfg string) (*restclient.Config, error) {\n\tlog.Entry(context.TODO()).Debugf(\"getting client config for kubeContext: `%s`\", kctx)\n\n\trawConfig, err := getCurrentConfig()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tclientConfig := clientcmd.NewNonInteractiveClientConfig(rawConfig, kctx, &clientcmd.ConfigOverrides{CurrentContext: kctx}, clientcmd.NewDefaultClientConfigLoadingRules())\n\trestConfig, err := clientConfig.ClientConfig()\n\tif kctx == \"\" && kcfg == \"\" && clientcmd.IsEmptyConfig(err) {\n\t\tlog.Entry(context.TODO()).Debug(\"no kube-context set and no kubeConfig found, attempting in-cluster config\")\n\t\trestConfig, err := restclient.InClusterConfig()\n\t\tif err != nil {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/kubernetes/context/context.go#L63-L99","documentation":"GetClusterInfo loads the raw kubeconfig via getCurrentConfig and looks up rawConfig.Clusters[kctx]. Note it indexes the Clusters map by the kubeContext name, not by the context's cluster field — if no cluster entry with that name exists, this error is returned. Backticks in the message show the offending kctx value.","triggerScenarios":"GetClusterInfo(kctx) with a kctx string that is not a key in the kubeconfig's clusters map — including passing a context name whose cluster entry is named differently, or a fully unknown context name.","commonSituations":"Typos in --kube-context; using a context name where a cluster name is expected; kubeconfig regenerated after cluster deletion so the cluster entry disappeared.","solutions":["Run `kubectl config get-contexts` and `kubectl config view -o jsonpath='{.clusters[*].name}'` to see valid names","Pass the correct kubeContext (or the cluster name) to the API","Re-add the missing cluster entry: `kubectl config set-cluster <name> --server=<url>`"],"exampleFix":"// before: GetClusterInfo(\"minikube\") but cluster entry is \"minikube-noop\"\n// after: use the exact cluster name from the kubeconfig\nkubectl config view -o jsonpath='{.clusters[*].name}'","handlingStrategy":"validation","validationCode":"raw, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n    clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()\nif err != nil {\n    return err\n}\nif _, ok := raw.Clusters[kctx]; !ok {\n    return fmt.Errorf(\"cluster %q not in kubeconfig; known: %v\", kctx, maps.Keys(raw.Clusters))\n}","typeGuard":"func clusterInfoAvailable(kctx string) bool {\n    raw, _ := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(\n        clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()\n    _, ok := raw.Clusters[kctx]\n    return ok\n}","tryCatchPattern":"info, err := context.GetClusterInfo(kctx)\nif err != nil {\n    return fmt.Errorf(\"cluster %q missing; run `kubectl config view -o jsonpath='{.clusters[*].name}'`: %w\", kctx, err)\n}","preventionTips":["Pass the exact cluster name from `kubectl config view`, not a context alias","List available clusters before calling GetClusterInfo","Re-run cloud-provider credential commands after cluster recreation"],"tags":["kubernetes","kubecontext","kubeconfig"],"backgroundTag":"kubecontext-not-found","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"}