{"record":{"id":"a20213724240f4b4","repo":"crowdsecurity/crowdsec","slug":"selector-must-be-set-in-kubernetes-acquisition","errorCode":null,"errorMessage":"selector must be set in kubernetes acquisition","messagePattern":"selector must be set in kubernetes acquisition","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/kubernetes/config.go","lineNumber":60,"sourceCode":"\nfunc (c *Configuration) SetDefaults() {\n\tif c.Namespace == \"\" {\n\t\tc.Namespace = \"default\"\n\t}\n\n\tif c.Mode == \"\" {\n\t\tc.Mode = configuration.TAIL_MODE\n\t}\n\tif c.KubeConfigFile == \"\" {\n\t\tif home, err := os.UserHomeDir(); err == nil {\n\t\t\tc.KubeConfigFile = filepath.Join(home, \".kube\", \"config\")\n\t\t}\n\t}\n}\n\nfunc (c *Configuration) Validate() error {\n\tif c.Selector == \"\" {\n\t\treturn errors.New(\"selector must be set in kubernetes acquisition\")\n\t}\n\tif _, err := labels.Parse(c.Selector); err != nil {\n\t\treturn fmt.Errorf(\"invalid selector %q in kubernetes acquisition: %w\", c.Selector, err)\n\t}\n\tif c.Mode != configuration.TAIL_MODE {\n\t\treturn fmt.Errorf(\"unsupported mode %q in kubernetes acquisition, only %q is supported\", c.Mode, configuration.TAIL_MODE)\n\t}\n\treturn nil\n}\n\nfunc (s *Source) UnmarshalConfig(yamlConfig []byte) error {\n\tcfg, err := ConfigurationFromYAML(yamlConfig)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif s.logger != nil {\n\t\ts.logger.Tracef(\"Kubernetes configuration: %+v\", cfg)","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/kubernetes/config.go#L42-L78","documentation":"The kubernetes acquisition source tails pod logs matching a label selector; without a selector it would have to tail every pod in the cluster. Configuration.Validate() requires Selector to be non-empty so the watch is scoped to the pods you intend to collect from.","triggerScenarios":"Calling Validate() on a kubernetes Configuration whose Selector field is the empty string — typically a YAML config missing the `selector:` key.","commonSituations":"A new acquisition file where the user wrote only source: kubernetes and mode, assuming logs are collected cluster-wide; or a templated selector that rendered empty.","solutions":["Add a label selector to the acquisition YAML, e.g. selector: app=crowdsec-logs (Kubernetes label selector syntax, comma-separated).","Scope tightly to the pods whose logs you need rather than using a broad selector.","Verify the selector syntax with kubectl get pods -l '<selector>' before deploying."],"exampleFix":"// before (yaml)\nsource: kubernetes\nmode: tail\n\n// after (yaml)\nsource: kubernetes\nmode: tail\nselector: app=nginx","handlingStrategy":"validation","validationCode":"if cfg.Selector == \"\" {\n    return fmt.Errorf(\"kubernetes acquisition: selector is required\")\n}\nif _, err := labels.Parse(cfg.Selector); err != nil {\n    return fmt.Errorf(\"kubernetes acquisition: bad selector: %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Test the selector with `kubectl get pods -l '<selector>'` before configuring acquisition.","Annotate pods you want collected with a dedicated label and select on it.","Avoid empty or overly broad selectors that would tail the entire cluster."],"tags":["kubernetes","config-validation","label-selector"],"backgroundTag":"missing-required-config-field","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"}