@@ -501,6 +501,7 @@ var _ = Describe("Reconciler", func() {
501
501
Expect (mgr .GetCache ().WaitForCacheSync (ctx )).To (BeTrue ())
502
502
503
503
obj = testutil .BuildTestCR (gvk )
504
+ obj .SetLabels (map [string ]string {"foo" : "bar" })
504
505
objKey = types.NamespacedName {Namespace : obj .GetNamespace (), Name : obj .GetName ()}
505
506
req = reconcile.Request {NamespacedName : objKey }
506
507
})
@@ -533,6 +534,8 @@ var _ = Describe("Reconciler", func() {
533
534
cancel ()
534
535
})
535
536
537
+ selector := metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }}
538
+
536
539
// After migration to Ginkgo v2 this can be rewritten using e.g. DescribeTable.
537
540
parameterizedReconcilerTests := func (opts reconcilerTestSuiteOpts ) {
538
541
BeforeEach (func () {
@@ -551,6 +554,7 @@ var _ = Describe("Reconciler", func() {
551
554
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
552
555
WithUninstallAnnotations (annotation.UninstallDescription {}),
553
556
WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
557
+ WithSelector (selector ),
554
558
WithOverrideValues (map [string ]string {
555
559
"image.repository" : "custom-nginx" ,
556
560
}),
@@ -566,6 +570,7 @@ var _ = Describe("Reconciler", func() {
566
570
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
567
571
WithUninstallAnnotations (annotation.UninstallDescription {}),
568
572
WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
573
+ WithSelector (selector ),
569
574
WithOverrideValues (map [string ]string {
570
575
"image.repository" : "custom-nginx" ,
571
576
}),
@@ -1455,6 +1460,40 @@ var _ = Describe("Reconciler", func() {
1455
1460
})
1456
1461
})
1457
1462
})
1463
+ When ("label selector succeeds" , func () {
1464
+ It ("reconciles only matching label" , func () {
1465
+ By ("setting an invalid action client getter to assert different reconcile results" , func () {
1466
+ r .actionClientGetter = helmclient .ActionClientGetterFunc (func (context.Context , client.Object ) (helmclient.ActionInterface , error ) {
1467
+ fakeClient := helmfake .NewActionClient ()
1468
+ return & fakeClient , nil
1469
+ })
1470
+ })
1471
+
1472
+ By ("setting not matching label to the CR" , func () {
1473
+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1474
+ obj .SetLabels (map [string ]string {"foo" : "baz" })
1475
+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1476
+ })
1477
+
1478
+ By ("reconciling is skipped, action client was not called and no error returned" , func () {
1479
+ res , err := r .Reconcile (ctx , req )
1480
+ Expect (res ).To (Equal (reconcile.Result {}))
1481
+ Expect (err ).To (BeNil ())
1482
+ })
1483
+
1484
+ By ("setting matching label to the CR" , func () {
1485
+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1486
+ obj .SetLabels (map [string ]string {"foo" : "bar" })
1487
+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1488
+ })
1489
+
1490
+ By ("reconciling is not skipped and error returned because of broken action client" , func () {
1491
+ res , err := r .Reconcile (ctx , req )
1492
+ Expect (res ).To (Equal (reconcile.Result {}))
1493
+ Expect (err ).To (MatchError ("get not implemented" ))
1494
+ })
1495
+ })
1496
+ })
1458
1497
})
1459
1498
})
1460
1499
})
0 commit comments