@@ -59,11 +59,25 @@ func controllerSetup(startingObjects []runtime.Object, t *testing.T, stopCh <-ch
59
59
DockerURLsInitialized : make (chan struct {}),
60
60
},
61
61
)
62
+ controller .initialSecretsCheckDone = true
62
63
controller .secretsSynced = func () bool { return true }
63
64
return kubeclient , fakeWatch , controller , informerFactory
64
65
}
65
66
66
- func wrapHandler (indicator chan bool , handler func (string ) error , t * testing.T ) func (string ) error {
67
+ func wrapHandler (indicator chan bool , handler func () error , t * testing.T ) func () error {
68
+ return func () error {
69
+ defer func () { indicator <- true }()
70
+
71
+ err := handler ()
72
+ if err != nil {
73
+ t .Errorf ("unexpected error: %v" , err )
74
+ }
75
+
76
+ return err
77
+ }
78
+ }
79
+
80
+ func wrapStringHandler (indicator chan bool , handler func (string ) error , t * testing.T ) func (string ) error {
67
81
return func (key string ) error {
68
82
defer func () { indicator <- true }()
69
83
@@ -129,7 +143,8 @@ func TestUpdateNewStyleSecret(t *testing.T) {
129
143
130
144
kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {newStyleDockercfgSecret }, t , stopChannel )
131
145
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
132
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
146
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
147
+ controller .initialSecretsCheckDone = false
133
148
informerFactory .Start (stopChannel )
134
149
go controller .Run (5 , stopChannel )
135
150
@@ -139,6 +154,9 @@ func TestUpdateNewStyleSecret(t *testing.T) {
139
154
case <- time .After (time .Duration (45 * time .Second )):
140
155
t .Fatalf ("failed to become ready" )
141
156
}
157
+ if controller .initialSecretsCheckDone != false {
158
+ t .Fatalf ("initialSecretsCheckDone should be false" )
159
+ }
142
160
143
161
fakeWatch .Modify (registryService )
144
162
t .Log ("Waiting to reach syncRegistryLocationHandler" )
@@ -147,6 +165,12 @@ func TestUpdateNewStyleSecret(t *testing.T) {
147
165
case <- time .After (time .Duration (45 * time .Second )):
148
166
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
149
167
}
168
+
169
+ // after this point the secrets should be added to the queue and initial check should be done.
170
+ if controller .initialSecretsCheckDone != true {
171
+ t .Fatalf ("initialSecretsCheckDone should be true" )
172
+ }
173
+
150
174
t .Log ("Waiting to update secret" )
151
175
select {
152
176
case <- updatedSecret :
@@ -216,9 +240,10 @@ func TestUpdateOldStyleSecretWithKey(t *testing.T) {
216
240
Data : map [string ][]byte {v1 .DockerConfigKey : dockercfgContent },
217
241
}
218
242
219
- kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {oldStyleDockercfgSecret }, t , stopChannel )
243
+ kubeclient , _ , controller , informerFactory := controllerSetup ([]runtime.Object {registryService , oldStyleDockercfgSecret }, t , stopChannel )
220
244
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
221
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
245
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
246
+ controller .initialSecretsCheckDone = false
222
247
informerFactory .Start (stopChannel )
223
248
go controller .Run (5 , stopChannel )
224
249
@@ -229,8 +254,6 @@ func TestUpdateOldStyleSecretWithKey(t *testing.T) {
229
254
t .Fatalf ("failed to become ready" )
230
255
}
231
256
232
- fakeWatch .Modify (registryService )
233
-
234
257
t .Log ("Waiting to reach syncRegistryLocationHandler" )
235
258
select {
236
259
case <- received :
@@ -309,7 +332,7 @@ func TestUpdateOldStyleSecretWithoutKey(t *testing.T) {
309
332
return true , tokenSecret , nil
310
333
})
311
334
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
312
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
335
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
313
336
informerFactory .Start (stopChannel )
314
337
go controller .Run (5 , stopChannel )
315
338
@@ -400,17 +423,18 @@ func TestClearSecretAndRecreate(t *testing.T) {
400
423
401
424
kubeclient , fakeWatch , controller , informerFactory := controllerSetup ([]runtime.Object {registryService , oldStyleDockercfgSecret }, t , stopChannel )
402
425
controller .syncRegistryLocationHandler = wrapHandler (received , controller .syncRegistryLocationChange , t )
403
- controller .syncSecretHandler = wrapHandler (updatedSecret , controller .syncSecretUpdate , t )
426
+ controller .syncSecretHandler = wrapStringHandler (updatedSecret , controller .syncSecretUpdate , t )
404
427
informerFactory .Start (stopChannel )
405
428
go controller .Run (5 , stopChannel )
406
429
407
430
t .Log ("Waiting for ready" )
408
431
select {
409
432
case <- controller .dockerURLsInitialized :
410
433
case <- time .After (time .Duration (45 * time .Second )):
411
- t .Fatalf ("failed to become ready " )
434
+ t .Fatalf ("failed waiting for dockerURLsInitialized " )
412
435
}
413
436
437
+ t .Logf ("deleting %s service" , registryService .Name )
414
438
fakeWatch .Delete (registryService )
415
439
416
440
t .Log ("Waiting for first update" )
@@ -419,6 +443,7 @@ func TestClearSecretAndRecreate(t *testing.T) {
419
443
case <- time .After (time .Duration (45 * time .Second )):
420
444
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
421
445
}
446
+
422
447
t .Log ("Waiting to update secret" )
423
448
select {
424
449
case <- updatedSecret :
@@ -449,6 +474,8 @@ func TestClearSecretAndRecreate(t *testing.T) {
449
474
}
450
475
451
476
kubeclient .ClearActions ()
477
+
478
+ t .Logf ("adding %s service" , registryService .Name )
452
479
fakeWatch .Add (registryService )
453
480
454
481
t .Log ("Waiting for second update" )
@@ -457,6 +484,7 @@ func TestClearSecretAndRecreate(t *testing.T) {
457
484
case <- time .After (time .Duration (45 * time .Second )):
458
485
t .Fatalf ("failed to call into syncRegistryLocationHandler" )
459
486
}
487
+
460
488
t .Log ("Waiting to update secret" )
461
489
select {
462
490
case <- updatedSecret :
0 commit comments