{"record":{"id":"246e85ed7c93925e","repo":"kubernetes/kops","slug":"duplicate-instancegroup-name-found-q","errorCode":null,"errorMessage":"duplicate InstanceGroup Name found: %q","messagePattern":"duplicate InstanceGroup Name found: %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apis/kops/registry/helpers.go","lineNumber":38,"sourceCode":"\t\"context\"\n\t\"fmt\"\n\n\tmetav1 \"k8s.io/apimachinery/pkg/apis/meta/v1\"\n\tapi \"k8s.io/kops/pkg/apis/kops\"\n\t\"k8s.io/kops/pkg/client/simple\"\n\t\"k8s.io/kops/pkg/kubemanifest\"\n)\n\nfunc CreateClusterConfig(ctx context.Context, clientset simple.Clientset, cluster *api.Cluster, groups []*api.InstanceGroup, addons kubemanifest.ObjectList) error {\n\t// Check for instancegroup Name duplicates before writing\n\t{\n\t\tnames := map[string]bool{}\n\t\tfor i, ns := range groups {\n\t\t\tif ns.ObjectMeta.Name == \"\" {\n\t\t\t\treturn fmt.Errorf(\"InstanceGroup #%d did not have a Name\", i+1)\n\t\t\t}\n\t\t\tif names[ns.ObjectMeta.Name] {\n\t\t\t\treturn fmt.Errorf(\"duplicate InstanceGroup Name found: %q\", ns.ObjectMeta.Name)\n\t\t\t}\n\t\t\tnames[ns.ObjectMeta.Name] = true\n\t\t}\n\t}\n\n\t_, err := clientset.CreateCluster(ctx, cluster)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfor _, ig := range groups {\n\t\t_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, ig, metav1.CreateOptions{})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error writing updated instancegroup configuration: %v\", err)\n\t\t}\n\t}\n\n\t{","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/apis/kops/registry/helpers.go#L20-L56","documentation":"CreateClusterConfig builds a set of already-seen instance group names and rejects the cluster config if two InstanceGroups share the same ObjectMeta.Name. Duplicate names would collide when the groups are persisted as cluster resources, so the error is raised before any writes happen.","triggerScenarios":"Calling CreateClusterConfig (from RunCreateCluster) where two or more entries in groups have identical ObjectMeta.Name values — e.g. appending a nodes group twice, generating groups per zone with the same name, or merging group lists without deduplication.","commonSituations":"Scripts that create one IG per AZ but reuse a fixed name; programmatic cluster construction that appends default groups plus custom groups with clashing names; concatenating manifests from two clusters that both define a 'nodes' group.","solutions":["Rename the duplicate instance groups to unique names (e.g. nodes-a, nodes-b) before calling CreateClusterConfig.","Deduplicate the groups slice prior to the call, e.g. skip groups whose name is already in a set.","If generating per-zone groups, include the zone in the name (fmt.Sprintf(\"nodes-%s\", zone)).","Run `kops get ig` to list existing group names and pick non-conflicting ones."],"exampleFix":"// before\ngroups = append(groups, masterGroup(\"nodes\"), nodeGroup(\"nodes\"))\n// after\ngroups = append(groups, masterGroup(\"master-a\"), nodeGroup(\"nodes\"))","handlingStrategy":"validation","validationCode":"func dedupeIGs(groups []*api.InstanceGroup) ([]*api.InstanceGroup, error) {\n\tseen := map[string]bool{}\n\tfor _, ig := range groups {\n\t\tif seen[ig.ObjectMeta.Name] {\n\t\t\treturn nil, fmt.Errorf(\"duplicate instance group %q\", ig.ObjectMeta.Name)\n\t\t}\n\t\tseen[ig.ObjectMeta.Name] = true\n\t}\n\treturn groups, nil\n}","typeGuard":null,"tryCatchPattern":"if err := kopsregistry.CreateClusterConfig(ctx, cs, cluster, groups, addons); err != nil {\n\tif strings.Contains(err.Error(), \"duplicate InstanceGroup Name\") {\n\t\tvar name string\n\t\tfmt.Sscanf(err.Error(), \"duplicate InstanceGroup Name found: %q\", &name)\n\t\treturn fmt.Errorf(\"rename or drop group %q and retry\", name)\n\t}\n\treturn err\n}","preventionTips":["Generate group names programmatically with unique suffixes (role + zone).","Deduplicate merged group lists before calling CreateClusterConfig.","Enforce uniqueness in CI by listing `kops get ig` and checking for repeats.","Keep a single source of truth for group definitions instead of appending from multiple scripts."],"tags":["kops","instance-group","validation","duplicate"],"backgroundTag":"duplicate-resource-name","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"}