kubernetes/kops · error

cluster name did not match expected name: %v vs %v

Error message

cluster name did not match expected name: %v vs %v

What it means

After loading the cluster, GetCluster defensively compares the requested cluster name against cluster.ObjectMeta.Name and fails if they differ. This guards against passing a name that resolves to a different cluster object in the state store (e.g. an alias, partial name, or stale reference).

Source

Thrown at cmd/kops/root.go:357

	if clusterName == "" {
		return nil, field.Required(field.NewPath("clusterName"), "Cluster name is required")
	}

	clientset, err := factory.KopsClient()
	if err != nil {
		return nil, err
	}

	cluster, err := clientset.GetCluster(ctx, clusterName)
	if err != nil {
		return nil, fmt.Errorf("error reading cluster configuration: %v", err)
	}
	if cluster == nil {
		return nil, fmt.Errorf("cluster %q not found", clusterName)
	}

	if clusterName != cluster.ObjectMeta.Name {
		return nil, fmt.Errorf("cluster name did not match expected name: %v vs %v", clusterName, cluster.ObjectMeta.Name)
	}
	return cluster, nil
}

func GetClusterNameForCompletionNoKubeconfig(clusterArgs []string) (clusterName string, completions []string, directive cobra.ShellCompDirective) {
	if len(clusterArgs) > 0 {
		return clusterArgs[0], nil, 0
	}

	if rootCommand.clusterName != "" {
		return rootCommand.clusterName, nil, 0
	}

	return "", []string{"--name"}, cobra.ShellCompDirectiveNoFileComp
}

func GetClusterForCompletion(ctx context.Context, factory commandutils.Factory, clusterArgs []string) (cluster *kopsapi.Cluster, clientSet simple.Clientset, completions []string, directive cobra.ShellCompDirective) {
	clusterName := ""

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Compare the two names printed in the error and re-run with the exact name from the second (%v vs %v shows expected vs found).
  2. Run kops get clusters to see canonical names stored in the state store.
  3. Quote the cluster name in your shell and strip any trailing whitespace or slash.
  4. Ensure KOPS_CLUSTER_NAME/--name matches the metadata name exactly.

Example fix

// before
kops create ig nodes --name Cluster.K8s.Local
// error: cluster name did not match expected name: Cluster.K8s.Local vs cluster.k8s.local
// after
kops create ig nodes --name cluster.k8s.local
Defensive patterns

Strategy: validation

Validate before calling

CANONICAL=$(kops get clusters -o json | jq -r '.items[].metadata.name' | grep -Fx "$CLUSTER_NAME") || { echo "use exact name"; exit 1; }

Try / catch

cluster, err := GetCluster(ctx, clusterName)
if err != nil {
    return err
}
if cluster.ObjectMeta.Name != clusterName {
    return fmt.Errorf("requested %q but state store holds %q; use the canonical name", clusterName, cluster.ObjectMeta.Name)
}

Prevention

When it happens

Trigger: clientset.GetCluster successfully loads a cluster whose.ObjectMeta.Name differs from the clusterName string the user supplied — typically when a short or alternative name was given that still resolved via state store lookup.

Common situations: Passing a shortened name or hostname while the state store object is registered under the full DNS name; copy/paste of a cluster name with a trailing slash, whitespace, or scheme; referencing a cluster in the wrong state store bucket that happens to resolve.

Related errors


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