go-kratos/kratos · error
options namespace not full
Error message
options namespace not full
What it means
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.
Source
Thrown at contrib/config/kubernetes/config.go:135
return kvs, nil
}
func (k *kube) configMap(cm v1.ConfigMap) (kvs []*config.KeyValue) {
for name, val := range cm.Data {
k := fmt.Sprintf("%s/%s/%s", k.opts.Namespace, cm.Name, name)
kvs = append(kvs, &config.KeyValue{
Key: k,
Value: []byte(val),
Format: strings.TrimPrefix(filepath.Ext(k), "."),
})
}
return kvs
}
func (k *kube) Load() ([]*config.KeyValue, error) {
if k.opts.Namespace == "" {
return nil, errors.New("options namespace not full")
}
if err := k.init(); err != nil {
return nil, err
}
return k.load()
}
func (k *kube) Watch() (config.Watcher, error) {
return newWatcher(k)
}
View on GitHub (pinned to 668db92c2c)
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
Example fix
// before
src := kubernetes.NewSource()
err := config.New(config.WithSource(src)).Load() // options namespace not full
// after
src := kubernetes.NewSource(
kubernetes.Namespace("production"),
kubernetes.KubeConfig("/etc/kube/config"),
) Defensive patterns
Strategy: validation
Validate before calling
ns := os.Getenv("POD_NAMESPACE")
if ns == "" { ns = "default" }
src := kubernetes.NewSource(kubernetes.Namespace(ns)) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16).
Data as JSON: /api/errors/383d587a9b3974e8.
Report an issue: GitHub.