@@ -486,6 +486,7 @@ var _ = Describe("Reconciler", func() {
486486 Expect (mgr .GetCache ().WaitForCacheSync (ctx )).To (BeTrue ())
487487
488488 obj = testutil .BuildTestCR (gvk )
489+ obj .SetLabels (map [string ]string {"foo" : "bar" })
489490 objKey = types.NamespacedName {Namespace : obj .GetNamespace (), Name : obj .GetName ()}
490491 req = reconcile.Request {NamespacedName : objKey }
491492 })
@@ -518,6 +519,8 @@ var _ = Describe("Reconciler", func() {
518519 cancel ()
519520 })
520521
522+ selector := metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }}
523+
521524 // After migration to Ginkgo v2 this can be rewritten using e.g. DescribeTable.
522525 parameterizedReconcilerTests := func (opts reconcilerTestSuiteOpts ) {
523526 BeforeEach (func () {
@@ -535,6 +538,7 @@ var _ = Describe("Reconciler", func() {
535538 WithInstallAnnotations (annotation.InstallDescription {}),
536539 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
537540 WithUninstallAnnotations (annotation.UninstallDescription {}),
541+ WithSelector (selector ),
538542 WithOverrideValues (map [string ]string {
539543 "image.repository" : "custom-nginx" ,
540544 }),
@@ -549,6 +553,7 @@ var _ = Describe("Reconciler", func() {
549553 WithInstallAnnotations (annotation.InstallDescription {}),
550554 WithUpgradeAnnotations (annotation.UpgradeDescription {}),
551555 WithUninstallAnnotations (annotation.UninstallDescription {}),
556+ WithSelector (selector ),
552557 WithOverrideValues (map [string ]string {
553558 "image.repository" : "custom-nginx" ,
554559 }),
@@ -1425,6 +1430,40 @@ var _ = Describe("Reconciler", func() {
14251430 })
14261431 })
14271432 })
1433+ When ("label selector succeeds" , func () {
1434+ It ("reconciles only matching label" , func () {
1435+ By ("setting an invalid action client getter to assert different reconcile results" , func () {
1436+ r .actionClientGetter = helmclient .ActionClientGetterFunc (func (context.Context , client.Object ) (helmclient.ActionInterface , error ) {
1437+ fakeClient := helmfake .NewActionClient ()
1438+ return & fakeClient , nil
1439+ })
1440+ })
1441+
1442+ By ("setting not matching label to the CR" , func () {
1443+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1444+ obj .SetLabels (map [string ]string {"foo" : "baz" })
1445+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1446+ })
1447+
1448+ By ("reconciling is skipped, action client was not called and no error returned" , func () {
1449+ res , err := r .Reconcile (ctx , req )
1450+ Expect (res ).To (Equal (reconcile.Result {}))
1451+ Expect (err ).ToNot (HaveOccurred ())
1452+ })
1453+
1454+ By ("setting matching label to the CR" , func () {
1455+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1456+ obj .SetLabels (map [string ]string {"foo" : "bar" })
1457+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1458+ })
1459+
1460+ By ("reconciling is not skipped and error returned because of broken action client" , func () {
1461+ res , err := r .Reconcile (ctx , req )
1462+ Expect (res ).To (Equal (reconcile.Result {}))
1463+ Expect (err ).To (MatchError ("get not implemented" ))
1464+ })
1465+ })
1466+ })
14281467 })
14291468 })
14301469 })
0 commit comments