@@ -167,13 +167,22 @@ func TestPodMemoryTarget(t *testing.T) {
167
167
}
168
168
169
169
for _ , testCase := range testCases {
170
- pod := Pod (testCase .input , "name" , "opmImage" , "utilImage" , "image" , " service-account" , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
170
+ pod := Pod (testCase .input , "name" , "opmImage" , "utilImage" , "image" , serviceAccount ( "" , " service-account") , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
171
171
if diff := cmp .Diff (pod , testCase .expected ); diff != "" {
172
172
t .Errorf ("got incorrect pod: %v" , diff )
173
173
}
174
174
}
175
175
}
176
176
177
+ func serviceAccount (namespace , name string ) * corev1.ServiceAccount {
178
+ return & corev1.ServiceAccount {
179
+ ObjectMeta : metav1.ObjectMeta {
180
+ Namespace : namespace ,
181
+ Name : name ,
182
+ },
183
+ }
184
+ }
185
+
177
186
func TestPodExtractContent (t * testing.T ) {
178
187
var testCases = []struct {
179
188
name string
@@ -362,13 +371,63 @@ func TestPodExtractContent(t *testing.T) {
362
371
}
363
372
364
373
for _ , testCase := range testCases {
365
- pod := Pod (testCase .input , "name" , "opmImage" , "utilImage" , "image" , " service-account" , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
374
+ pod := Pod (testCase .input , "name" , "opmImage" , "utilImage" , "image" , serviceAccount ( "" , " service-account") , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
366
375
if diff := cmp .Diff (pod , testCase .expected ); diff != "" {
367
376
t .Errorf ("got incorrect pod: %v" , diff )
368
377
}
369
378
}
370
379
}
371
380
381
+ func TestPodServiceAccountImagePullSecrets (t * testing.T ) {
382
+ var testCases = []struct {
383
+ name string
384
+ catalogSource * v1alpha1.CatalogSource
385
+ serviceAccount * corev1.ServiceAccount
386
+ }{
387
+ {
388
+ name : "ServiceAccount has no imagePullSecret" ,
389
+ serviceAccount : & corev1.ServiceAccount {
390
+ ObjectMeta : metav1.ObjectMeta {
391
+ Namespace : "" ,
392
+ Name : "service-account" ,
393
+ },
394
+ },
395
+ },
396
+ {
397
+ name : "ServiceAccount has one imagePullSecret" ,
398
+ serviceAccount : & corev1.ServiceAccount {
399
+ ObjectMeta : metav1.ObjectMeta {
400
+ Namespace : "" ,
401
+ Name : "service-account" ,
402
+ },
403
+ ImagePullSecrets : []corev1.LocalObjectReference {{Name : "foo" }},
404
+ },
405
+ },
406
+ }
407
+
408
+ catalogSource := & v1alpha1.CatalogSource {
409
+ ObjectMeta : metav1.ObjectMeta {
410
+ Name : "test" ,
411
+ Namespace : "testns" ,
412
+ },
413
+ Spec : v1alpha1.CatalogSourceSpec {
414
+ GrpcPodConfig : & v1alpha1.GrpcPodConfig {
415
+ ExtractContent : & v1alpha1.ExtractContentConfig {
416
+ CacheDir : "/tmp/cache" ,
417
+ CatalogDir : "/catalog" ,
418
+ },
419
+ },
420
+ },
421
+ }
422
+
423
+ for _ , testCase := range testCases {
424
+ pod := Pod (catalogSource , "name" , "opmImage" , "utilImage" , "image" , testCase .serviceAccount , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
425
+ if diff := cmp .Diff (testCase .serviceAccount .ImagePullSecrets , pod .Spec .ImagePullSecrets ); diff != "" {
426
+ t .Errorf ("got incorrect pod: %v" , diff )
427
+ }
428
+ }
429
+ }
430
+
372
431
func TestPodNodeSelector (t * testing.T ) {
373
432
catsrc := & v1alpha1.CatalogSource {
374
433
ObjectMeta : metav1.ObjectMeta {
@@ -380,7 +439,7 @@ func TestPodNodeSelector(t *testing.T) {
380
439
key := "kubernetes.io/os"
381
440
value := "linux"
382
441
383
- gotCatSrcPod := Pod (catsrc , "hello" , "utilImage" , "opmImage" , "busybox" , "" , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
442
+ gotCatSrcPod := Pod (catsrc , "hello" , "utilImage" , "opmImage" , "busybox" , serviceAccount ( "" , "service-account" ) , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
384
443
gotCatSrcPodSelector := gotCatSrcPod .Spec .NodeSelector
385
444
386
445
if gotCatSrcPodSelector [key ] != value {
@@ -428,7 +487,7 @@ func TestPullPolicy(t *testing.T) {
428
487
}
429
488
430
489
for _ , tt := range table {
431
- p := Pod (source , "catalog" , "opmImage" , "utilImage" , tt .image , "" , nil , nil , int32 (0 ), int32 (0 ), int64 (workloadUserID ))
490
+ p := Pod (source , "catalog" , "opmImage" , "utilImage" , tt .image , serviceAccount ( "" , "service-account" ) , nil , nil , int32 (0 ), int32 (0 ), int64 (workloadUserID ))
432
491
policy := p .Spec .Containers [0 ].ImagePullPolicy
433
492
if policy != tt .policy {
434
493
t .Fatalf ("expected pull policy %s for image %s" , tt .policy , tt .image )
@@ -540,7 +599,7 @@ func TestPodContainerSecurityContext(t *testing.T) {
540
599
},
541
600
}
542
601
for _ , testcase := range testcases {
543
- outputPod := Pod (testcase .inputCatsrc , "hello" , "utilImage" , "opmImage" , "busybox" , "" , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
602
+ outputPod := Pod (testcase .inputCatsrc , "hello" , "utilImage" , "opmImage" , "busybox" , serviceAccount ( "" , "service-account" ) , map [string ]string {}, map [string ]string {}, int32 (0 ), int32 (0 ), int64 (workloadUserID ))
544
603
if testcase .expectedSecurityContext != nil {
545
604
require .Equal (t , testcase .expectedSecurityContext , outputPod .Spec .SecurityContext )
546
605
}
@@ -570,7 +629,7 @@ func TestPodAvoidsConcurrentWrite(t *testing.T) {
570
629
"annotation" : "somethingelse" ,
571
630
}
572
631
573
- gotPod := Pod (catsrc , "hello" , "opmImage" , "utilImage" , "busybox" , "" , labels , annotations , int32 (0 ), int32 (0 ), int64 (workloadUserID ))
632
+ gotPod := Pod (catsrc , "hello" , "opmImage" , "utilImage" , "busybox" , serviceAccount ( "" , "service-account" ) , labels , annotations , int32 (0 ), int32 (0 ), int64 (workloadUserID ))
574
633
575
634
// check labels and annotations point to different addresses between parameters and what's in the pod
576
635
require .NotEqual (t , & labels , & gotPod .Labels )
@@ -799,7 +858,7 @@ func TestPodSchedulingOverrides(t *testing.T) {
799
858
}
800
859
801
860
for _ , testCase := range testCases {
802
- pod := Pod (testCase .catalogSource , "hello" , "opmImage" , "utilImage" , "busybox" , "" , map [string ]string {}, testCase .annotations , int32 (0 ), int32 (0 ), int64 (workloadUserID ))
861
+ pod := Pod (testCase .catalogSource , "hello" , "opmImage" , "utilImage" , "busybox" , serviceAccount ( "" , "service-account" ) , map [string ]string {}, testCase .annotations , int32 (0 ), int32 (0 ), int64 (workloadUserID ))
803
862
require .Equal (t , testCase .expectedNodeSelectors , pod .Spec .NodeSelector )
804
863
require .Equal (t , testCase .expectedPriorityClassName , pod .Spec .PriorityClassName )
805
864
require .Equal (t , testCase .expectedTolerations , pod .Spec .Tolerations )
0 commit comments