GoogleContainerTools/skaffold · error
failed to get cluster info for kubeContext: `%s`
Error message
failed to get cluster info for kubeContext: `%s`
What it means
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.
Source
Thrown at pkg/skaffold/kubernetes/context/context.go:81
// create a RESTClient with an in-cluster config.
func GetDefaultRestClientConfig() (*restclient.Config, error) {
return getRestClientConfig(kubeContext, kubeConfigFile)
}
// GetRestClientConfig returns a REST client config for API calls against the Kubernetes API for the given context.
func GetRestClientConfig(kubeContext string) (*restclient.Config, error) {
return getRestClientConfig(kubeContext, kubeConfigFile)
}
// GetClusterInfo returns the Cluster information for the given kubeContext
func GetClusterInfo(kctx string) (*clientcmdapi.Cluster, error) {
rawConfig, err := getCurrentConfig()
if err != nil {
return nil, err
}
c, found := rawConfig.Clusters[kctx]
if !found {
return nil, fmt.Errorf("failed to get cluster info for kubeContext: `%s`", kctx)
}
return c, nil
}
func getRestClientConfig(kctx string, kcfg string) (*restclient.Config, error) {
log.Entry(context.TODO()).Debugf("getting client config for kubeContext: `%s`", kctx)
rawConfig, err := getCurrentConfig()
if err != nil {
return nil, err
}
clientConfig := clientcmd.NewNonInteractiveClientConfig(rawConfig, kctx, &clientcmd.ConfigOverrides{CurrentContext: kctx}, clientcmd.NewDefaultClientConfigLoadingRules())
restConfig, err := clientConfig.ClientConfig()
if kctx == "" && kcfg == "" && clientcmd.IsEmptyConfig(err) {
log.Entry(context.TODO()).Debug("no kube-context set and no kubeConfig found, attempting in-cluster config")
restConfig, err := restclient.InClusterConfig()
if err != nil {View on GitHub (pinned to a1189de023)
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>`
Example fix
// before: GetClusterInfo("minikube") but cluster entry is "minikube-noop"
// after: use the exact cluster name from the kubeconfig
kubectl config view -o jsonpath='{.clusters[*].name}' Defensive patterns
Strategy: validation
Validate before calling
raw, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()
if err != nil {
return err
}
if _, ok := raw.Clusters[kctx]; !ok {
return fmt.Errorf("cluster %q not in kubeconfig; known: %v", kctx, maps.Keys(raw.Clusters))
} Type guard
func clusterInfoAvailable(kctx string) bool {
raw, _ := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(), nil).RawConfig()
_, ok := raw.Clusters[kctx]
return ok
} Try / catch
info, err := context.GetClusterInfo(kctx)
if err != nil {
return fmt.Errorf("cluster %q missing; run `kubectl config view -o jsonpath='{.clusters[*].name}'`: %w", kctx, err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Typos in --kube-context; using a context name where a cluster name is expected; kubeconfig regenerated after cluster deletion so the cluster entry disappeared.
Related errors
- getting Kubernetes client: %w
- unable to connect to Kubernetes: %w
- error getting Kubernetes dynamic client: %w
- error getting Kubernetes client: %w
- resolving namespace: %w
AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05).
Data as JSON: /api/errors/995ea8de260d93a7.
Report an issue: GitHub.