{"record":{"id":"796f579c56806d2c","repo":"GoogleContainerTools/skaffold","slug":"getting-current-cluster-context-w","errorCode":null,"errorMessage":"getting current cluster context: %w","messagePattern":"getting current cluster context: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/runner/runcontext/context.go","lineNumber":403,"sourceCode":"\n\treturn pipelineConfigName\n}\n\nfunc GetRunContext(ctx context.Context, opts config.SkaffoldOptions, configs []schemaUtil.VersionedConfig) (*RunContext, error) {\n\tpipelines := make(map[string]latest.Pipeline)\n\tvar orderedConfigs []string\n\n\tfor _, cfg := range configs {\n\t\tif cfg != nil {\n\t\t\tpipeline := cfg.(*latest.SkaffoldConfig).Pipeline\n\t\t\tcfgName := getConfigName(cfg.(*latest.SkaffoldConfig).Metadata.Name)\n\t\t\tpipelines[cfgName] = pipeline\n\t\t\torderedConfigs = append(orderedConfigs, cfgName)\n\t\t}\n\t}\n\tkubeConfig, err := kubectx.CurrentConfig()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"getting current cluster context: %w\", err)\n\t}\n\tkubeContext := kubeConfig.CurrentContext\n\tlog.Entry(context.TODO()).Infof(\"Using kubectl context: %s\", kubeContext)\n\n\t// TODO(dgageot): this should be the folder containing skaffold.yaml. Should also be moved elsewhere.\n\tcwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"finding current directory: %w\", err)\n\t}\n\n\t// combine all provided lists of insecure registries into a map\n\tcfgRegistries, err := config.GetInsecureRegistries(opts.GlobalConfig)\n\tif err != nil {\n\t\tlog.Entry(context.TODO()).Warn(\"error retrieving insecure registries from global config: push/pull issues may exist...\")\n\t}\n\tvar regList []string\n\tregList = append(regList, opts.InsecureRegistries...)\n\tfor _, cfgName := range orderedConfigs {","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/runner/runcontext/context.go#L385-L421","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check $KUBECONFIG points to an existing, readable file","Run `kubectl config current-context` to validate the kubeconfig parses","Fix or regenerate ~/.kube/config (e.g. re-login with your cluster tool: gcloud/az/kind)","Unset conflicting KUBECONFIG entries listing multiple broken files"],"exampleFix":"// before\nexport KUBECONFIG=/stale/path/config\n// after\nunset KUBECONFIG  # fall back to ~/.kube/config\n# or point to a valid file\nexport KUBECONFIG=$HOME/.kube/config && kubectl config current-context","handlingStrategy":"validation","validationCode":"kc := os.Getenv(\"KUBECONFIG\"); if kc == \"\" { kc = filepath.Join(os.Getenv(\"HOME\"), \".kube\", \"config\") }\nif _, err := os.Stat(kc); err != nil { return fmt.Errorf(\"kubeconfig missing: %w\", err) }","typeGuard":null,"tryCatchPattern":"runCtx, err := GetRunContext(config, opts)\nif err != nil && strings.Contains(err.Error(), \"getting current cluster context\") {\n    return nil, fmt.Errorf(\"fix kubeconfig (KUBECONFIG=%s): %v\", os.Getenv(\"KUBECONFIG\"), err)\n}\nreturn runCtx, err","preventionTips":["Validate kubeconfig with `kubectl config current-context` in pre-flight","Avoid hand-editing ~/.kube/config; use kubectl/cloud CLIs to regenerate","Check KUBECONFIG env var in containers and CI"],"tags":["skaffold","kubernetes","kubeconfig","go"],"backgroundTag":"kubeconfig-unreadable","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"}