{"record":{"id":"f281d2cc3db8e79c","repo":"GoogleContainerTools/skaffold","slug":"getting-current-cluster-context-w-f281d2","errorCode":null,"errorMessage":"getting current cluster context: %w","messagePattern":"getting current cluster context: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/schema/profiles.go","lineNumber":78,"sourceCode":"\t}\n\n\t// remove profiles section for run modes where profiles are already merged into the main pipeline\n\tswitch opts.Mode() {\n\tcase cfg.RunModes.Build, cfg.RunModes.Dev, cfg.RunModes.Deploy, cfg.RunModes.Debug, cfg.RunModes.Render, cfg.RunModes.Run, cfg.RunModes.Diagnose, cfg.RunModes.Delete:\n\t\tc.Profiles = nil\n\t}\n\treturn profiles, fieldsOverrodeByProfile, checkKubeContextConsistency(contextSpecificProfiles, opts.KubeContext, c.Deploy.KubeContext)\n}\n\nfunc checkKubeContextConsistency(contextSpecificProfiles []string, cliContext, effectiveContext string) error {\n\t// cli flag takes precedence\n\tif cliContext != \"\" {\n\t\treturn nil\n\t}\n\n\tkubeConfig, err := kubectx.CurrentConfig()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"getting current cluster context: %w\", err)\n\t}\n\tcurrentContext := kubeConfig.CurrentContext\n\n\t// nothing to do\n\tif effectiveContext == \"\" || effectiveContext == currentContext || len(contextSpecificProfiles) == 0 {\n\t\treturn nil\n\t}\n\n\treturn fmt.Errorf(\"profiles %q were activated by kube-context %q, but the effective kube-context is %q -- please revise your `profiles.activation` and `deploy.kubeContext` configurations\", contextSpecificProfiles, currentContext, effectiveContext)\n}\n\n// activatedProfiles returns the activated profiles and activated profiles which are kube-context specific.\n// The latter matters for error reporting when the effective kube-context changes.\nfunc activatedProfiles(profiles []latest.Profile, opts cfg.SkaffoldOptions, namedProfiles []string) ([]string, []string, error) {\n\tvar activated []string\n\tvar contextSpecificProfiles []string\n\n\tif opts.ProfileAutoActivation {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/schema/profiles.go#L60-L96","documentation":"After applying profiles, Skaffold checks kube-context consistency between context-activated profiles and the effective deploy.kubeContext. To do so it reads the current context from the local kubeconfig via kubectx.CurrentConfig; if the kubeconfig cannot be loaded or parsed, the failure is wrapped as `getting current cluster context: %w`. The check is skipped entirely when --kubecontext is passed on the CLI.","triggerScenarios":"Auto-activated context-specific profiles exist (or deploy.kubeContext is set) and no --kubecontext flag is given, so checkKubeContextConsistency calls kubectx.CurrentConfig(); this fails when KUBECONFIG points at missing/unreadable/malformed files or the default ~/.kube/config is absent/corrupt.","commonSituations":"Running skaffold in CI without a kubeconfig (no cluster credentials set up); KUBECONFIG env var pointing to a nonexistent path; malformed YAML in ~/.kube/config; permissions issues after switching users or containers.","solutions":["Ensure a valid kubeconfig exists at ~/.kube/config (e.g. `gcloud container clusters get-credentials` or copy from a working machine)","Check the KUBECONFIG env var points at an existing, valid file (or unset it to use the default)","Pass `--kubecontext <ctx>` explicitly, which short-circuits this kubeconfig lookup","Read the wrapped inner error for the concrete parse/read failure and fix the kubeconfig file"],"exampleFix":"# before\nexport KUBECONFIG=~/.kube/nonexistent\n# after\nexport KUBECONFIG=$HOME/.kube/config && kubectl config current-context","handlingStrategy":"fallback","validationCode":"kubeconfig := os.Getenv(\"KUBECONFIG\")\nif kubeconfig == \"\" { kubeconfig = filepath.Join(homedir, \".kube\", \"config\") }\nif _, err := os.Stat(kubeconfig); err != nil {\n    return fmt.Errorf(\"kubeconfig %s missing: run `gcloud container clusters get-credentials` first\", kubeconfig)\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := schema.ApplyProfiles(c, overrides, opts, named); err != nil {\n    if strings.Contains(err.Error(), \"getting current cluster context\") {\n        // retry with explicit kubecontext so the kubeconfig lookup is skipped\n        opts.KubeContext = \"default\"\n        return schema.ApplyProfiles(c, overrides, opts, named)\n    }\n    return err\n}","preventionTips":["Provision kubeconfig before running skaffold in CI (cluster get-credentials or service-account kubeconfig)","Pass --kubecontext explicitly to skip the local kubeconfig read","Verify KUBECONFIG points to a valid file in every environment","Run `kubectl config current-context` as a preflight check"],"tags":["kubernetes","kubeconfig","profiles","configuration"],"backgroundTag":"kubeconfig-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"}