@@ -17,6 +17,7 @@ limitations under the License.
17
17
package config
18
18
19
19
import (
20
+ "context"
20
21
"math/rand"
21
22
"reflect"
22
23
"sort"
@@ -85,10 +86,10 @@ func CreatePodUpdate(op kubetypes.PodOperation, source string, pods ...*v1.Pod)
85
86
return kubetypes.PodUpdate {Pods : pods , Op : op , Source : source }
86
87
}
87
88
88
- func createPodConfigTester (mode PodConfigNotificationMode ) (chan <- interface {}, <- chan kubetypes.PodUpdate , * PodConfig ) {
89
+ func createPodConfigTester (ctx context. Context , mode PodConfigNotificationMode ) (chan <- interface {}, <- chan kubetypes.PodUpdate , * PodConfig ) {
89
90
eventBroadcaster := record .NewBroadcaster ()
90
91
config := NewPodConfig (mode , eventBroadcaster .NewRecorder (scheme .Scheme , v1.EventSource {Component : "kubelet" }))
91
- channel := config .Channel (TestSource )
92
+ channel := config .Channel (ctx , TestSource )
92
93
ch := config .Updates ()
93
94
return channel , ch , config
94
95
}
@@ -129,7 +130,10 @@ func expectNoPodUpdate(t *testing.T, ch <-chan kubetypes.PodUpdate) {
129
130
}
130
131
131
132
func TestNewPodAdded (t * testing.T ) {
132
- channel , ch , config := createPodConfigTester (PodConfigNotificationIncremental )
133
+ ctx , cancel := context .WithCancel (context .Background ())
134
+ defer cancel ()
135
+
136
+ channel , ch , config := createPodConfigTester (ctx , PodConfigNotificationIncremental )
133
137
134
138
// see an update
135
139
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "new" ))
@@ -141,7 +145,10 @@ func TestNewPodAdded(t *testing.T) {
141
145
}
142
146
143
147
func TestNewPodAddedInvalidNamespace (t * testing.T ) {
144
- channel , ch , config := createPodConfigTester (PodConfigNotificationIncremental )
148
+ ctx , cancel := context .WithCancel (context .Background ())
149
+ defer cancel ()
150
+
151
+ channel , ch , config := createPodConfigTester (ctx , PodConfigNotificationIncremental )
145
152
146
153
// see an update
147
154
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "" ))
@@ -153,7 +160,10 @@ func TestNewPodAddedInvalidNamespace(t *testing.T) {
153
160
}
154
161
155
162
func TestNewPodAddedDefaultNamespace (t * testing.T ) {
156
- channel , ch , config := createPodConfigTester (PodConfigNotificationIncremental )
163
+ ctx , cancel := context .WithCancel (context .Background ())
164
+ defer cancel ()
165
+
166
+ channel , ch , config := createPodConfigTester (ctx , PodConfigNotificationIncremental )
157
167
158
168
// see an update
159
169
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "default" ))
@@ -165,7 +175,10 @@ func TestNewPodAddedDefaultNamespace(t *testing.T) {
165
175
}
166
176
167
177
func TestNewPodAddedDifferentNamespaces (t * testing.T ) {
168
- channel , ch , config := createPodConfigTester (PodConfigNotificationIncremental )
178
+ ctx , cancel := context .WithCancel (context .Background ())
179
+ defer cancel ()
180
+
181
+ channel , ch , config := createPodConfigTester (ctx , PodConfigNotificationIncremental )
169
182
170
183
// see an update
171
184
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "default" ))
@@ -182,7 +195,10 @@ func TestNewPodAddedDifferentNamespaces(t *testing.T) {
182
195
}
183
196
184
197
func TestInvalidPodFiltered (t * testing.T ) {
185
- channel , ch , _ := createPodConfigTester (PodConfigNotificationIncremental )
198
+ ctx , cancel := context .WithCancel (context .Background ())
199
+ defer cancel ()
200
+
201
+ channel , ch , _ := createPodConfigTester (ctx , PodConfigNotificationIncremental )
186
202
187
203
// see an update
188
204
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "new" ))
@@ -196,7 +212,10 @@ func TestInvalidPodFiltered(t *testing.T) {
196
212
}
197
213
198
214
func TestNewPodAddedSnapshotAndUpdates (t * testing.T ) {
199
- channel , ch , config := createPodConfigTester (PodConfigNotificationSnapshotAndUpdates )
215
+ ctx , cancel := context .WithCancel (context .Background ())
216
+ defer cancel ()
217
+
218
+ channel , ch , config := createPodConfigTester (ctx , PodConfigNotificationSnapshotAndUpdates )
200
219
201
220
// see an set
202
221
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "new" ))
@@ -214,7 +233,10 @@ func TestNewPodAddedSnapshotAndUpdates(t *testing.T) {
214
233
}
215
234
216
235
func TestNewPodAddedSnapshot (t * testing.T ) {
217
- channel , ch , config := createPodConfigTester (PodConfigNotificationSnapshot )
236
+ ctx , cancel := context .WithCancel (context .Background ())
237
+ defer cancel ()
238
+
239
+ channel , ch , config := createPodConfigTester (ctx , PodConfigNotificationSnapshot )
218
240
219
241
// see an set
220
242
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "new" ))
@@ -232,7 +254,10 @@ func TestNewPodAddedSnapshot(t *testing.T) {
232
254
}
233
255
234
256
func TestNewPodAddedUpdatedRemoved (t * testing.T ) {
235
- channel , ch , _ := createPodConfigTester (PodConfigNotificationIncremental )
257
+ ctx , cancel := context .WithCancel (context .Background ())
258
+ defer cancel ()
259
+
260
+ channel , ch , _ := createPodConfigTester (ctx , PodConfigNotificationIncremental )
236
261
237
262
// should register an add
238
263
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "new" ))
@@ -255,7 +280,10 @@ func TestNewPodAddedUpdatedRemoved(t *testing.T) {
255
280
}
256
281
257
282
func TestNewPodAddedDelete (t * testing.T ) {
258
- channel , ch , _ := createPodConfigTester (PodConfigNotificationIncremental )
283
+ ctx , cancel := context .WithCancel (context .Background ())
284
+ defer cancel ()
285
+
286
+ channel , ch , _ := createPodConfigTester (ctx , PodConfigNotificationIncremental )
259
287
260
288
// should register an add
261
289
addedPod := CreateValidPod ("foo" , "new" )
@@ -274,7 +302,10 @@ func TestNewPodAddedDelete(t *testing.T) {
274
302
}
275
303
276
304
func TestNewPodAddedUpdatedSet (t * testing.T ) {
277
- channel , ch , _ := createPodConfigTester (PodConfigNotificationIncremental )
305
+ ctx , cancel := context .WithCancel (context .Background ())
306
+ defer cancel ()
307
+
308
+ channel , ch , _ := createPodConfigTester (ctx , PodConfigNotificationIncremental )
278
309
279
310
// should register an add
280
311
podUpdate := CreatePodUpdate (kubetypes .ADD , TestSource , CreateValidPod ("foo" , "new" ), CreateValidPod ("foo2" , "new" ), CreateValidPod ("foo3" , "new" ))
@@ -296,6 +327,9 @@ func TestNewPodAddedUpdatedSet(t *testing.T) {
296
327
}
297
328
298
329
func TestNewPodAddedSetReconciled (t * testing.T ) {
330
+ ctx , cancel := context .WithCancel (context .Background ())
331
+ defer cancel ()
332
+
299
333
// Create and touch new test pods, return the new pods and touched pod. We should create new pod list
300
334
// before touching to avoid data race.
301
335
newTestPods := func (touchStatus , touchSpec bool ) ([]* v1.Pod , * v1.Pod ) {
@@ -318,7 +352,7 @@ func TestNewPodAddedSetReconciled(t *testing.T) {
318
352
} {
319
353
var podWithStatusChange * v1.Pod
320
354
pods , _ := newTestPods (false , false )
321
- channel , ch , _ := createPodConfigTester (PodConfigNotificationIncremental )
355
+ channel , ch , _ := createPodConfigTester (ctx , PodConfigNotificationIncremental )
322
356
323
357
// Use SET to initialize the config, especially initialize the source set
324
358
channel <- CreatePodUpdate (kubetypes .SET , TestSource , pods ... )
@@ -341,6 +375,9 @@ func TestNewPodAddedSetReconciled(t *testing.T) {
341
375
}
342
376
343
377
func TestInitialEmptySet (t * testing.T ) {
378
+ ctx , cancel := context .WithCancel (context .Background ())
379
+ defer cancel ()
380
+
344
381
for _ , test := range []struct {
345
382
mode PodConfigNotificationMode
346
383
op kubetypes.PodOperation
@@ -349,7 +386,7 @@ func TestInitialEmptySet(t *testing.T) {
349
386
{PodConfigNotificationSnapshot , kubetypes .SET },
350
387
{PodConfigNotificationSnapshotAndUpdates , kubetypes .SET },
351
388
} {
352
- channel , ch , _ := createPodConfigTester (test .mode )
389
+ channel , ch , _ := createPodConfigTester (ctx , test .mode )
353
390
354
391
// should register an empty PodUpdate operation
355
392
podUpdate := CreatePodUpdate (kubetypes .SET , TestSource )
@@ -366,7 +403,10 @@ func TestInitialEmptySet(t *testing.T) {
366
403
}
367
404
368
405
func TestPodUpdateAnnotations (t * testing.T ) {
369
- channel , ch , _ := createPodConfigTester (PodConfigNotificationIncremental )
406
+ ctx , cancel := context .WithCancel (context .Background ())
407
+ defer cancel ()
408
+
409
+ channel , ch , _ := createPodConfigTester (ctx , PodConfigNotificationIncremental )
370
410
371
411
pod := CreateValidPod ("foo2" , "new" )
372
412
pod .Annotations = make (map [string ]string )
@@ -395,7 +435,10 @@ func TestPodUpdateAnnotations(t *testing.T) {
395
435
}
396
436
397
437
func TestPodUpdateLabels (t * testing.T ) {
398
- channel , ch , _ := createPodConfigTester (PodConfigNotificationIncremental )
438
+ ctx , cancel := context .WithCancel (context .Background ())
439
+ defer cancel ()
440
+
441
+ channel , ch , _ := createPodConfigTester (ctx , PodConfigNotificationIncremental )
399
442
400
443
pod := CreateValidPod ("foo2" , "new" )
401
444
pod .Labels = make (map [string ]string )
0 commit comments