{"record":{"id":"e3937e5e532e02b5","repo":"kubernetes/kops","slug":"instancegroup-q-already-exists","errorCode":null,"errorMessage":"instanceGroup %q already exists","messagePattern":"instanceGroup %q already exists","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/create.go","lineNumber":173,"sourceCode":"\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 create 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\treturn fmt.Errorf(\"error querying cluster %q: %v\", clusterName, err)\n\t\t\t\t}\n\n\t\t\t\tif cluster == nil {\n\t\t\t\t\treturn fmt.Errorf(\"cluster %q not found\", clusterName)\n\t\t\t\t}\n\n\t\t\t\t_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, v, metav1.CreateOptions{})\n\t\t\t\tif err != nil {\n\t\t\t\t\tif apierrors.IsAlreadyExists(err) {\n\t\t\t\t\t\treturn fmt.Errorf(\"instanceGroup %q already exists\", v.ObjectMeta.Name)\n\t\t\t\t\t}\n\t\t\t\t\treturn fmt.Errorf(\"error creating instanceGroup: %v\", err)\n\t\t\t\t}\n\t\t\t\tfmt.Fprintf(&sb, \"Created instancegroup/%s\\n\", v.ObjectMeta.Name)\n\n\t\t\tcase *kopsapi.SSHCredential:\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 create SSHCredential\", kopsapi.LabelClusterName)\n\t\t\t\t}\n\t\t\t\tif v.Spec.PublicKey == \"\" {\n\t\t\t\t\treturn fmt.Errorf(\"spec.PublicKey is required\")\n\t\t\t\t}\n\n\t\t\t\tcluster, err := clientset.GetCluster(ctx, clusterName)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/create.go#L155-L191","documentation":"When creating an InstanceGroup via InstanceGroupsFor(cluster).Create, the backend returns an API IsAlreadyExists error if an instance group with the same name already exists for that cluster; RunCreate wraps it into this friendly message.","triggerScenarios":"`kops create -f ig.yaml` (or a file containing an InstanceGroup) where an InstanceGroup with the same metadata.name already exists in the target cluster — including a duplicate IG document inside the same multi-section -f file.","commonSituations":"Re-running a create script that already succeeded partially; copying a nodes instance group file without renaming it; applying the same manifest twice instead of using `kops replace` or `kops apply`.","solutions":["Use `kops replace -f ig.yaml` to overwrite the existing group","Use `kops apply` / update the existing group via `kops edit ig <name>` instead of create","Rename the new instance group (unique metadata.name) if it is intended to be an additional group","If unintended duplicate, delete one copy before creating"],"exampleFix":"// before\nkops create -f nodes.yaml\n// after\nkops replace -f nodes.yaml","handlingStrategy":"try-catch","validationCode":"existing, _ := clientset.InstanceGroupsFor(cluster).Get(ctx, ig.Name, metav1.GetOptions{})\nif existing != nil {\n    // use replace instead of create\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"already exists\") {\n    _, err = clientset.InstanceGroupsFor(cluster).Update(ctx, ig, metav1.UpdateOptions{})\n}","preventionTips":["Make create scripts idempotent: get-or-create/update","Use `kops replace` or `kops apply` for repeat runs","Keep instance group names unique per cluster"],"tags":["kops","cli","instancegroup","already-exists"],"backgroundTag":"resource-already-exists","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"}