{"record":{"id":"fa5b739b0de49e96","repo":"kubernetes/kops","slug":"cluster-name-did-not-match-expected-name-v-vs-v","errorCode":null,"errorMessage":"cluster name did not match expected name: %v vs %v","messagePattern":"cluster name did not match expected name: (.+?) vs (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/root.go","lineNumber":357,"sourceCode":"\tif clusterName == \"\" {\n\t\treturn nil, field.Required(field.NewPath(\"clusterName\"), \"Cluster name is required\")\n\t}\n\n\tclientset, err := factory.KopsClient()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tcluster, err := clientset.GetCluster(ctx, clusterName)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error reading cluster configuration: %v\", err)\n\t}\n\tif cluster == nil {\n\t\treturn nil, fmt.Errorf(\"cluster %q not found\", clusterName)\n\t}\n\n\tif clusterName != cluster.ObjectMeta.Name {\n\t\treturn nil, fmt.Errorf(\"cluster name did not match expected name: %v vs %v\", clusterName, cluster.ObjectMeta.Name)\n\t}\n\treturn cluster, nil\n}\n\nfunc GetClusterNameForCompletionNoKubeconfig(clusterArgs []string) (clusterName string, completions []string, directive cobra.ShellCompDirective) {\n\tif len(clusterArgs) > 0 {\n\t\treturn clusterArgs[0], nil, 0\n\t}\n\n\tif rootCommand.clusterName != \"\" {\n\t\treturn rootCommand.clusterName, nil, 0\n\t}\n\n\treturn \"\", []string{\"--name\"}, cobra.ShellCompDirectiveNoFileComp\n}\n\nfunc GetClusterForCompletion(ctx context.Context, factory commandutils.Factory, clusterArgs []string) (cluster *kopsapi.Cluster, clientSet simple.Clientset, completions []string, directive cobra.ShellCompDirective) {\n\tclusterName := \"\"","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/root.go#L339-L375","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Run kops get clusters to see canonical names stored in the state store.","Quote the cluster name in your shell and strip any trailing whitespace or slash.","Ensure KOPS_CLUSTER_NAME/--name matches the metadata name exactly."],"exampleFix":"// before\nkops create ig nodes --name Cluster.K8s.Local\n// error: cluster name did not match expected name: Cluster.K8s.Local vs cluster.k8s.local\n// after\nkops create ig nodes --name cluster.k8s.local","handlingStrategy":"validation","validationCode":"CANONICAL=$(kops get clusters -o json | jq -r '.items[].metadata.name' | grep -Fx \"$CLUSTER_NAME\") || { echo \"use exact name\"; exit 1; }","typeGuard":null,"tryCatchPattern":"cluster, err := GetCluster(ctx, clusterName)\nif err != nil {\n    return err\n}\nif cluster.ObjectMeta.Name != clusterName {\n    return fmt.Errorf(\"requested %q but state store holds %q; use the canonical name\", clusterName, cluster.ObjectMeta.Name)\n}","preventionTips":["Trim whitespace/slashes from cluster names sourced from variables","Never hand-type cluster names in scripts; resolve them from kops output","Keep name casing consistent (names are case-sensitive)","Store the canonical name in a single source (env file) referenced everywhere"],"tags":["kops","name-mismatch","cluster-config"],"backgroundTag":"cluster-name-mismatch","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}