@@ -33,6 +33,7 @@ import (
33
33
"k8s.io/apimachinery/pkg/types"
34
34
"k8s.io/client-go/rest"
35
35
"k8s.io/client-go/util/workqueue"
36
+ "k8s.io/utils/pointer"
36
37
37
38
"sigs.k8s.io/controller-runtime/pkg/cache"
38
39
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -44,7 +45,6 @@ import (
44
45
"sigs.k8s.io/controller-runtime/pkg/predicate"
45
46
"sigs.k8s.io/controller-runtime/pkg/reconcile"
46
47
"sigs.k8s.io/controller-runtime/pkg/scheme"
47
- "sigs.k8s.io/controller-runtime/pkg/source"
48
48
)
49
49
50
50
type typedNoop struct {}
@@ -118,7 +118,7 @@ var _ = Describe("application", func() {
118
118
Expect (err ).NotTo (HaveOccurred ())
119
119
120
120
instance , err := ControllerManagedBy (m ).
121
- Watches (source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) , & handler.EnqueueRequestForObject {}).
121
+ Watches (& appsv1.ReplicaSet {}, & handler.EnqueueRequestForObject {}).
122
122
Build (noop )
123
123
Expect (err ).To (MatchError (ContainSubstring ("one of For() or Named() must be called" )))
124
124
Expect (instance ).To (BeNil ())
@@ -157,7 +157,7 @@ var _ = Describe("application", func() {
157
157
158
158
instance , err := ControllerManagedBy (m ).
159
159
Named ("my_controller" ).
160
- Watches (source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) , & handler.EnqueueRequestForObject {}).
160
+ Watches (& appsv1.ReplicaSet {}, & handler.EnqueueRequestForObject {}).
161
161
Build (noop )
162
162
Expect (err ).NotTo (HaveOccurred ())
163
163
Expect (instance ).NotTo (BeNil ())
@@ -362,14 +362,27 @@ var _ = Describe("application", func() {
362
362
doReconcileTest (ctx , "3" , m , false , bldr )
363
363
})
364
364
365
+ It ("should Reconcile Owns objects for every owner" , func () {
366
+ m , err := manager .New (cfg , manager.Options {})
367
+ Expect (err ).NotTo (HaveOccurred ())
368
+
369
+ bldr := ControllerManagedBy (m ).
370
+ For (& appsv1.Deployment {}).
371
+ Owns (& appsv1.ReplicaSet {}, MatchEveryOwner )
372
+
373
+ ctx , cancel := context .WithCancel (context .Background ())
374
+ defer cancel ()
375
+ doReconcileTest (ctx , "12" , m , false , bldr )
376
+ })
377
+
365
378
It ("should Reconcile Watches objects" , func () {
366
379
m , err := manager .New (cfg , manager.Options {})
367
380
Expect (err ).NotTo (HaveOccurred ())
368
381
369
382
bldr := ControllerManagedBy (m ).
370
383
For (& appsv1.Deployment {}).
371
384
Watches ( // Equivalent of Owns
372
- source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) ,
385
+ & appsv1.ReplicaSet {},
373
386
handler .EnqueueRequestForOwner (m .GetScheme (), m .GetRESTMapper (), & appsv1.Deployment {}, handler .OnlyControllerOwner ()),
374
387
)
375
388
@@ -385,9 +398,9 @@ var _ = Describe("application", func() {
385
398
bldr := ControllerManagedBy (m ).
386
399
Named ("Deployment" ).
387
400
Watches ( // Equivalent of For
388
- source . Kind ( m . GetCache (), & appsv1.Deployment {}) , & handler.EnqueueRequestForObject {}).
401
+ & appsv1.Deployment {}, & handler.EnqueueRequestForObject {}).
389
402
Watches ( // Equivalent of Owns
390
- source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) ,
403
+ & appsv1.ReplicaSet {},
391
404
handler .EnqueueRequestForOwner (m .GetScheme (), m .GetRESTMapper (), & appsv1.Deployment {}, handler .OnlyControllerOwner ()),
392
405
)
393
406
@@ -483,7 +496,7 @@ var _ = Describe("application", func() {
483
496
bldr := ControllerManagedBy (mgr ).
484
497
For (& appsv1.Deployment {}, OnlyMetadata ).
485
498
Owns (& appsv1.ReplicaSet {}, OnlyMetadata ).
486
- Watches (source . Kind ( mgr . GetCache (), & appsv1.StatefulSet {}) ,
499
+ Watches (& appsv1.StatefulSet {},
487
500
handler .EnqueueRequestsFromMapFunc (func (o client.Object ) []reconcile.Request {
488
501
defer GinkgoRecover ()
489
502
@@ -645,7 +658,6 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
645
658
646
659
By ("Creating a ReplicaSet" )
647
660
// Expect a Reconcile when an Owned object is managedObjects.
648
- t := true
649
661
rs := & appsv1.ReplicaSet {
650
662
ObjectMeta : metav1.ObjectMeta {
651
663
Namespace : "default" ,
@@ -656,7 +668,7 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
656
668
Name : deployName ,
657
669
Kind : "Deployment" ,
658
670
APIVersion : "apps/v1" ,
659
- Controller : & t ,
671
+ Controller : pointer . Bool ( true ) ,
660
672
UID : dep .UID ,
661
673
},
662
674
},
0 commit comments