{"record":{"id":"442b27e7fefb818f","repo":"kubernetes/kops","slug":"must-specify-q-label-with-cluster-name-to-replace","errorCode":null,"errorMessage":"must specify %q label with cluster name to replace instanceGroup","messagePattern":"must specify %q label with cluster name to replace instanceGroup","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/replace.go","lineNumber":163,"sourceCode":"\t\t\t\t\t\t\treturn fmt.Errorf(\"error populating configuration: %w\", err)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t_, err = clientset.CreateCluster(ctx, v)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"error creating cluster: %v\", err)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_, err = clientset.UpdateCluster(ctx, v, status)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"error replacing cluster: %v\", err)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\tcase *kopsapi.InstanceGroup:\n\t\t\t\tclusterName := v.ObjectMeta.Labels[kopsapi.LabelClusterName]\n\t\t\t\tif clusterName == \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"must specify %q label with cluster name to replace instanceGroup\", kopsapi.LabelClusterName)\n\t\t\t\t}\n\t\t\t\tcluster, err := clientset.GetCluster(ctx, clusterName)\n\t\t\t\tif err != nil {\n\t\t\t\t\tif errors.IsNotFound(err) {\n\t\t\t\t\t\treturn fmt.Errorf(\"cluster %q not found\", clusterName)\n\t\t\t\t\t}\n\t\t\t\t\treturn fmt.Errorf(\"error fetching cluster %q: %v\", clusterName, err)\n\t\t\t\t}\n\t\t\t\t// check if the instancegroup exists already\n\t\t\t\tigName := v.ObjectMeta.Name\n\t\t\t\tig, err := clientset.InstanceGroupsFor(cluster).Get(ctx, igName, metav1.GetOptions{})\n\t\t\t\tif err != nil {\n\t\t\t\t\tif errors.IsNotFound(err) {\n\t\t\t\t\t\tif !c.Force {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"instanceGroup: %v does not exist (try adding --force flag)\", igName)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn fmt.Errorf(\"unable to check for instanceGroup: %v\", err)","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/replace.go#L145-L181","documentation":"When replacing an InstanceGroup manifest, kops derives the owning cluster from the metadata label kopsapi.LabelClusterName (kops.k8s.io/cluster). If the label is absent or empty, it cannot know which cluster the instance group belongs to and fails with this error.","triggerScenarios":"Hand-written or exported instancegroup YAML missing metadata.labels['kops.k8s.io/cluster']; manifests generated by tools that strip labels; copying an instancegroup from one cluster and forgetting to set the label.","commonSituations":"Authoring instancegroup manifests manually instead of `kops get instancegroups -o yaml`; label removed during templating/templating engines (helm/kustomize stripping labels); older exported manifests predating the label convention.","solutions":["Add metadata.labels.kops.k8s.io/cluster: <cluster-name> to the instancegroup manifest","Regenerate the manifest with `kops get instancegroup <name> -o yaml` which includes the label","If copying between clusters, update the label to the target cluster name","Use `kops create instancegroup` / `kops replace -f` with a properly labeled manifest"],"exampleFix":"// before\nkind: InstanceGroup\nmetadata:\n  name: nodes\n// after\nkind: InstanceGroup\nmetadata:\n  name: nodes\n  labels:\n    kops.k8s.io/cluster: mycluster.example.com","handlingStrategy":"validation","validationCode":"func validateInstanceGroup(manifest []byte) error {\n    var ig kopsapi.InstanceGroup\n    if err := yaml.Unmarshal(manifest, &ig); err != nil {\n        return err\n    }\n    if ig.ObjectMeta.Labels[kopsapi.LabelClusterName] == \"\" {\n        return fmt.Errorf(\"missing required label %q\", kopsapi.LabelClusterName)\n    }\n    return nil\n}","typeGuard":"func hasClusterLabel(labels map[string]string) bool {\n    return labels[kopsapi.LabelClusterName] != \"\"\n}","tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"must specify\") {\n        // add kops.k8s.io/cluster label and retry\n    }\n    return err\n}","preventionTips":["Always include kops.k8s.io/cluster in instancegroup metadata.labels","Export manifests with `kops get instancegroups -o yaml` rather than hand-writing","Check templating tools are not stripping labels","Update the label when copying instancegroups between clusters"],"tags":["instancegroup","labels","manifest"],"backgroundTag":"missing-required-label","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"}