@@ -83,16 +83,17 @@ var _ = Describe("Multi-Namespace Informer Cache", func() {
83
83
func CacheTest (createCacheFunc func (config * rest.Config , opts cache.Options ) (cache.Cache , error )) {
84
84
Describe ("Cache test" , func () {
85
85
var (
86
- informerCache cache.Cache
87
- stop chan struct {}
88
- knownPod1 runtime.Object
89
- knownPod2 runtime.Object
90
- knownPod3 runtime.Object
91
- knownPod4 runtime.Object
86
+ informerCache cache.Cache
87
+ informerCacheCtx context.Context
88
+ informerCacheCancel context.CancelFunc
89
+ knownPod1 runtime.Object
90
+ knownPod2 runtime.Object
91
+ knownPod3 runtime.Object
92
+ knownPod4 runtime.Object
92
93
)
93
94
94
95
BeforeEach (func () {
95
- stop = make ( chan struct {} )
96
+ informerCacheCtx , informerCacheCancel = context . WithCancel ( context . Background () )
96
97
Expect (cfg ).NotTo (BeNil ())
97
98
98
99
By ("creating three pods" )
@@ -123,11 +124,11 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
123
124
Expect (err ).NotTo (HaveOccurred ())
124
125
By ("running the cache and waiting for it to sync" )
125
126
// pass as an arg so that we don't race between close and re-assign
126
- go func (stopCh chan struct {} ) {
127
+ go func (ctx context. Context ) {
127
128
defer GinkgoRecover ()
128
- Expect (informerCache .Start (stopCh )).To (Succeed ())
129
- }(stop )
130
- Expect (informerCache .WaitForCacheSync (stop )).To (BeTrue ())
129
+ Expect (informerCache .Start (ctx )).To (Succeed ())
130
+ }(informerCacheCtx )
131
+ Expect (informerCache .WaitForCacheSync (informerCacheCtx )).To (BeTrue ())
131
132
})
132
133
133
134
AfterEach (func () {
@@ -137,7 +138,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
137
138
deletePod (knownPod3 )
138
139
deletePod (knownPod4 )
139
140
140
- close ( stop )
141
+ informerCacheCancel ( )
141
142
})
142
143
143
144
Describe ("as a Reader" , func () {
@@ -394,11 +395,13 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
394
395
Expect (err ).NotTo (HaveOccurred ())
395
396
396
397
By ("running the cache and waiting for it to sync" )
398
+ ctx , cancel := context .WithCancel (context .Background ())
399
+ defer cancel ()
397
400
go func () {
398
401
defer GinkgoRecover ()
399
- Expect (namespacedCache .Start (stop )).To (Succeed ())
402
+ Expect (namespacedCache .Start (ctx )).To (Succeed ())
400
403
}()
401
- Expect (namespacedCache .WaitForCacheSync (stop )).NotTo (BeFalse ())
404
+ Expect (namespacedCache .WaitForCacheSync (ctx )).NotTo (BeFalse ())
402
405
403
406
By ("listing pods in all namespaces" )
404
407
out := & unstructured.UnstructuredList {}
@@ -572,11 +575,13 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
572
575
Expect (informer .IndexField (context .TODO (), pod , "spec.restartPolicy" , indexFunc )).To (Succeed ())
573
576
574
577
By ("running the cache and waiting for it to sync" )
578
+ ctx , cancel := context .WithCancel (context .Background ())
579
+ defer cancel ()
575
580
go func () {
576
581
defer GinkgoRecover ()
577
- Expect (informer .Start (stop )).To (Succeed ())
582
+ Expect (informer .Start (ctx )).To (Succeed ())
578
583
}()
579
- Expect (informer .WaitForCacheSync (stop )).NotTo (BeFalse ())
584
+ Expect (informer .WaitForCacheSync (ctx )).NotTo (BeFalse ())
580
585
581
586
By ("listing Pods with restartPolicyOnFailure" )
582
587
listObj := & kcorev1.PodList {}
@@ -636,7 +641,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
636
641
Object : map [string ]interface {}{
637
642
"spec" : map [string ]interface {}{
638
643
"containers" : []map [string ]interface {}{
639
- map [ string ] interface {} {
644
+ {
640
645
"name" : "nginx" ,
641
646
"image" : "nginx" ,
642
647
},
@@ -700,11 +705,13 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
700
705
Expect (informer .IndexField (context .TODO (), pod , "spec.restartPolicy" , indexFunc )).To (Succeed ())
701
706
702
707
By ("running the cache and waiting for it to sync" )
708
+ ctx , cancel := context .WithCancel (context .Background ())
709
+ defer cancel ()
703
710
go func () {
704
711
defer GinkgoRecover ()
705
- Expect (informer .Start (stop )).To (Succeed ())
712
+ Expect (informer .Start (ctx )).To (Succeed ())
706
713
}()
707
- Expect (informer .WaitForCacheSync (stop )).NotTo (BeFalse ())
714
+ Expect (informer .WaitForCacheSync (ctx )).NotTo (BeFalse ())
708
715
709
716
By ("listing Pods with restartPolicyOnFailure" )
710
717
listObj := & unstructured.UnstructuredList {}
0 commit comments