kubernetes/kops · critical

clientset is not initialized

Error message

clientset is not initialized

What it means

The kops-controller main function guards against a nil Kubernetes clientset when Cluster API (CAPI) support is enabled. If CAPI is on but clientset construction failed earlier (or was skipped), main logs this and exits with status 1.

Source

Thrown at cmd/kops-controller/main.go:273

	if opt.EnableCloudIPAM {
		if err := setupCloudIPAM(ctx, mgr, &opt); err != nil {
			setupLog.Error(err, "unable to setup cloud IPAM")
			os.Exit(1)

		}
	}

	if err := addNodeController(ctx, mgr, &opt); err != nil {
		setupLog.Error(err, "unable to create controller", "controller", "NodeController")
		os.Exit(1)
	}

	// +kubebuilder:scaffold:builder

	if opt.CAPI.IsEnabled() {
		if clientset == nil {
			setupLog.Error(fmt.Errorf("clientset is not initialized"), "registering Cluster API controllers")
			os.Exit(1)
		}
		if err := clusterapi.RegisterControllers(mgr, clientset); err != nil {
			setupLog.Error(err, "registering Cluster API controllers")
			os.Exit(1)
		}
	}

	setupLog.Info("starting manager")
	if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil {
		setupLog.Error(err, "problem running manager")
		os.Exit(1)
	}
}

func buildScheme(opt *config.Options) (*runtime.Scheme, error) {
	scheme := runtime.NewScheme()
	if err := corev1.AddToScheme(scheme); err != nil {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Check earlier startup logs for the clientset creation failure that left it nil
  2. Verify kubeconfig/InClusterConfig is valid and mounted
  3. If CAPI is not intended, unset the --cluster-api flag
  4. File a bug if clientset init succeeded but the variable is still nil
Defensive patterns

Strategy: validation

Validate before calling

if opt.CAPI.IsEnabled() && clientset == nil {
	setupLog.Error(fmt.Errorf("clientset is not initialized"), "registering Cluster API controllers")
	os.Exit(1)
}

Type guard

if clientset == nil {
	// fail fast before RegisterControllers
}

Prevention

When it happens

Trigger: opt.CAPI.IsEnabled() is true while the clientset variable remains nil — the clientset creation code path failed or was not reached before controller registration.

Common situations: Misconfigured --cluster-api flag combined with a kubeconfig error that silently skipped clientset construction, or a code-path regression in main where clientset init is conditional.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/4166dc0c3578f9d2. Report an issue: GitHub.