GoogleContainerTools/skaffold · error

getting current cluster context: %w

Error message

getting current cluster context: %w

What it means

While building the RunContext, Skaffold loads the current kubeconfig via kubectx.CurrentConfig to determine the active cluster context. If kubeconfig cannot be read or parsed, the failure is wrapped as "getting current cluster context: %w" and GetRunContext returns early.

Source

Thrown at pkg/skaffold/runner/runcontext/context.go:403

	return pipelineConfigName
}

func GetRunContext(ctx context.Context, opts config.SkaffoldOptions, configs []schemaUtil.VersionedConfig) (*RunContext, error) {
	pipelines := make(map[string]latest.Pipeline)
	var orderedConfigs []string

	for _, cfg := range configs {
		if cfg != nil {
			pipeline := cfg.(*latest.SkaffoldConfig).Pipeline
			cfgName := getConfigName(cfg.(*latest.SkaffoldConfig).Metadata.Name)
			pipelines[cfgName] = pipeline
			orderedConfigs = append(orderedConfigs, cfgName)
		}
	}
	kubeConfig, err := kubectx.CurrentConfig()
	if err != nil {
		return nil, fmt.Errorf("getting current cluster context: %w", err)
	}
	kubeContext := kubeConfig.CurrentContext
	log.Entry(context.TODO()).Infof("Using kubectl context: %s", kubeContext)

	// TODO(dgageot): this should be the folder containing skaffold.yaml. Should also be moved elsewhere.
	cwd, err := os.Getwd()
	if err != nil {
		return nil, fmt.Errorf("finding current directory: %w", err)
	}

	// combine all provided lists of insecure registries into a map
	cfgRegistries, err := config.GetInsecureRegistries(opts.GlobalConfig)
	if err != nil {
		log.Entry(context.TODO()).Warn("error retrieving insecure registries from global config: push/pull issues may exist...")
	}
	var regList []string
	regList = append(regList, opts.InsecureRegistries...)
	for _, cfgName := range orderedConfigs {

View on GitHub (pinned to a1189de023)

Solutions

  1. Check $KUBECONFIG points to an existing, readable file
  2. Run `kubectl config current-context` to validate the kubeconfig parses
  3. Fix or regenerate ~/.kube/config (e.g. re-login with your cluster tool: gcloud/az/kind)
  4. Unset conflicting KUBECONFIG entries listing multiple broken files

Example fix

// before
export KUBECONFIG=/stale/path/config
// after
unset KUBECONFIG  # fall back to ~/.kube/config
# or point to a valid file
export KUBECONFIG=$HOME/.kube/config && kubectl config current-context
Defensive patterns

Strategy: validation

Validate before calling

kc := os.Getenv("KUBECONFIG"); if kc == "" { kc = filepath.Join(os.Getenv("HOME"), ".kube", "config") }
if _, err := os.Stat(kc); err != nil { return fmt.Errorf("kubeconfig missing: %w", err) }

Try / catch

runCtx, err := GetRunContext(config, opts)
if err != nil && strings.Contains(err.Error(), "getting current cluster context") {
    return nil, fmt.Errorf("fix kubeconfig (KUBECONFIG=%s): %v", os.Getenv("KUBECONFIG"), err)
}
return runCtx, err

Prevention

When it happens

Trigger: Any command that constructs a RunContext when kubectx.CurrentConfig() fails — malformed or unreadable $KUBECONFIG / ~/.kube/config, invalid YAML, or a KUBECONFIG path pointing to a missing file.

Common situations: KUBECONFIG env var set to a nonexistent path, hand-edited kubeconfig with syntax errors, corrupted config after tooling upgrades, or running in a container without a mounted kubeconfig.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/796f579c56806d2c. Report an issue: GitHub.