{"record":{"id":"383d587a9b3974e8","repo":"go-kratos/kratos","slug":"options-namespace-not-full","errorCode":null,"errorMessage":"options namespace not full","messagePattern":"options namespace not full","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"contrib/config/kubernetes/config.go","lineNumber":135,"sourceCode":"\treturn kvs, nil\n}\n\nfunc (k *kube) configMap(cm v1.ConfigMap) (kvs []*config.KeyValue) {\n\tfor name, val := range cm.Data {\n\t\tk := fmt.Sprintf(\"%s/%s/%s\", k.opts.Namespace, cm.Name, name)\n\n\t\tkvs = append(kvs, &config.KeyValue{\n\t\t\tKey:    k,\n\t\t\tValue:  []byte(val),\n\t\t\tFormat: strings.TrimPrefix(filepath.Ext(k), \".\"),\n\t\t})\n\t}\n\treturn kvs\n}\n\nfunc (k *kube) Load() ([]*config.KeyValue, error) {\n\tif k.opts.Namespace == \"\" {\n\t\treturn nil, errors.New(\"options namespace not full\")\n\t}\n\tif err := k.init(); err != nil {\n\t\treturn nil, err\n\t}\n\treturn k.load()\n}\n\nfunc (k *kube) Watch() (config.Watcher, error) {\n\treturn newWatcher(k)\n}\n","sourceCodeStart":117,"sourceCodeEnd":146,"githubUrl":"https://github.com/go-kratos/kratos/blob/668db92c2c001e9552594ba5a8aede8456af6d7e/contrib/config/kubernetes/config.go#L117-L146","documentation":"Returned by kube.Load in the kubernetes config source (contrib/config/kubernetes/config.go:135). The source lists ConfigMaps via CoreV1().ConfigMaps(k.opts.Namespace), so a namespace is mandatory; if the options.Namespace field is empty (kubernetes.NewSource called without the Namespace option) Load refuses to run. Note this triggers at Load time, not at NewSource time, because NewSource performs no validation.","triggerScenarios":"kubernetes.NewSource() with no options followed by config.New(...).Load(); or passing only LabelSelector/FieldSelector/KubeConfig options without kubernetes.Namespace(\"...\"). Also triggered by a namespace value that is literally the empty string.","commonSituations":"Running the app outside a cluster with a kubeconfig but forgetting the Namespace option; migrating from file config to k8s ConfigMaps and assuming the namespace comes from the kubeconfig context (it does not - it comes only from the option); CI environments where the option was stripped.","solutions":["Pass kubernetes.Namespace to NewSource, e.g. kubernetes.NewSource(kubernetes.Namespace(\"default\"))","If out-of-cluster, combine with kubernetes.KubeConfig(\"~/.kube/config\")","Ensure the target namespace actually contains ConfigMaps matching your selectors, otherwise Load returns an empty key set"],"exampleFix":"// before\nsrc := kubernetes.NewSource()\nerr := config.New(config.WithSource(src)).Load() // options namespace not full\n\n// after\nsrc := kubernetes.NewSource(\n    kubernetes.Namespace(\"production\"),\n    kubernetes.KubeConfig(\"/etc/kube/config\"),\n)","handlingStrategy":"validation","validationCode":"ns := os.Getenv(\"POD_NAMESPACE\")\nif ns == \"\" { ns = \"default\" }\nsrc := kubernetes.NewSource(kubernetes.Namespace(ns))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass kubernetes.Namespace - it is not derived from kubeconfig context","In-cluster, read the namespace from the pod's serviceaccount file or POD_NAMESPACE env as a fallback","Remember validation happens at Load(), so a missing option surfaces as a startup failure, not a construction failure"],"tags":["config","kubernetes","configmap","load-time-validation"],"backgroundTag":null,"analyzedSha":"668db92c2c001e9552594ba5a8aede8456af6d7e","analyzedAt":"2026-08-16T02:07:20.704Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}