@@ -503,6 +503,7 @@ var _ = Describe("Reconciler", func() {
503
503
Expect (mgr .GetCache ().WaitForCacheSync (ctx )).To (BeTrue ())
504
504
505
505
obj = testutil .BuildTestCR (gvk )
506
+ obj .SetLabels (map [string ]string {"foo" : "bar" })
506
507
objKey = types.NamespacedName {Namespace : obj .GetNamespace (), Name : obj .GetName ()}
507
508
req = reconcile.Request {NamespacedName : objKey }
508
509
})
@@ -535,6 +536,8 @@ var _ = Describe("Reconciler", func() {
535
536
cancel ()
536
537
})
537
538
539
+ selector := metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }}
540
+
538
541
// After migration to Ginkgo v2 this can be rewritten using e.g. DescribeTable.
539
542
parameterizedReconcilerTests := func (opts reconcilerTestSuiteOpts ) {
540
543
BeforeEach (func () {
@@ -553,6 +556,7 @@ var _ = Describe("Reconciler", func() {
553
556
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
554
557
WithUninstallAnnotations (annotation.UninstallDescription {}),
555
558
WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
559
+ WithSelector (selector ),
556
560
WithOverrideValues (map [string ]string {
557
561
"image.repository" : "custom-nginx" ,
558
562
}),
@@ -568,6 +572,7 @@ var _ = Describe("Reconciler", func() {
568
572
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
569
573
WithUninstallAnnotations (annotation.UninstallDescription {}),
570
574
WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
575
+ WithSelector (selector ),
571
576
WithOverrideValues (map [string ]string {
572
577
"image.repository" : "custom-nginx" ,
573
578
}),
@@ -1502,6 +1507,40 @@ var _ = Describe("Reconciler", func() {
1502
1507
})
1503
1508
})
1504
1509
})
1510
+ When ("label selector succeeds" , func () {
1511
+ It ("reconciles only matching label" , func () {
1512
+ By ("setting an invalid action client getter to assert different reconcile results" , func () {
1513
+ r .actionClientGetter = helmclient .ActionClientGetterFunc (func (context.Context , client.Object ) (helmclient.ActionInterface , error ) {
1514
+ fakeClient := helmfake .NewActionClient ()
1515
+ return & fakeClient , nil
1516
+ })
1517
+ })
1518
+
1519
+ By ("setting not matching label to the CR" , func () {
1520
+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1521
+ obj .SetLabels (map [string ]string {"foo" : "baz" })
1522
+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1523
+ })
1524
+
1525
+ By ("reconciling is skipped, action client was not called and no error returned" , func () {
1526
+ res , err := r .Reconcile (ctx , req )
1527
+ Expect (res ).To (Equal (reconcile.Result {}))
1528
+ Expect (err ).To (BeNil ())
1529
+ })
1530
+
1531
+ By ("setting matching label to the CR" , func () {
1532
+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1533
+ obj .SetLabels (map [string ]string {"foo" : "bar" })
1534
+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1535
+ })
1536
+
1537
+ By ("reconciling is not skipped and error returned because of broken action client" , func () {
1538
+ res , err := r .Reconcile (ctx , req )
1539
+ Expect (res ).To (Equal (reconcile.Result {}))
1540
+ Expect (err ).To (MatchError ("get not implemented" ))
1541
+ })
1542
+ })
1543
+ })
1505
1544
})
1506
1545
})
1507
1546
})
0 commit comments