@@ -503,6 +503,7 @@ var _ = Describe("Reconciler", func() {
503503 Expect (mgr .GetCache ().WaitForCacheSync (ctx )).To (BeTrue ())
504504
505505 obj = testutil .BuildTestCR (gvk )
506+ obj .SetLabels (map [string ]string {"foo" : "bar" })
506507 objKey = types.NamespacedName {Namespace : obj .GetNamespace (), Name : obj .GetName ()}
507508 req = reconcile.Request {NamespacedName : objKey }
508509 })
@@ -535,6 +536,8 @@ var _ = Describe("Reconciler", func() {
535536 cancel ()
536537 })
537538
539+ selector := metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }}
540+
538541 // After migration to Ginkgo v2 this can be rewritten using e.g. DescribeTable.
539542 parameterizedReconcilerTests := func (opts reconcilerTestSuiteOpts ) {
540543 BeforeEach (func () {
@@ -553,6 +556,7 @@ var _ = Describe("Reconciler", func() {
553556 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
554557 WithUninstallAnnotations (annotation.UninstallDescription {}),
555558 WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
559+ WithSelector (selector ),
556560 WithOverrideValues (map [string ]string {
557561 "image.repository" : "custom-nginx" ,
558562 }),
@@ -568,6 +572,7 @@ var _ = Describe("Reconciler", func() {
568572 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
569573 WithUninstallAnnotations (annotation.UninstallDescription {}),
570574 WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
575+ WithSelector (selector ),
571576 WithOverrideValues (map [string ]string {
572577 "image.repository" : "custom-nginx" ,
573578 }),
@@ -1502,6 +1507,40 @@ var _ = Describe("Reconciler", func() {
15021507 })
15031508 })
15041509 })
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 ).ToNot (HaveOccurred ())
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+ })
15051544 })
15061545 })
15071546 })
0 commit comments