{"record":{"id":"1d61954f6d4fa308","repo":"kubernetes/kops","slug":"lifecycle-set-to-existsandvalidates-but-object-wa","errorCode":null,"errorMessage":"lifecycle set to ExistsAndValidates, but object was not found","messagePattern":"lifecycle set to ExistsAndValidates, but object was not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/context.go","lineNumber":149,"sourceCode":"\t}\n\treturn e.RunTasks(c.ctx, c.tasks)\n}\n\n// Render dispatches the creation of an object to the appropriate handler defined on the Task,\n// it is typically called after we have checked the existing state of the Task and determined that is different\n// from the desired state.\nfunc (c *Context[T]) Render(a, e, changes Task[T]) error {\n\ttypeContextPtr := reflect.TypeOf((*Context[T])(nil))\n\tvar lifecycle Lifecycle\n\tif hl, ok := e.(HasLifecycle); ok {\n\t\tlifecycle = hl.GetLifecycle()\n\t}\n\n\tif lifecycle != \"\" {\n\t\tif reflect.ValueOf(a).IsNil() {\n\t\t\tswitch lifecycle {\n\t\t\tcase LifecycleExistsAndValidates:\n\t\t\t\treturn fmt.Errorf(\"lifecycle set to ExistsAndValidates, but object was not found\")\n\t\t\tcase LifecycleExistsAndWarnIfChanges:\n\t\t\t\treturn NewExistsAndWarnIfChangesError(\"Lifecycle set to ExistsAndWarnIfChanges and object was not found.\")\n\t\t\t}\n\t\t} else {\n\t\t\tswitch lifecycle {\n\t\t\tcase LifecycleExistsAndValidates, LifecycleExistsAndWarnIfChanges:\n\n\t\t\t\tout := os.Stderr\n\t\t\t\tchangeList, err := buildChangeList(a, e, changes)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\n\t\t\t\tb := &bytes.Buffer{}\n\t\t\t\ttaskName := getTaskName(e)\n\t\t\t\tfmt.Fprintf(b, \"Object from different phase did not match, problems possible:\\n\")\n\t\t\t\tfmt.Fprintf(b, \"  %s/%s\\n\", taskName, \"?\")\n\t\t\t\tfor _, change := range changeList {","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/context.go#L131-L167","documentation":"In the generic fi task engine, Render checks lifecycle assertions: with lifecycle ExistsAndValidates, the existing (actual) object must be present and must match desired state. If the actual object `a` is nil — i.e. nothing exists in the cloud/API — the assertion cannot be satisfied and kops returns this error instead of creating the object.","triggerScenarios":"Running a phase/update with a task whose lifecycle is ExistsAndValidates but the underlying cloud object was deleted externally or never created, so the 'actual' Task is nil when Render is dispatched by defaultDeltaRunMethod.","commonSituations":"A resource was manually deleted in the cloud console between `kops update cluster --lifecycle-existence-checks` runs; targeting a cluster whose resources were partially torn down; strict existence-validation mode (used by kops-controller / phases like exists-and-validates) on a fresh cluster.","solutions":["Recreate the missing object (rerun the appropriate phase with a create/warn lifecycle) so the object exists before asserting ExistsAndValidates.","Relax the lifecycle for that task, e.g. `--lifecycle exists-and-warn-if-changes` or the normal Sync lifecycle.","Re-run `kops update cluster` to reconcile/repair the drift, then re-run the validating phase."],"exampleFix":"# before\nkops update cluster <name> --lifecycle-existence-checks  # fails: object gone\n# after\nkops update cluster <name>  # reconcile and recreate missing objects first","handlingStrategy":"validation","validationCode":"// verify the object exists in the cloud before running exists-and-validates\nif _, err := lookupCloudObject(name); err != nil { recreateObject() }","typeGuard":null,"tryCatchPattern":"err := kopsUpdate(...)\nif err != nil && strings.Contains(err.Error(), \"ExistsAndValidates, but object was not found\") {\n    // recreate missing object with default lifecycle, then re-validate\n}","preventionTips":["Don't delete cloud resources manually on clusters managed with existence checks.","Run reconciliation (`kops update cluster`) before strict validation phases.","Use exists-and-warn-if-changes for resources that may legitimately be absent."],"tags":["lifecycle","task-engine","drift","exists-and-validates"],"backgroundTag":"lifecycle-existence-assertion-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"}