@@ -501,6 +501,7 @@ var _ = Describe("Reconciler", func() {
501501 Expect (mgr .GetCache ().WaitForCacheSync (ctx )).To (BeTrue ())
502502
503503 obj = testutil .BuildTestCR (gvk )
504+ obj .SetLabels (map [string ]string {"foo" : "bar" })
504505 objKey = types.NamespacedName {Namespace : obj .GetNamespace (), Name : obj .GetName ()}
505506 req = reconcile.Request {NamespacedName : objKey }
506507 })
@@ -533,6 +534,8 @@ var _ = Describe("Reconciler", func() {
533534 cancel ()
534535 })
535536
537+ selector := metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }}
538+
536539 // After migration to Ginkgo v2 this can be rewritten using e.g. DescribeTable.
537540 parameterizedReconcilerTests := func (opts reconcilerTestSuiteOpts ) {
538541 BeforeEach (func () {
@@ -551,6 +554,7 @@ var _ = Describe("Reconciler", func() {
551554 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
552555 WithUninstallAnnotations (annotation.UninstallDescription {}),
553556 WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
557+ WithSelector (selector ),
554558 WithOverrideValues (map [string ]string {
555559 "image.repository" : "custom-nginx" ,
556560 }),
@@ -566,6 +570,7 @@ var _ = Describe("Reconciler", func() {
566570 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
567571 WithUninstallAnnotations (annotation.UninstallDescription {}),
568572 WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
573+ WithSelector (selector ),
569574 WithOverrideValues (map [string ]string {
570575 "image.repository" : "custom-nginx" ,
571576 }),
@@ -1455,6 +1460,40 @@ var _ = Describe("Reconciler", func() {
14551460 })
14561461 })
14571462 })
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+ })
14581497 })
14591498 })
14601499 })
0 commit comments