kubernetes/kops · error

error getting clientset

Error message

error getting clientset: %v

What it means

After loading the cluster, RunCreateKeypair builds a kops clientset via f.KopsClient(). Failure constructing the API client (registry/REST client wiring against the configured state store) is wrapped with this message.

Solutions

  1. Retry with the same kOps version that manages the cluster (avoid version skew).
  2. Verify state store config (`kops get clusters` works) to isolate client construction from auth.
  3. Set --v=8 (or KOPS debug flags) for verbose error detail.
  4. Reinstall/refresh kops if the binary or its vendored config is inconsistent.

Example fix

// before
kops create keypair cluster.k8s.local --keyset ca   # different kops version than cluster
// after
kops version  # match binary version to cluster's kops version, then retry
kops create keypair cluster.k8s.local --keyset ca
Defensive patterns

Strategy: try-catch

Validate before calling

kops get clusters >/dev/null 2>&1 || { echo "kops client cannot initialize against state store"; exit 1; }

Try / catch

if ! out=$(kops create keypair "$CLUSTER" --keyset ca 2>&1); then
  case "$out" in
    *"error getting clientset"*) echo "Client init failed; check kops version and config: $out";;
  esac
fi

Prevention

When it happens

Trigger: f.KopsClient() returns an error during `kops create keypair` — typically bad kOps configuration, unresolvable state store, or an internal client initialization failure (cmd/kops/create_keypair.go:158).

Common situations: Corrupt or incompatible kops config in the state store; version mismatch between kOps CLI and state-store layout; environment misconfiguration affecting client construction.

Related errors


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

Appendix: source

Thrown at cmd/kops/create_keypair.go:158

	cmd.Flags().BoolVar(&options.Primary, "primary", options.Primary, "Make the keypair the one used to issue certificates")

	return cmd
}

// RunCreateKeypair adds a custom CA certificate and private key.
func RunCreateKeypair(ctx context.Context, f *util.Factory, out io.Writer, options *CreateKeypairOptions) error {
	if !rotatableKeysetFilter(options.Keyset, nil) {
		return fmt.Errorf("adding keypair to %q is not supported", options.Keyset)
	}

	cluster, err := GetCluster(ctx, f, options.ClusterName)
	if err != nil {
		return fmt.Errorf("error getting cluster: %q: %v", options.ClusterName, err)
	}

	clientSet, err := f.KopsClient()
	if err != nil {
		return fmt.Errorf("error getting clientset: %v", err)
	}

	keyStore, err := clientSet.KeyStore(cluster)
	if err != nil {
		return fmt.Errorf("error getting keystore: %v", err)
	}

	if options.Keyset != "all" {
		return createKeypair(ctx, out, options, options.Keyset, keyStore)
	}

	keysets, err := keyStore.ListKeysets()
	if err != nil {
		return fmt.Errorf("listing keysets: %v", err)
	}

	for name := range keysets {
		if rotatableKeysetFilter(name, nil) {

View on GitHub (pinned to 4c8573c808)