@@ -33,6 +33,7 @@ import (
3333 "k8s.io/apimachinery/pkg/types"
3434 "k8s.io/client-go/rest"
3535 "k8s.io/client-go/util/workqueue"
36+ "k8s.io/utils/pointer"
3637
3738 "sigs.k8s.io/controller-runtime/pkg/cache"
3839 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -44,7 +45,6 @@ import (
4445 "sigs.k8s.io/controller-runtime/pkg/predicate"
4546 "sigs.k8s.io/controller-runtime/pkg/reconcile"
4647 "sigs.k8s.io/controller-runtime/pkg/scheme"
47- "sigs.k8s.io/controller-runtime/pkg/source"
4848)
4949
5050type typedNoop struct {}
@@ -118,7 +118,7 @@ var _ = Describe("application", func() {
118118 Expect (err ).NotTo (HaveOccurred ())
119119
120120 instance , err := ControllerManagedBy (m ).
121- Watches (source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) , & handler.EnqueueRequestForObject {}).
121+ Watches (& appsv1.ReplicaSet {}, & handler.EnqueueRequestForObject {}).
122122 Build (noop )
123123 Expect (err ).To (MatchError (ContainSubstring ("one of For() or Named() must be called" )))
124124 Expect (instance ).To (BeNil ())
@@ -157,7 +157,7 @@ var _ = Describe("application", func() {
157157
158158 instance , err := ControllerManagedBy (m ).
159159 Named ("my_controller" ).
160- Watches (source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) , & handler.EnqueueRequestForObject {}).
160+ Watches (& appsv1.ReplicaSet {}, & handler.EnqueueRequestForObject {}).
161161 Build (noop )
162162 Expect (err ).NotTo (HaveOccurred ())
163163 Expect (instance ).NotTo (BeNil ())
@@ -362,14 +362,27 @@ var _ = Describe("application", func() {
362362 doReconcileTest (ctx , "3" , m , false , bldr )
363363 })
364364
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+
365378 It ("should Reconcile Watches objects" , func () {
366379 m , err := manager .New (cfg , manager.Options {})
367380 Expect (err ).NotTo (HaveOccurred ())
368381
369382 bldr := ControllerManagedBy (m ).
370383 For (& appsv1.Deployment {}).
371384 Watches ( // Equivalent of Owns
372- source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) ,
385+ & appsv1.ReplicaSet {},
373386 handler .EnqueueRequestForOwner (m .GetScheme (), m .GetRESTMapper (), & appsv1.Deployment {}, handler .OnlyControllerOwner ()),
374387 )
375388
@@ -385,9 +398,9 @@ var _ = Describe("application", func() {
385398 bldr := ControllerManagedBy (m ).
386399 Named ("Deployment" ).
387400 Watches ( // Equivalent of For
388- source . Kind ( m . GetCache (), & appsv1.Deployment {}) , & handler.EnqueueRequestForObject {}).
401+ & appsv1.Deployment {}, & handler.EnqueueRequestForObject {}).
389402 Watches ( // Equivalent of Owns
390- source . Kind ( m . GetCache (), & appsv1.ReplicaSet {}) ,
403+ & appsv1.ReplicaSet {},
391404 handler .EnqueueRequestForOwner (m .GetScheme (), m .GetRESTMapper (), & appsv1.Deployment {}, handler .OnlyControllerOwner ()),
392405 )
393406
@@ -483,7 +496,7 @@ var _ = Describe("application", func() {
483496 bldr := ControllerManagedBy (mgr ).
484497 For (& appsv1.Deployment {}, OnlyMetadata ).
485498 Owns (& appsv1.ReplicaSet {}, OnlyMetadata ).
486- Watches (source . Kind ( mgr . GetCache (), & appsv1.StatefulSet {}) ,
499+ Watches (& appsv1.StatefulSet {},
487500 handler .EnqueueRequestsFromMapFunc (func (o client.Object ) []reconcile.Request {
488501 defer GinkgoRecover ()
489502
@@ -645,7 +658,6 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
645658
646659 By ("Creating a ReplicaSet" )
647660 // Expect a Reconcile when an Owned object is managedObjects.
648- t := true
649661 rs := & appsv1.ReplicaSet {
650662 ObjectMeta : metav1.ObjectMeta {
651663 Namespace : "default" ,
@@ -656,7 +668,7 @@ func doReconcileTest(ctx context.Context, nameSuffix string, mgr manager.Manager
656668 Name : deployName ,
657669 Kind : "Deployment" ,
658670 APIVersion : "apps/v1" ,
659- Controller : & t ,
671+ Controller : pointer . Bool ( true ) ,
660672 UID : dep .UID ,
661673 },
662674 },
0 commit comments