{"record":{"id":"81ec575af8cffb9a","repo":"kubernetes/kops","slug":"clustername-does-not-match-expected-got-q-want","errorCode":null,"errorMessage":"clusterName does not match expected: got %q, want %q","messagePattern":"clusterName does not match expected: got %q, want %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/tpm/gcetpmverifier/tpmverifier.go","lineNumber":159,"sourceCode":"\tclusterName := \"\"\n\tinstanceGroupName := \"\"\n\tfor _, item := range instance.Metadata.Items {\n\t\tswitch item.Key {\n\t\tcase gce.MetadataKeyInstanceGroupName:\n\t\t\tinstanceGroupName = fi.ValueOf(item.Value)\n\t\tcase gcemetadata.MetadataKeyClusterName:\n\t\t\tclusterName = fi.ValueOf(item.Value)\n\t\t}\n\t}\n\n\tcapgRole := instance.Labels[gce.LabelKeyCAPIRoleName]\n\n\tif clusterName == \"\" {\n\t\treturn nil, fmt.Errorf(\"could not determine cluster for instance %s\", instance.SelfLink)\n\t}\n\n\tif clusterName != v.opt.ClusterName {\n\t\treturn nil, fmt.Errorf(\"clusterName does not match expected: got %q, want %q\", clusterName, v.opt.ClusterName)\n\t}\n\n\tvar capiMachine *clusterapi.Machine\n\n\tif v.capiManager != nil && capgRole != \"\" {\n\t\tproviderID := \"gce://\" + tokenData.GCPProjectID + \"/\" + tokenData.Zone + \"/\" + tokenData.Instance\n\n\t\tm, err := v.capiManager.FindMachineByProviderID(ctx, providerID)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error finding Machine with providerID %q: %w\", providerID, err)\n\t\t}\n\t\tcapiMachine = m\n\t}\n\n\t// Check if this is a CAPG managed instance\n\tif instanceGroupName == \"\" && capiMachine == nil {\n\t\treturn nil, fmt.Errorf(\"could not determine ownership for instance %s\", instance.SelfLink)\n\t}","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/tpm/gcetpmverifier/tpmverifier.go#L141-L177","documentation":"VerifyToken rejects a node token because the instance's cluster-lifecycle metadata (`k3s.io/cluster-name` style cluster-name metadata item) names a cluster other than the one this verifier was configured for (v.opt.ClusterName). This is a deliberate cross-cluster guard: the verifier only trusts instances that provably belong to the cluster it serves.","triggerScenarios":"A node instance with the gce-cluster-name metadata set to a different cluster calls the TPM verifier endpoint; or the verifier's ClusterName option is misconfigured relative to the metadata value stamped on instances; or an instance was migrated/reused between clusters keeping stale metadata.","commonSituations":"Reusing an instance group or MIG across two kOps clusters; typo'd --cluster name when starting the verifier/server; shared VPC with instances from multiple clusters hitting the same verifier; rebuild of a cluster reusing the same GCE project with a renamed cluster.","solutions":["Confirm the verifier was started with the same --cluster name as the cluster that stamped the instance metadata","Check the instance's cluster-name metadata item in the GCE console and fix it if stale","Verify the request is coming from the intended cluster's nodes at all; if cross-cluster, point that cluster at its own verifier","If the cluster was intentionally renamed, update instance metadata to the new cluster name"],"exampleFix":"// before\nv, _ := NewTPMVerifier(ctx, opt) // opt.ClusterName = \"wrong.example.com\"\n// after\nopt.ClusterName = \"actual.example.com\" // must match instance metadata cluster name\nv, _ := NewTPMVerifier(ctx, opt)","handlingStrategy":"validation","validationCode":"// before contacting the verifier, ensure node metadata matches the expected cluster\ninst, err := computeClient.Instances.Get(proj, zone, name).Context(ctx).Do()\nif err != nil { return err }\nvar clusterName string\nfor _, it := range inst.Metadata.Items {\n    if it.Key == \"cluster-name\" { clusterName = fi.ValueOf(it.Value) }\n}\nif clusterName == \"\" || clusterName != expectedClusterName {\n    return fmt.Errorf(\"instance %s belongs to cluster %q, not %q\", name, clusterName, expectedClusterName)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always launch nodes from kops/CAPG so cluster-name metadata is stamped correctly","Keep verifier --cluster flag in sync with the cluster name in the cluster spec","Never reuse instances across clusters; recreate instead of re-pointing","Alert on verifier logs showing this error to catch cross-cluster join attempts"],"tags":["gce","tpm","cluster-name-mismatch","bootstrap"],"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"}