@@ -486,6 +486,7 @@ var _ = Describe("Reconciler", func() {
486
486
Expect (mgr .GetCache ().WaitForCacheSync (ctx )).To (BeTrue ())
487
487
488
488
obj = testutil .BuildTestCR (gvk )
489
+ obj .SetLabels (map [string ]string {"foo" : "bar" })
489
490
objKey = types.NamespacedName {Namespace : obj .GetNamespace (), Name : obj .GetName ()}
490
491
req = reconcile.Request {NamespacedName : objKey }
491
492
})
@@ -518,6 +519,8 @@ var _ = Describe("Reconciler", func() {
518
519
cancel ()
519
520
})
520
521
522
+ selector := metav1.LabelSelector {MatchLabels : map [string ]string {"foo" : "bar" }}
523
+
521
524
// After migration to Ginkgo v2 this can be rewritten using e.g. DescribeTable.
522
525
parameterizedReconcilerTests := func (opts reconcilerTestSuiteOpts ) {
523
526
BeforeEach (func () {
@@ -535,6 +538,7 @@ var _ = Describe("Reconciler", func() {
535
538
WithInstallAnnotations (annotation.InstallDescription {}),
536
539
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
537
540
WithUninstallAnnotations (annotation.UninstallDescription {}),
541
+ WithSelector (selector ),
538
542
WithOverrideValues (map [string ]string {
539
543
"image.repository" : "custom-nginx" ,
540
544
}),
@@ -549,6 +553,7 @@ var _ = Describe("Reconciler", func() {
549
553
WithInstallAnnotations (annotation.InstallDescription {}),
550
554
WithUpgradeAnnotations (annotation.UpgradeDescription {}),
551
555
WithUninstallAnnotations (annotation.UninstallDescription {}),
556
+ WithSelector (selector ),
552
557
WithOverrideValues (map [string ]string {
553
558
"image.repository" : "custom-nginx" ,
554
559
}),
@@ -1425,6 +1430,40 @@ var _ = Describe("Reconciler", func() {
1425
1430
})
1426
1431
})
1427
1432
})
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
+ })
1428
1467
})
1429
1468
})
1430
1469
})
0 commit comments