@@ -484,6 +484,7 @@ var _ = Describe("Reconciler", func() {
484
484
Expect (mgr .GetCache ().WaitForCacheSync (ctx )).To (BeTrue ())
485
485
486
486
obj = testutil .BuildTestCR (gvk )
487
+ obj .SetLabels (map [string ]string {"foo" : "bar" })
487
488
objKey = types.NamespacedName {Namespace : obj .GetNamespace (), Name : obj .GetName ()}
488
489
req = reconcile.Request {NamespacedName : objKey }
489
490
@@ -517,6 +518,8 @@ var _ = Describe("Reconciler", func() {
517
518
cancel ()
518
519
})
519
520
521
+ selector := metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }}
522
+
520
523
// After migration to Ginkgo v2 this can be rewritten using e.g. DescribeTable.
521
524
parameterizedReconcilerTests := func (opts reconcilerTestSuiteOpts ) {
522
525
BeforeEach (func () {
@@ -535,6 +538,7 @@ var _ = Describe("Reconciler", func() {
535
538
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
536
539
WithUninstallAnnotations (annotation.UninstallDescription {}),
537
540
WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
541
+ WithSelector (selector ),
538
542
WithOverrideValues (map [string ]string {
539
543
"image.repository" : "custom-nginx" ,
540
544
}),
@@ -550,6 +554,7 @@ var _ = Describe("Reconciler", func() {
550
554
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
551
555
WithUninstallAnnotations (annotation.UninstallDescription {}),
552
556
WithPauseReconcileAnnotation ("my.domain/pause-reconcile" ),
557
+ WithSelector (selector ),
553
558
WithOverrideValues (map [string ]string {
554
559
"image.repository" : "custom-nginx" ,
555
560
}),
@@ -1392,6 +1397,40 @@ var _ = Describe("Reconciler", func() {
1392
1397
})
1393
1398
})
1394
1399
})
1400
+ When ("label selector succeeds" , func () {
1401
+ It ("reconciles only matching label" , func () {
1402
+ By ("setting an invalid action client getter to assert different reconcile results" , func () {
1403
+ r .actionClientGetter = helmclient .ActionClientGetterFunc (func (client.Object ) (helmclient.ActionInterface , error ) {
1404
+ fakeClient := helmfake .NewActionClient ()
1405
+ return & fakeClient , nil
1406
+ })
1407
+ })
1408
+
1409
+ By ("setting not matching label to the CR" , func () {
1410
+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1411
+ obj .SetLabels (map [string ]string {"foo" : "baz" })
1412
+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1413
+ })
1414
+
1415
+ By ("reconciling is skipped, action client was not called and no error returned" , func () {
1416
+ res , err := r .Reconcile (ctx , req )
1417
+ Expect (res ).To (Equal (reconcile.Result {}))
1418
+ Expect (err ).To (BeNil ())
1419
+ })
1420
+
1421
+ By ("setting matching label to the CR" , func () {
1422
+ Expect (mgr .GetClient ().Get (ctx , objKey , obj )).To (Succeed ())
1423
+ obj .SetLabels (map [string ]string {"foo" : "bar" })
1424
+ Expect (mgr .GetClient ().Update (ctx , obj )).To (Succeed ())
1425
+ })
1426
+
1427
+ By ("reconciling is not skipped and error returned because of broken action client" , func () {
1428
+ res , err := r .Reconcile (ctx , req )
1429
+ Expect (res ).To (Equal (reconcile.Result {}))
1430
+ Expect (err ).To (MatchError ("get not implemented" ))
1431
+ })
1432
+ })
1433
+ })
1395
1434
})
1396
1435
})
1397
1436
})
0 commit comments