kubernetes/kops · error

getting cluster: %q: %v

Error message

getting cluster: %q: %v

What it means

After validating the keyset, RunPromoteKeypair calls GetCluster to fetch the cluster spec from the state store. Any failure there (cluster not found, state store unreachable, auth problems) is wrapped as "getting cluster: %q: %v".

Source

Thrown at cmd/kops/promote_keypair.go:123

			return completePromoteKeyset(cmd.Context(), f, options, args, toComplete)
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			return RunPromoteKeypair(cmd.Context(), f, out, options)
		},
	}

	return cmd
}

// RunPromoteKeypair promotes a keypair.
func RunPromoteKeypair(ctx context.Context, f *util.Factory, out io.Writer, options *PromoteKeypairOptions) error {
	if !rotatableKeysetFilter(options.Keyset, nil) {
		return fmt.Errorf("promoting keypairs for %q is not supported", options.Keyset)
	}

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

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

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

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

	keysets, err := keyStore.ListKeysets()
	if err != nil {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Verify the cluster exists: `kops get clusters` and correct --name
  2. Check KOPS_STATE_STORE points to the correct bucket and is reachable
  3. Refresh cloud credentials (aws s3 ls / gcloud auth) and retry
  4. Inspect the inner %v error for the precise storage/auth cause

Example fix

// before
kops promote keypair all  # KOPS_STATE_STORE unset
// after
export KOPS_STATE_STORE=s3://my-state-bucket
kops promote keypair all --name mycluster.k8s.local
Defensive patterns

Strategy: try-catch

Validate before calling

kops get cluster "$CLUSTER" >/dev/null || { echo "cluster not reachable/found"; exit 1; }

Try / catch

err := RunPromoteKeypair(ctx, f, out, opts)
if err != nil && strings.Contains(err.Error(), "getting cluster") {
	log.Printf("check state store & cluster name: %v", err)
}

Prevention

When it happens

Trigger: `kops promote keypair ... --name <cluster>` where the cluster does not exist in the state store, or the state store (S3/GCS/etc.) is unreachable or credentials are missing.

Common situations: Wrong --name (typo in cluster name); KOPS_STATE_STORE not set or pointing at a wrong/deleted bucket; expired cloud credentials; network restrictions blocking the state store.

Related errors


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