Skip to content

Commit 067f3d5

Browse files
jtschellingclaude
andcommitted
test(janitor): wait for reconciler to settle before immutability Update
Locally reproduced the CI failure with a focused envtest harness (creating, snapshotting rv, then doing a stale-rv Update gets the exact "the object has been modified" 409 error, just like CI). The apiserver treats the client-supplied resourceVersion as a precondition on Update; when the reconciler bumps the rv between the test's Get and Update, the request short-circuits with 409 BEFORE admission webhooks run, so the test never sees the webhook's "nodeName cannot be changed" rejection. The sibling lifecycle tests don't hit this because their Setup waits for NVSentinelOwnershipReleased=True (which parks the dispatcher in the no-op branch). Mirror that gate here — once Released=True there are no more reconciler writes to race against, so the fresh Get→Update has a stable rv and admission gets to run. Also tightens the Teardown to mirror the other lifecycle tests: drive finalizer-based cleanup via DeleteAllCRs, plus a Node scrub as belt-and-suspenders if the finalizer path didn't complete. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 432d76a commit 067f3d5

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

tests/external_remediation_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,24 @@ func TestExtRRWebhookRejectsInvalidSpec(t *testing.T) {
8585
require.NoError(t, err)
8686

8787
crName := "extrr-immutable-node"
88-
extrr, err := helpers.CreateExtRRCR(ctx, client, crName, nodeName, "immutability-test")
88+
_, err = helpers.CreateExtRRCR(ctx, client, crName, nodeName, "immutability-test")
8989
require.NoError(t, err, "valid create must be admitted")
9090

91-
t.Cleanup(func() { _ = client.Resources().Delete(ctx, extrr) })
91+
t.Cleanup(func() {
92+
_ = helpers.DeleteAllCRs(ctx, t, client, helpers.ExternalRemediationRequestGVK)
93+
_ = helpers.ScrubExtRRStateFromNode(ctx, client, nodeName)
94+
})
95+
96+
// Wait for the reconciler to settle (Released=True → branch 6
97+
// no-op). Otherwise the apiserver returns 409 conflict on our
98+
// Update — the client's resourceVersion becomes a precondition,
99+
// and a stale rv short-circuits the request before admission
100+
// webhooks run.
101+
helpers.WaitForExtRRCondition(ctx, t, client, crName,
102+
"NVSentinelOwnershipReleased", "True")
92103

93-
// Attempt to flip nodeName via update.
104+
extrr := &unstructured.Unstructured{}
105+
extrr.SetGroupVersionKind(helpers.ExternalRemediationRequestGVK)
94106
require.NoError(t, client.Resources().Get(ctx, crName, "", extrr))
95107
require.NoError(t, unstructured.SetNestedField(
96108
extrr.Object, "different-node", "spec", "healthEvent", "nodeName"))

0 commit comments

Comments
 (0)