{"record":{"id":"5ccb366e267f0e01","repo":"crowdsecurity/crowdsec","slug":"building-kubernetes-client-config-for-namespace-q","errorCode":null,"errorMessage":"building kubernetes client config for namespace=%q selector=%q: %w","messagePattern":"building kubernetes client config for namespace=%q selector=%q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/kubernetes/run.go","lineNumber":46,"sourceCode":"\nfunc podRef(p *corev1.Pod) string {\n\tif p == nil {\n\t\treturn \"<nil pod>\"\n\t}\n\treturn fmt.Sprintf(\"%s/%s uid=%s phase=%s rv=%s node=%s\",\n\t\tp.Namespace,\n\t\tp.Name,\n\t\tp.UID,\n\t\tp.Status.Phase,\n\t\tp.ResourceVersion,\n\t\tp.Spec.NodeName,\n\t)\n}\n\nfunc (s *Source) initClient() error {\n\tcfg, err := s.config.buildClientConfig(s.logger)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"building kubernetes client config for namespace=%q selector=%q: %w\", s.config.Namespace, s.config.Selector, err)\n\t}\n\n\tclient, err := kubernetes.NewForConfig(cfg)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"can't create a kubernetes client for namespace=%q selector=%q: %w\", s.config.Namespace, s.config.Selector, err)\n\t}\n\n\ts.client = client\n\n\treturn nil\n}\n\nfunc (s *Source) initCancels() {\n\ts.mu.Lock()\n\ts.cancels = map[types.UID]context.CancelFunc{}\n\ts.mu.Unlock()\n}\n","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/kubernetes/run.go#L28-L64","documentation":"initClient fails when building the kube client config (in-cluster or kubeconfig fallback) errors — missing kubeconfig file, bad context name, or invalid credentials — preventing the kubernetes datasource from starting.","triggerScenarios":"Thrown at pkg/acquisition/modules/kubernetes/run.go:46 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure ~/.kube/config exists and is valid, or set kube_config to the right path","Check the kube_context name matches a context in the kubeconfig","In-cluster: verify the service account token/CA are mounted"],"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"}