{"record":{"id":"7031dab61c52df5b","repo":"kubernetes/kops","slug":"instancegroup-v-does-not-exist-try-adding-for","errorCode":null,"errorMessage":"instanceGroup: %v does not exist (try adding --force flag)","messagePattern":"instanceGroup: (.+?) does not exist \\(try adding --force flag\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/replace.go","lineNumber":178,"sourceCode":"\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 replace 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\tif errors.IsNotFound(err) {\n\t\t\t\t\t\treturn fmt.Errorf(\"cluster %q not found\", clusterName)\n\t\t\t\t\t}\n\t\t\t\t\treturn fmt.Errorf(\"error fetching cluster %q: %v\", clusterName, err)\n\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}","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/replace.go#L160-L196","documentation":"`kops replace` refuses to replace an InstanceGroup whose name is not found in the state store. Because `replace` is semantically an update operation, kOps conservatively fails instead of silently creating a brand-new InstanceGroup; passing `--force` explicitly opts in to create-on-missing behavior. The check is done via clientset.InstanceGroupsFor(cluster).Get, and the error is returned when errors.IsNotFound(err) is true and c.Force is false.","triggerScenarios":"Running `kops replace -f ig.yaml` where the InstanceGroup name in the manifest (v.ObjectMeta.Name) does not exist in the cluster's state store and the --force flag was not supplied. The Get call returns a NotFound error, triggering this message.","commonSituations":"Typo in the InstanceGroup name in the manifest; renaming an existing InstanceGroup instead of editing it; replacing a manifest from a different/older cluster whose IGs were deleted; forgetting that replace does not create resources without --force.","solutions":["Re-run the command with the --force flag: `kops replace -f ig.yaml --force` to create the missing InstanceGroup.","Verify the `metadata.name` in the manifest matches an existing InstanceGroup (`kops get instancegroups <cluster>`) and fix the typo if not.","If the IG should already exist, confirm you are pointing at the right cluster/state store (--name and KOPS_STATE_STORE) before forcing creation.","Alternatively use `kops create -f ig.yaml` when the intent is creation, then `kops update cluster --yes` to apply."],"exampleFix":"# before\nkops replace -f instancegroup-nodes.yaml\n// error: instanceGroup: nodes does not exist (try adding --force flag)\n# after\nkops replace -f instancegroup-nodes.yaml --force","handlingStrategy":"validation","validationCode":"// Before replace, confirm the InstanceGroup exists\nname := igManifest.ObjectMeta.Name\n_, err := clientset.InstanceGroupsFor(cluster).Get(ctx, name, metav1.GetOptions{})\nif errors.IsNotFound(err) {\n    // either add --force or create first: kops create -f ig.yaml\n    fmt.Printf(\"InstanceGroup %s does not exist; use --force or create it\\n\", name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep InstanceGroup manifest names in sync with `kops get instancegroups` output before replace","Use --force deliberately and only when creation is intended","Pin cluster name with --name to avoid checking the wrong state store","Script the existence check into CI before running replace"],"tags":["kops","instancegroup","cli","not-found"],"backgroundTag":"resource-not-found","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"}