@@ -49,6 +49,7 @@ type pullerExpects struct {
49
49
shouldRecordStartedPullingTime bool
50
50
shouldRecordFinishedPullingTime bool
51
51
events []v1.Event
52
+ msg string
52
53
}
53
54
54
55
type pullerTestCase struct {
@@ -77,7 +78,7 @@ func pullerTestCases() []pullerTestCase {
77
78
[]v1.Event {
78
79
{Reason : "Pulling" },
79
80
{Reason : "Pulled" },
80
- }},
81
+ }, "" },
81
82
}},
82
83
83
84
{ // image present, don't pull
@@ -92,15 +93,15 @@ func pullerTestCases() []pullerTestCase {
92
93
{[]string {"GetImageRef" }, nil , false , false ,
93
94
[]v1.Event {
94
95
{Reason : "Pulled" },
95
- }},
96
+ }, "" },
96
97
{[]string {"GetImageRef" }, nil , false , false ,
97
98
[]v1.Event {
98
99
{Reason : "Pulled" },
99
- }},
100
+ }, "" },
100
101
{[]string {"GetImageRef" }, nil , false , false ,
101
102
[]v1.Event {
102
103
{Reason : "Pulled" },
103
- }},
104
+ }, "" },
104
105
}},
105
106
// image present, pull it
106
107
{containerImage : "present_image" ,
@@ -115,17 +116,17 @@ func pullerTestCases() []pullerTestCase {
115
116
[]v1.Event {
116
117
{Reason : "Pulling" },
117
118
{Reason : "Pulled" },
118
- }},
119
+ }, "" },
119
120
{[]string {"PullImage" , "GetImageSize" }, nil , true , true ,
120
121
[]v1.Event {
121
122
{Reason : "Pulling" },
122
123
{Reason : "Pulled" },
123
- }},
124
+ }, "" },
124
125
{[]string {"PullImage" , "GetImageSize" }, nil , true , true ,
125
126
[]v1.Event {
126
127
{Reason : "Pulling" },
127
128
{Reason : "Pulled" },
128
- }},
129
+ }, "" },
129
130
}},
130
131
// missing image, error PullNever
131
132
{containerImage : "missing_image" ,
@@ -139,15 +140,15 @@ func pullerTestCases() []pullerTestCase {
139
140
{[]string {"GetImageRef" }, ErrImageNeverPull , false , false ,
140
141
[]v1.Event {
141
142
{Reason : "ErrImageNeverPull" },
142
- }},
143
+ }, "" },
143
144
{[]string {"GetImageRef" }, ErrImageNeverPull , false , false ,
144
145
[]v1.Event {
145
146
{Reason : "ErrImageNeverPull" },
146
- }},
147
+ }, "" },
147
148
{[]string {"GetImageRef" }, ErrImageNeverPull , false , false ,
148
149
[]v1.Event {
149
150
{Reason : "ErrImageNeverPull" },
150
- }},
151
+ }, "" },
151
152
}},
152
153
// missing image, unable to inspect
153
154
{containerImage : "missing_image" ,
@@ -161,15 +162,15 @@ func pullerTestCases() []pullerTestCase {
161
162
{[]string {"GetImageRef" }, ErrImageInspect , false , false ,
162
163
[]v1.Event {
163
164
{Reason : "InspectFailed" },
164
- }},
165
+ }, "" },
165
166
{[]string {"GetImageRef" }, ErrImageInspect , false , false ,
166
167
[]v1.Event {
167
168
{Reason : "InspectFailed" },
168
- }},
169
+ }, "" },
169
170
{[]string {"GetImageRef" }, ErrImageInspect , false , false ,
170
171
[]v1.Event {
171
172
{Reason : "InspectFailed" },
172
- }},
173
+ }, "" },
173
174
}},
174
175
// missing image, unable to fetch
175
176
{containerImage : "typo_image" ,
@@ -184,29 +185,29 @@ func pullerTestCases() []pullerTestCase {
184
185
[]v1.Event {
185
186
{Reason : "Pulling" },
186
187
{Reason : "Failed" },
187
- }},
188
+ }, "" },
188
189
{[]string {"GetImageRef" , "PullImage" }, ErrImagePull , true , false ,
189
190
[]v1.Event {
190
191
{Reason : "Pulling" },
191
192
{Reason : "Failed" },
192
- }},
193
+ }, "" },
193
194
{[]string {"GetImageRef" }, ErrImagePullBackOff , false , false ,
194
195
[]v1.Event {
195
196
{Reason : "BackOff" },
196
- }},
197
+ }, "" },
197
198
{[]string {"GetImageRef" , "PullImage" }, ErrImagePull , true , false ,
198
199
[]v1.Event {
199
200
{Reason : "Pulling" },
200
201
{Reason : "Failed" },
201
- }},
202
+ }, "" },
202
203
{[]string {"GetImageRef" }, ErrImagePullBackOff , false , false ,
203
204
[]v1.Event {
204
205
{Reason : "BackOff" },
205
- }},
206
+ }, "" },
206
207
{[]string {"GetImageRef" }, ErrImagePullBackOff , false , false ,
207
208
[]v1.Event {
208
209
{Reason : "BackOff" },
209
- }},
210
+ }, "" },
210
211
}},
211
212
// image present, non-zero qps, try to pull
212
213
{containerImage : "present_image" ,
@@ -221,17 +222,17 @@ func pullerTestCases() []pullerTestCase {
221
222
[]v1.Event {
222
223
{Reason : "Pulling" },
223
224
{Reason : "Pulled" },
224
- }},
225
+ }, "" },
225
226
{[]string {"PullImage" , "GetImageSize" }, nil , true , true ,
226
227
[]v1.Event {
227
228
{Reason : "Pulling" },
228
229
{Reason : "Pulled" },
229
- }},
230
+ }, "" },
230
231
{[]string {"PullImage" , "GetImageSize" }, nil , true , true ,
231
232
[]v1.Event {
232
233
{Reason : "Pulling" },
233
234
{Reason : "Pulled" },
234
- }},
235
+ }, "" },
235
236
}},
236
237
// image present, non-zero qps, try to pull when qps exceeded
237
238
{containerImage : "present_image" ,
@@ -246,16 +247,16 @@ func pullerTestCases() []pullerTestCase {
246
247
[]v1.Event {
247
248
{Reason : "Pulling" },
248
249
{Reason : "Failed" },
249
- }},
250
+ }, "" },
250
251
{[]string (nil ), ErrImagePull , true , false ,
251
252
[]v1.Event {
252
253
{Reason : "Pulling" },
253
254
{Reason : "Failed" },
254
- }},
255
+ }, "" },
255
256
{[]string (nil ), ErrImagePullBackOff , false , false ,
256
257
[]v1.Event {
257
258
{Reason : "BackOff" },
258
- }},
259
+ }, "" },
259
260
}},
260
261
// error case if image name fails validation due to invalid reference format
261
262
{containerImage : "FAILED_IMAGE" ,
@@ -269,7 +270,7 @@ func pullerTestCases() []pullerTestCase {
269
270
{[]string (nil ), ErrInvalidImageName , false , false ,
270
271
[]v1.Event {
271
272
{Reason : "InspectFailed" },
272
- }},
273
+ }, "" },
273
274
}},
274
275
// error case if image name contains http
275
276
{containerImage : "http://url" ,
@@ -283,7 +284,7 @@ func pullerTestCases() []pullerTestCase {
283
284
{[]string (nil ), ErrInvalidImageName , false , false ,
284
285
[]v1.Event {
285
286
{Reason : "InspectFailed" },
286
- }},
287
+ }, "" },
287
288
}},
288
289
// error case if image name contains sha256
289
290
{containerImage : "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" ,
@@ -297,7 +298,39 @@ func pullerTestCases() []pullerTestCase {
297
298
{[]string (nil ), ErrInvalidImageName , false , false ,
298
299
[]v1.Event {
299
300
{Reason : "InspectFailed" },
300
- }},
301
+ }, "" },
302
+ }},
303
+ {containerImage : "typo_image" ,
304
+ testName : "image missing, SignatureValidationFailed" ,
305
+ policy : v1 .PullIfNotPresent ,
306
+ inspectErr : nil ,
307
+ pullerErr : crierrors .ErrSignatureValidationFailed ,
308
+ qps : 0.0 ,
309
+ burst : 0 ,
310
+ expected : []pullerExpects {
311
+ {[]string {"GetImageRef" , "PullImage" }, crierrors .ErrSignatureValidationFailed , true , false ,
312
+ []v1.Event {
313
+ {Reason : "Pulling" },
314
+ {Reason : "Failed" },
315
+ }, "image pull failed for typo_image because the signature validation failed" },
316
+ {[]string {"GetImageRef" , "PullImage" }, crierrors .ErrSignatureValidationFailed , true , false ,
317
+ []v1.Event {
318
+ {Reason : "Pulling" },
319
+ {Reason : "Failed" },
320
+ }, "image pull failed for typo_image because the signature validation failed" },
321
+ {[]string {"GetImageRef" }, ErrImagePullBackOff , false , false ,
322
+ []v1.Event {
323
+ {Reason : "BackOff" },
324
+ }, "Back-off pulling image \" typo_image\" : SignatureValidationFailed: image pull failed for typo_image because the signature validation failed" },
325
+ {[]string {"GetImageRef" , "PullImage" }, crierrors .ErrSignatureValidationFailed , true , false ,
326
+ []v1.Event {
327
+ {Reason : "Pulling" },
328
+ {Reason : "Failed" },
329
+ }, "image pull failed for typo_image because the signature validation failed" },
330
+ {[]string {"GetImageRef" }, ErrImagePullBackOff , false , false ,
331
+ []v1.Event {
332
+ {Reason : "BackOff" },
333
+ }, "Back-off pulling image \" typo_image\" : SignatureValidationFailed: image pull failed for typo_image because the signature validation failed" },
301
334
}},
302
335
}
303
336
}
@@ -372,11 +405,12 @@ func TestParallelPuller(t *testing.T) {
372
405
fakeRuntime .CalledFunctions = nil
373
406
fakeClock .Step (time .Second )
374
407
375
- _ , _ , err := puller .EnsureImageExists (ctx , nil , pod , container .Image , nil , nil , "" , container .ImagePullPolicy )
408
+ _ , msg , err := puller .EnsureImageExists (ctx , nil , pod , container .Image , nil , nil , "" , container .ImagePullPolicy )
376
409
fakeRuntime .AssertCalls (expected .calls )
377
410
assert .Equal (t , expected .err , err )
378
411
assert .Equal (t , expected .shouldRecordStartedPullingTime , fakePodPullingTimeRecorder .startedPullingRecorded )
379
412
assert .Equal (t , expected .shouldRecordFinishedPullingTime , fakePodPullingTimeRecorder .finishedPullingRecorded )
413
+ assert .Contains (t , msg , expected .msg )
380
414
fakePodPullingTimeRecorder .reset ()
381
415
}
382
416
})
@@ -404,11 +438,12 @@ func TestSerializedPuller(t *testing.T) {
404
438
fakeRuntime .CalledFunctions = nil
405
439
fakeClock .Step (time .Second )
406
440
407
- _ , _ , err := puller .EnsureImageExists (ctx , nil , pod , container .Image , nil , nil , "" , container .ImagePullPolicy )
441
+ _ , msg , err := puller .EnsureImageExists (ctx , nil , pod , container .Image , nil , nil , "" , container .ImagePullPolicy )
408
442
fakeRuntime .AssertCalls (expected .calls )
409
443
assert .Equal (t , expected .err , err )
410
444
assert .Equal (t , expected .shouldRecordStartedPullingTime , fakePodPullingTimeRecorder .startedPullingRecorded )
411
445
assert .Equal (t , expected .shouldRecordFinishedPullingTime , fakePodPullingTimeRecorder .finishedPullingRecorded )
446
+ assert .Contains (t , msg , expected .msg )
412
447
fakePodPullingTimeRecorder .reset ()
413
448
}
414
449
})
@@ -456,7 +491,7 @@ func TestPullAndListImageWithPodAnnotations(t *testing.T) {
456
491
inspectErr : nil ,
457
492
pullerErr : nil ,
458
493
expected : []pullerExpects {
459
- {[]string {"GetImageRef" , "PullImage" , "GetImageSize" }, nil , true , true , nil },
494
+ {[]string {"GetImageRef" , "PullImage" , "GetImageSize" }, nil , true , true , nil , "" },
460
495
}}
461
496
462
497
useSerializedEnv := true
@@ -512,7 +547,7 @@ func TestPullAndListImageWithRuntimeHandlerInImageCriAPIFeatureGate(t *testing.T
512
547
inspectErr : nil ,
513
548
pullerErr : nil ,
514
549
expected : []pullerExpects {
515
- {[]string {"GetImageRef" , "PullImage" , "GetImageSize" }, nil , true , true , nil },
550
+ {[]string {"GetImageRef" , "PullImage" , "GetImageSize" }, nil , true , true , nil , "" },
516
551
}}
517
552
518
553
useSerializedEnv := true
0 commit comments