Skip to content

Commit f9c8015

Browse files
fix: retry image-update writes in Eventually to handle 409 Conflict in CI
The reconciler can modify the AgentDeployment (finalizer add, status write) between the test's Get and Update, bumping the resourceVersion. The resulting 409 Conflict was flaking the 'does not advance StableVersion during a partial rollout' test (and would also flake 'updates the child Deployment image'). Fix: wrap the Get+Update block in Eventually so the test transparently retries on conflict — the standard controller-runtime envtest idiom for this pattern.
1 parent cb0934c commit f9c8015

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

internal/controller/agentdeployment_controller_test.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,17 @@ var _ = Describe("AgentDeployment Controller", func() {
363363
})
364364

365365
It("updates the child Deployment image when spec.image changes", func() {
366-
// Update the image field.
367-
ad := &agentraxv1alpha1.AgentDeployment{}
368-
Expect(k8sClient.Get(ctx, key, ad)).To(Succeed())
369-
ad.Spec.Image = "nginx:1.25"
370-
Expect(k8sClient.Update(ctx, ad)).To(Succeed())
366+
// Wrap Get+Update in Eventually to handle 409 Conflict: the reconciler
367+
// may bump the resourceVersion (finalizer add, status write) between
368+
// the test's Get and Update, causing a stale-object conflict.
369+
Eventually(func() error {
370+
ad := &agentraxv1alpha1.AgentDeployment{}
371+
if err := k8sClient.Get(ctx, key, ad); err != nil {
372+
return err
373+
}
374+
ad.Spec.Image = "nginx:1.25"
375+
return k8sClient.Update(ctx, ad)
376+
}, testTimeout, testInterval).Should(Succeed(), "spec.image update should be accepted without conflict")
371377

372378
// Verify the child Deployment picks up the new image.
373379
Eventually(func() string {
@@ -388,12 +394,26 @@ var _ = Describe("AgentDeployment Controller", func() {
388394
// After updating the image the Deployment generation advances but
389395
// ObservedGeneration / UpdatedReplicas / AvailableReplicas never satisfy
390396
// the rollout-complete gate — so StableVersion must stay empty.
391-
ad := &agentraxv1alpha1.AgentDeployment{}
392-
Expect(k8sClient.Get(ctx, key, ad)).To(Succeed())
393-
stableVersionBefore := ad.Status.StableVersion
397+
var stableVersionBefore string
398+
// Wrap Get in Eventually to read a fully-settled object before capturing the baseline.
399+
Eventually(func() error {
400+
ad := &agentraxv1alpha1.AgentDeployment{}
401+
if err := k8sClient.Get(ctx, key, ad); err != nil {
402+
return err
403+
}
404+
stableVersionBefore = ad.Status.StableVersion
405+
return nil
406+
}, testTimeout, testInterval).Should(Succeed())
394407

395-
ad.Spec.Image = "nginx:1.25"
396-
Expect(k8sClient.Update(ctx, ad)).To(Succeed())
408+
// Wrap Get+Update in Eventually to handle 409 Conflict (same as above).
409+
Eventually(func() error {
410+
ad := &agentraxv1alpha1.AgentDeployment{}
411+
if err := k8sClient.Get(ctx, key, ad); err != nil {
412+
return err
413+
}
414+
ad.Spec.Image = "nginx:1.25"
415+
return k8sClient.Update(ctx, ad)
416+
}, testTimeout, testInterval).Should(Succeed(), "spec.image update should be accepted without conflict")
397417

398418
// Wait for the Deployment spec to reflect the new image so we know the
399419
// reconciler has processed the update.

0 commit comments

Comments
 (0)