{"record":{"id":"2e78a2ac4a811209","repo":"kubernetes/kops","slug":"no-instance-groups-found-in-cluster-q","errorCode":null,"errorMessage":"no instance groups found in cluster %q","messagePattern":"no instance groups found in cluster %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/toolbox/clusterapi/generate_machinedeployment.go","lineNumber":156,"sourceCode":"\t// \t\t\tzone = subnetCandidate.Zone\n\t// \t\t}\n\t// \t}\n\t// \tif zone == \"\" {\n\t// \t\treturn fmt.Errorf(\"unable to determine zone for subnet %q in cluster %q; please specify --zone\", subnet, options.ClusterName)\n\t// \t}\n\t// \tlog.Info(\"selected zone\", \"zone\", zone)\n\t// }\n\n\tinstanceType := options.InstanceType\n\timage := options.Image\n\tif len(zones) == 0 || instanceType == \"\" || image == \"\" {\n\t\tinstanceGroups, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif len(instanceGroups.Items) == 0 {\n\t\t\treturn fmt.Errorf(\"no instance groups found in cluster %q\", options.ClusterName)\n\t\t}\n\n\t\tif len(zones) == 0 {\n\t\t\tallZones := sets.New[string]()\n\t\t\tfor _, ig := range instanceGroups.Items {\n\t\t\t\tfor _, z := range ig.Spec.Zones {\n\t\t\t\t\tallZones.Insert(z)\n\t\t\t\t}\n\t\t\t}\n\t\t\tif allZones.Len() == 0 {\n\t\t\t\treturn fmt.Errorf(\"no zones found in instance groups in cluster %q\", options.ClusterName)\n\t\t\t}\n\n\t\t\tzones = sets.List(allZones)\n\t\t\tlog.Info(\"selected zones\", \"zones\", zones)\n\t\t}\n\n\t\tif instanceType == \"\" {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/toolbox/clusterapi/generate_machinedeployment.go#L138-L174","documentation":"RunGenerateMachineDeployment lists the cluster's instance groups to infer zones/types; if the list returns zero items it returns 'no instance groups found in cluster %q'. A cluster without instance groups has nothing to derive worker configuration from.","triggerScenarios":"Running generate machinedeployment against a cluster registered in the API/statestore that has no InstanceGroup objects yet (fresh cluster before `kops update cluster` created IGs, or wrong cluster name/statestore).","commonSituations":"Pointing at a cluster in a different KOPS_STATE_STORE; running before initial update/apply; instance groups deleted manually.","solutions":["Confirm the cluster name and KOPS_STATE_STORE point at the intended cluster (`kops get clusters`).","Run `kops update cluster --yes` first so instance groups are created.","Create instance groups with `kops create instancegroup` or from a template before generating the MachineDeployment."],"exampleFix":"// before: run generation on empty cluster\nkops toolbox clusterapi generate machinedeployment --cluster c1.k8s.local --name workers // error\n// after: create IG first\nkops create instancegroup --cluster c1.k8s.local nodes -o yaml\nkops update cluster --name c1.k8s.local --yes\nkops toolbox clusterapi generate machinedeployment --cluster c1.k8s.local --name workers","handlingStrategy":"validation","validationCode":"igs, err := clientset.InstanceGroupsFor(cluster).List(ctx, metav1.ListOptions{})\nif err != nil { return err }\nif len(igs.Items) == 0 {\n\treturn fmt.Errorf(\"cluster %q has no instance groups; run kops update cluster first\", cluster.Name)\n}","typeGuard":"func hasInstanceGroups(igs *api.InstanceGroupList) bool { return igs != nil && len(igs.Items) > 0 }","tryCatchPattern":"if err := RunGenerateMachineDeployment(ctx, f, out, options); err != nil {\n\tif strings.Contains(err.Error(), \"no instance groups found in cluster\") {\n\t\treturn fmt.Errorf(\"create instance groups (kops create instancegroup / update cluster) before generating: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Verify KOPS_STATE_STORE and cluster name match the intended cluster.","Complete `kops update cluster --yes` before cluster-api tooling runs.","Avoid deleting all instance groups without recreating them.","Preflight: list IGs and abort generation when the list is empty."],"tags":["kops","cluster-api","instance-groups"],"backgroundTag":"empty-instance-groups","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"}