You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7073a2a
Browse filesBrowse the repository at this point in the historyBrowse files
feat(component): add DeleteOnlyIfOwned to keep objects the owner does not own (#239)
* feat(component): add DeleteOnlyIfOwned to keep objects the owner does not own
A gated-off resource was deleted by name, so an object a user created
under the same name was deleted too. With DeleteOnlyIfOwned, a deletion
reads the live object and deletes it only when it carries an owner
reference with the owner's UID. The delete carries UID and
resourceVersion preconditions. An object without the reference, or one
that changed after the read, is kept and logged, and the reconcile does
not fail. The option covers Delete, DeleteWhen, GatedBy, a disabled
component feature gate and DeleteOnSuspend. It is a build error with
ReadOnly or Unowned.
Closes#233
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(component): keep an unowned object on delete-on-suspend
With DeleteOnlyIfOwned and DeleteOnSuspend, the suspension apply set the
owner reference on a user-created object, and the delete after it then
found the object owned and deleted it. The suspension now checks the
owner reference before Suspend and the apply, and an object without it
counts as suspended with no write. The read goes through the API reader
when set, so a stale cache that still shows an earlier owned object
does not let the apply take over a new one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(component): read suspension ownership into an empty object
The delete-on-suspend existence check read the live object into a copy
of the desired object. The ownership check then depended on the decoder
clearing ownerReferences that the copy carried from an earlier apply.
The read now goes into an empty object of the same type, as
observeController does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(component): bind the suspension apply to the ownership read
With DeleteOnlyIfOwned and DeleteOnSuspend, an object that was replaced
or disowned between the ownership read and the suspension apply was
taken over by the apply and then deleted. The suspension apply now
carries the observed resourceVersion, so the API server rejects it when
the object changed. The resource then reports Suspending, the object is
not written, and the reconcile does not fail.
The deleteResources doc now says that an entry left in place is not an
error, which the skip paths already did.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(component): cover a delete conflict with both ownership options
Add a test for a precondition conflict on the delete when
DeleteOnlyIfOwned and BlockOnForeignController are both set. The
reconcile does not fail and the object is kept. BlockOnForeignController
alone still fails on that conflict, so the combined case needs its own
test.
Move the owner reference check of the delete and suspension paths into
one ownedBy helper. Split the DeleteOnlyIfOwned GoDoc into paragraphs,
and give the suspension apply comment a subject.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/component.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,7 @@ be passed without a guard.
66
66
|`component.BlockOnAbsence()`| Read-only only: a NotFound records a blocked status and short-circuits the remaining resources |
67
67
|`component.IgnoreIfAbsent()`| Read-only only: a NotFound is silently ignored and last-known state is preserved |
68
68
|`component.BlockOnForeignController()`| Managed only: records a blocked status that names the owner whose controller reference is on the live object, then skips the apply and the remaining resources |
69
+
|`component.DeleteOnlyIfOwned()`| Managed only: a deletion removes the live object only when it carries an owner reference to the owner; any other object is left in place |
69
70
|`component.SuppressGraceInconsistencyWarning()`| Suppresses the grace/convergence inconsistency warning |
70
71
71
72
A read-only resource is not owned by the component, so it is never deleted. `ReadOnly()` is mutually exclusive with
@@ -105,6 +106,36 @@ A delete of an object that the read found safe carries the observed UID and reso
105
106
owner claims the object between the read and the delete, the delete fails and the next reconcile reads the object again.
106
107
The option requires a managed resource. A combination with `ReadOnly()` is a build error.
107
108
109
+
`DeleteOnlyIfOwned()` protects an object that the component did not create from a deletion. Without it, every deletion
110
+
path removes the object by name, whoever created it. The only exception is an object that another owner controls, which
111
+
`BlockOnForeignController()` keeps. Use the option when the resource name is one that a user can also create by hand.
112
+
For example, a component registers `<name>-app` as a ServiceAccount behind `GatedBy()`. When the gate is off and the
113
+
user created their own `<name>-app`, the option keeps the object of the user.
114
+
115
+
When `Delete()`, `DeleteWhen()`, `GatedBy()`, a disabled component feature gate, or a suspension with
116
+
`DeleteOnSuspend()` asks for a deletion, the component first reads the live object, through `ReconcileContext.APIReader`
117
+
when it is set and `ReconcileContext.Client` otherwise. The component deletes the object only when the object has an
118
+
owner reference with the UID of the owner. This reference does not have to be the controller reference. The component
119
+
sets this reference on each object that it applies, with two exceptions: an `Unowned()` resource, and a cluster-scoped
120
+
resource of a namespace-scoped owner. The option never deletes an object of the second kind, so do not use it there. If
121
+
the object does not have the reference, the component does not write to the object and records no `ResourceDeleted`
122
+
event. It logs the skip, and the reconcile does not fail. The resource does not contribute to the component condition.
123
+
As with a deletion, a disabled component feature gate reports `Disabled`. During a suspension with `DeleteOnSuspend()`,
124
+
the component also skips the suspension apply for such an object, because that apply would set the owner reference. The
125
+
resource counts as suspended. While no deletion is asked for, the option has no effect.
126
+
127
+
The delete carries the observed UID and resourceVersion as preconditions. If the object changes, or a different object
128
+
takes the name, between the read and the delete, the API server rejects the delete with a conflict. The component then
129
+
keeps the object, logs the skip, and does not fail the reconcile. The next reconcile reads the object again. A
130
+
suspension with `DeleteOnSuspend()` binds its apply to the read in the same way, through the observed resourceVersion.
131
+
If the object changes between the read and that apply, the API server rejects the apply. The component does not write
132
+
the object, the resource reports `Suspending`, and the reconcile does not fail.
133
+
134
+
The option composes with `BlockOnForeignController()`. With both options, the component keeps an object that another
135
+
owner controls, even when the object also references this owner. A conflict on the delete then does not fail the
136
+
reconcile. `DeleteOnlyIfOwned()` requires a managed resource that carries the owner reference. A combination with
137
+
`ReadOnly()` or `Unowned()` is a build error.
138
+
108
139
Options compose. Gate a resource and exclude it from health aggregation in one call:
0 commit comments