{"record":{"id":"0e52c1df2fecff5f","repo":"kubernetes/kops","slug":"could-not-determine-cluster-for-instance-s","errorCode":null,"errorMessage":"could not determine cluster for instance %s","messagePattern":"could not determine cluster for instance (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gce/tpm/gcetpmverifier/tpmverifier.go","lineNumber":155,"sourceCode":"\tif !strings.HasPrefix(lastComponent(instance.Zone), v.opt.Region+\"-\") {\n\t\treturn nil, fmt.Errorf(\"instance was in zone %q, expected region %q\", instance.Zone, v.opt.Region)\n\t}\n\n\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","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gce/tpm/gcetpmverifier/tpmverifier.go#L137-L173","documentation":"The verifier scans the instance's metadata items to find the cluster it belongs to (populating clusterName). If no metadata item yields a cluster name — and it's not a CAPG-managed instance — the instance cannot be attributed to any cluster and verification fails.","triggerScenarios":"For the fetched instance, all Metadata.Items were examined but clusterName remained \"\", and instance.Labels[gce.LabelKeyCAPIRoleName] didn't provide an alternate path; typically the instance lacks the cluster's metadata (e.g. missing K8s cluster name metadata key).","commonSituations":"VMs created outside kOps/Cluster API (manually created test instances), nodes whose instance-group metadata was stripped or never set, kOps upgrades changing metadata keys, or instances launched from stale templates.","solutions":["Ensure the instance's metadata contains the cluster name key (recreate the instance group via kOps so metadata is applied).","Verify the instance was created by kOps/CAPI for this cluster, not manually.","Compare the metadata keys the verifier looks for in the switch statement against what kOps currently sets on instance groups; upgrade nodes if schemas drifted."],"exampleFix":"// before: instance created manually, no cluster metadata\n// after: recreate via kops\nkops update cluster --yes && kops rolling-update cluster --yes","handlingStrategy":"validation","validationCode":"var clusterName string\nfor _, item := range instance.Metadata.Items {\n\tif item.Key == clusterNameKey {\n\t\tclusterName = *item.Value\n\t\tbreak\n\t}\n}\nif clusterName == \"\" {\n\treturn fmt.Errorf(\"instance %s has no %s metadata; recreate via kOps\", instance.Name, clusterNameKey)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only enroll VMs created by kOps/Cluster API for this cluster","Verify instance-group metadata is present before node registration","Recreate instances with kOps after metadata schema changes"],"tags":["gcp","metadata","configuration","cluster-membership"],"backgroundTag":"missing-required-argument","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}