{"record":{"id":"290244e888c72392","repo":"kubernetes/kops","slug":"instancegroup-d-did-not-have-a-name","errorCode":null,"errorMessage":"InstanceGroup #%d did not have a Name","messagePattern":"InstanceGroup #(.+?) did not have a Name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apis/kops/registry/helpers.go","lineNumber":35,"sourceCode":"package registry\n\nimport (\n\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}","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/apis/kops/registry/helpers.go#L17-L53","documentation":"CreateClusterConfig validates the instance groups before persisting the cluster config. Every InstanceGroup must have a non-empty ObjectMeta.Name; if the group at index i+1 has an empty name, this error is thrown. The name is required because instance groups are stored as named cluster resources and referenced by cluster templating.","triggerScenarios":"Calling CreateClusterConfig (from RunCreateCluster, i.e. `kops create cluster`) with a groups slice containing an api.InstanceGroup whose ObjectMeta.Name is \"\" — e.g. building IGs programmatically and forgetting to set Name, or a template/manifest with a missing `metadata.name`.","commonSituations":"Programmatic cluster creation via the kops API where IG structs are constructed manually; generating instance groups in a script and leaving the name field blank; YAML manifests for `kops replace -f` style flows missing metadata.name.","solutions":["Set ObjectMeta.Name on every InstanceGroup before calling CreateClusterConfig (e.g. ig.Name = \"nodes\" or ig.ObjectMeta.Name = ...).","If using `kops create cluster`, rely on its default IG names (master.*, nodes) instead of constructing groups by hand.","Add a pre-submit check iterating groups and failing early on empty names with the index reported.","If the group came from a YAML manifest, add `metadata: name: <ig-name>`."],"exampleFix":"// before\ngroups := []*api.InstanceGroup{{Spec: api.InstanceGroupSpec{Role: api.InstanceGroupRoleNode}}}\n// after\ngroups := []*api.InstanceGroup{{ObjectMeta: metav1.ObjectMeta{Name: \"nodes\"}, Spec: api.InstanceGroupSpec{Role: api.InstanceGroupRoleNode}}}","handlingStrategy":"validation","validationCode":"func requireIGNames(groups []*api.InstanceGroup) error {\n\tfor i, ig := range groups {\n\t\tif ig == nil || ig.ObjectMeta.Name == \"\" {\n\t\t\treturn fmt.Errorf(\"InstanceGroup #%d missing Name\", i+1)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := kopsregistry.CreateClusterConfig(ctx, cs, cluster, groups, addons); err != nil {\n\tif strings.Contains(err.Error(), \"did not have a Name\") {\n\t\treturn fmt.Errorf(\"fix group construction: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Construct instance groups through a helper that always sets ObjectMeta.Name.","Validate generated groups (names, roles) before handing them to CreateClusterConfig.","Add a unit test asserting every IG has a non-empty name.","When loading from YAML, validate metadata.name presence before applying."],"tags":["kops","instance-group","validation","naming"],"backgroundTag":"missing-resource-name","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"}