{"record":{"id":"471b40b5cbb147e5","repo":"crowdsecurity/crowdsec","slug":"can-t-create-a-kubernetes-client-for-namespace-q","errorCode":null,"errorMessage":"can't create a kubernetes client for namespace=%q selector=%q: %w","messagePattern":"can't create a kubernetes client for namespace=%q selector=%q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/kubernetes/run.go","lineNumber":51,"sourceCode":"\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\nfunc (s *Source) Stream(ctx context.Context, out chan pipeline.Event) error {\n\tvar wg sync.WaitGroup\n\n\ts.logger.WithFields(log.Fields{\n\t\t\"namespace\": s.config.Namespace,","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/kubernetes/run.go#L33-L69","documentation":"initClient builds a client-go config and calls kubernetes.NewForConfig; client construction failed (invalid kubeconfig, unreachable cluster settings, bad context), so the kubernetes source cannot start streaming pods for the given namespace/selector.","triggerScenarios":"Thrown at pkg/acquisition/modules/kubernetes/run.go:51 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Validate the apiserver URL and CA data in the kubeconfig","Re-generate credentials (kubeconfig or service account token)","Run 'kubectl get pods' with the same context to confirm it works"],"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"}