{"record":{"id":"7e46113b6a676d18","repo":"kubernetes/kops","slug":"cluster-v-does-not-exist-try-adding-force-flag","errorCode":null,"errorMessage":"cluster %v does not exist (try adding --force flag)","messagePattern":"cluster (.+?) does not exist \\(try adding --force flag\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/kops/replace.go","lineNumber":140,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\tstatus, err := cloud.FindClusterStatus(v)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn err\n\t\t\t\t\t}\n\n\t\t\t\t\t// Check if the cluster exists already\n\t\t\t\t\tclusterName := v.Name\n\t\t\t\t\tcluster, err := clientset.GetCluster(ctx, clusterName)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\tif errors.IsNotFound(err) {\n\t\t\t\t\t\t\tcluster = nil\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"error fetching cluster %q: %v\", clusterName, err)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tif cluster == nil {\n\t\t\t\t\t\tif !c.Force {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"cluster %v does not exist (try adding --force flag)\", clusterName)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\terr = cloudup.PerformAssignments(v, vfsContext, cloud)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"error populating configuration: %w\", err)\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t_, err = clientset.CreateCluster(ctx, v)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"error creating cluster: %v\", err)\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t_, err = clientset.UpdateCluster(ctx, v, status)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn fmt.Errorf(\"error replacing cluster: %v\", err)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/cmd/kops/replace.go#L122-L158","documentation":"Raised by `kops replace` when the configuration being replaced refers to a cluster that is not found in the state store and --force was not passed. It is a deliberate guard: without --force the command refuses to implicitly create a new cluster from a replace operation.","triggerScenarios":"Replacing a Cluster manifest whose name (v.Name) has no matching cluster in the state store, without the --force flag. Often the cluster name in the manifest is wrong or the state store points elsewhere.","commonSituations":"Typo in metadata.name of the cluster manifest; KOPS_STATE_STORE pointing at a different store than the one holding the cluster; genuinely wanting to create the cluster via replace but forgetting --force; renamed cluster.","solutions":["Add --force to create the cluster if creation is intended","Fix metadata.name in the manifest to match the existing cluster","Verify KOPS_STATE_STORE points at the store containing the cluster (`kops get clusters`)","Create the cluster with `kops create -f` instead of replace if that was the intent"],"exampleFix":"// before\nkops replace -f cluster.yaml\n// after\nkops replace -f cluster.yaml --force","handlingStrategy":"validation","validationCode":"existing, err := clientset.GetCluster(ctx, clusterName)\nclusterExists := err == nil\nif !clusterExists && !force {\n    return fmt.Errorf(\"refusing to replace nonexistent cluster %s without --force\", clusterName)\n}","typeGuard":null,"tryCatchPattern":"if err != nil && !strings.Contains(err.Error(), \"does not exist\") {\n    return err\n}\n// otherwise prompt or append --force deliberately","preventionTips":["Verify metadata.name against `kops get clusters` before replace","Only use --force when creation is explicitly intended","Confirm KOPS_STATE_STORE matches the store holding the cluster","Standardize cluster naming in manifests via templating"],"tags":["cli","cluster","flag"],"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"}