{"record":{"id":"6de8c322afa31b50","repo":"crowdsecurity/crowdsec","slug":"building-client-config-for-context-q-and-kube-con","errorCode":null,"errorMessage":"building client config for context %q and kube config file %s: %w","messagePattern":"building client config for context %q and kube config file (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/kubernetes/utils.go","lineNumber":42,"sourceCode":"\t}\n\n\tif logger != nil {\n\t\tlogger.WithFields(log.Fields{\n\t\t\t\"auth_mode\": \"in_cluster\",\n\t\t\t\"error\":     err,\n\t\t\t\"namespace\": c.Namespace,\n\t\t\t\"selector\":  c.Selector,\n\t\t}).Warn(\"failed to build in-cluster kubernetes client configuration, falling back to kubeconfig\")\n\t}\n\n\tloadingRules := &clientcmd.ClientConfigLoadingRules{ExplicitPath: c.KubeConfigFile}\n\toverrides := &clientcmd.ConfigOverrides{}\n\toverrides.CurrentContext = c.KubeContext\n\n\tcc := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides)\n\tcfg, err = cc.ClientConfig()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"building client config for context %q and kube config file %s: %w\", c.KubeContext, c.KubeConfigFile, err)\n\t}\n\n\tif logger != nil {\n\t\tlogger.WithFields(log.Fields{\n\t\t\t\"auth_mode\":         \"kubeconfig\",\n\t\t\t\"k8s_host\":          cfg.Host,\n\t\t\t\"bearer_token_file\": cfg.BearerTokenFile,\n\t\t\t\"kube_config\":       c.KubeConfigFile,\n\t\t\t\"kube_context\":      c.KubeContext,\n\t\t\t\"namespace\":         c.Namespace,\n\t\t\t\"selector\":          c.Selector,\n\t\t}).Info(\"using kubeconfig-based kubernetes client configuration\")\n\t}\n\n\treturn cfg, nil\n}\n","sourceCodeStart":24,"sourceCodeEnd":59,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/kubernetes/utils.go#L24-L59","documentation":"buildClientConfig fails when the kubeconfig fallback (clientcmd loading with explicit path and context overrides) cannot produce a rest.Config: missing/invalid kubeconfig file or unknown context name. Reached after the in-cluster attempt already failed.","triggerScenarios":"Thrown at pkg/acquisition/modules/kubernetes/utils.go:42 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the kubeconfig file path (kube_config option or ~/.kube/config)","Verify the kube_context name exists in the kubeconfig","Validate with 'kubectl --context <name> get pods'"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}