crowdsecurity/crowdsec · error

building kubernetes client config for namespace=%q selector=

Error message

building kubernetes client config for namespace=%q selector=%q: %w

What it means

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.

Source

Thrown at pkg/acquisition/modules/kubernetes/run.go:46

func podRef(p *corev1.Pod) string {
	if p == nil {
		return "<nil pod>"
	}
	return fmt.Sprintf("%s/%s uid=%s phase=%s rv=%s node=%s",
		p.Namespace,
		p.Name,
		p.UID,
		p.Status.Phase,
		p.ResourceVersion,
		p.Spec.NodeName,
	)
}

func (s *Source) initClient() error {
	cfg, err := s.config.buildClientConfig(s.logger)
	if err != nil {
		return fmt.Errorf("building kubernetes client config for namespace=%q selector=%q: %w", s.config.Namespace, s.config.Selector, err)
	}

	client, err := kubernetes.NewForConfig(cfg)
	if err != nil {
		return fmt.Errorf("can't create a kubernetes client for namespace=%q selector=%q: %w", s.config.Namespace, s.config.Selector, err)
	}

	s.client = client

	return nil
}

func (s *Source) initCancels() {
	s.mu.Lock()
	s.cancels = map[types.UID]context.CancelFunc{}
	s.mu.Unlock()
}

View on GitHub (pinned to 909b515798)

Solutions

  1. Ensure ~/.kube/config exists and is valid, or set kube_config to the right path
  2. Check the kube_context name matches a context in the kubeconfig
  3. In-cluster: verify the service account token/CA are mounted
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at pkg/acquisition/modules/kubernetes/run.go:46 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06). Data as JSON: /api/errors/5ccb366e267f0e01. Report an issue: GitHub.