{"record":{"id":"7f7958afd68e68fa","repo":"kubernetes/kops","slug":"error-creating-instancegroup-v-7f7958","errorCode":null,"errorMessage":"error creating instanceGroup: %v","messagePattern":"error creating instanceGroup: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/replace.go","lineNumber":189,"sourceCode":"\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)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tswitch ig {\n\t\t\t\tcase nil:\n\t\t\t\t\tklog.Infof(\"instanceGroup: %v was not found, creating resource now\", igName)\n\t\t\t\t\t_, err = clientset.InstanceGroupsFor(cluster).Create(ctx, v, metav1.CreateOptions{})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"error creating instanceGroup: %v\", err)\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\t_, err = clientset.InstanceGroupsFor(cluster).Update(ctx, v, metav1.UpdateOptions{})\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"error replacing instanceGroup: %v\", err)\n\t\t\t\t\t}\n\t\t\t\t}\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 replace 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 {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/replace.go#L171-L207","documentation":"When the InstanceGroup did not exist (ig == nil) and --force allowed creation, `kops replace` calls clientset.InstanceGroupsFor(cluster).Create. This error wraps any failure returned by that Create call, meaning the new InstanceGroup resource could not be persisted to the state store.","triggerScenarios":"Create fails after the existence check reported NotFound: concurrent creation by another operator/CI run, invalid IG spec rejected by validation, state-store write failure, or permission errors.","commonSituations":"Two pipelines running `kops replace --force` simultaneously (one creates first, the other's Create collides); manifest with invalid fields (bad machineType, missing subnets); state-store backend write errors.","solutions":["Read the wrapped error for the specific cause.","If it's a collision, re-run `kops replace -f ig.yaml` WITHOUT --force so the now-existing IG is updated instead of created.","Fix validation problems in the manifest (run `kops create -f ig.yaml --dry-run` to see errors).","Verify state-store write permissions and retry if transient."],"exampleFix":"# before\nkops replace -f ig.yaml --force   # Create collides after another process created it\n# after\nkops replace -f ig.yaml           # existing IG now goes through Update path","handlingStrategy":"try-catch","validationCode":"// Detect not-found and create via the documented path instead of --force\n_, err := clientset.InstanceGroupsFor(cluster).Get(ctx, igName, metav1.GetOptions{})\ncreateFirst := errors.IsNotFound(err)","typeGuard":null,"tryCatchPattern":"if strings.HasPrefix(err.Error(), \"error creating instanceGroup:\") {\n    // likely a concurrent create; fall back to update path\n    time.Sleep(time.Second)\n    return runReplaceWithoutForce()\n}","preventionTips":["Use a lock (CI mutex or DynamoDB lock) so only one job mutates IGs at a time","Validate manifests with --dry-run before applying","Re-check existence after a create collision instead of blindly retrying --force"],"tags":["kops","instancegroup","create","state-store"],"backgroundTag":"resource-create-failed","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"}