@@ -53,19 +53,30 @@ var _ = Describe("TenantQuota Controller", func() {
5353 adList := & agentraxv1alpha1.AgentDeploymentList {}
5454 Expect (k8sClient .List (ctx , adList , inNamespace (tqNS ))).To (Succeed ())
5555 for i := range adList .Items {
56- // Remove finalizer so deletion doesn't block.
5756 ad := & adList .Items [i ]
57+ // Remove finalizer so deletion is not blocked by the controller.
5858 ad .Finalizers = nil
59- _ = k8sClient .Update (ctx , ad )
60- _ = k8sClient .Delete (ctx , ad )
59+ if err := k8sClient .Update (ctx , ad ); err != nil && ! apierrors .IsNotFound (err ) {
60+ Expect (err ).NotTo (HaveOccurred (), "removing finalizer from AD %s" , ad .Name )
61+ }
62+ if err := k8sClient .Delete (ctx , ad ); err != nil && ! apierrors .IsNotFound (err ) {
63+ Expect (err ).NotTo (HaveOccurred (), "deleting AD %s" , ad .Name )
64+ }
65+ // Wait until the API server confirms the object is gone.
66+ Eventually (func () bool {
67+ err := k8sClient .Get (ctx , namespacedName (ad .Name , tqNS ), & agentraxv1alpha1.AgentDeployment {})
68+ return apierrors .IsNotFound (err )
69+ }, timeout , interval ).Should (BeTrue (), "AD %s should be fully deleted" , ad .Name )
6170 }
6271
6372 By ("deleting all TenantQuotas in the test namespace" )
6473 tqList := & agentraxv1alpha1.TenantQuotaList {}
6574 Expect (k8sClient .List (ctx , tqList , inNamespace (tqNS ))).To (Succeed ())
6675 for i := range tqList .Items {
6776 tq := & tqList .Items [i ]
68- _ = k8sClient .Delete (ctx , tq )
77+ if err := k8sClient .Delete (ctx , tq ); err != nil && ! apierrors .IsNotFound (err ) {
78+ Expect (err ).NotTo (HaveOccurred (), "deleting TQ %s" , tq .Name )
79+ }
6980 }
7081 })
7182
@@ -213,6 +224,9 @@ var _ = Describe("TenantQuota Controller", func() {
213224 // The reconciler calls RemoveStatusCondition, so the condition
214225 // must be fully absent once usage normalises.
215226 g .Expect (cond ).To (BeNil ())
227+ // Usage counters must reflect the one remaining AD (maxReplicas=2).
228+ g .Expect (f .Status .UsedAgents ).To (BeNumerically ("==" , 1 ))
229+ g .Expect (f .Status .UsedTotalReplicas ).To (BeNumerically ("==" , 2 ))
216230 }, timeout , interval ).Should (Succeed ())
217231 })
218232
0 commit comments