Skip to content

Commit c05bd2f

Browse files
authored
fix: Run migrations with service accounts (#325)
* Run migrations with service accounts Signed-off-by: Jason Parraga <sovietaced@gmail.com> * update unit tests Signed-off-by: Jason Parraga <sovietaced@gmail.com> --------- Signed-off-by: Jason Parraga <sovietaced@gmail.com>
1 parent e3bcf44 commit c05bd2f

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

internal/controller/install/lookout_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func generateLookoutInstallComponents(lookout *installv1alpha1.Lookout, scheme *
237237
}
238238
}
239239

240-
job, err := createLookoutMigrationJob(lookout)
240+
job, err := createLookoutMigrationJob(lookout, serviceAccountName)
241241
if err != nil {
242242
return nil, err
243243
}
@@ -440,7 +440,7 @@ func createLookoutIngressHttp(lookout *installv1alpha1.Lookout) (*networking.Ing
440440
}
441441

442442
// createLookoutMigrationJob returns a batch Job or an error if the app config is not correct
443-
func createLookoutMigrationJob(lookout *installv1alpha1.Lookout) (*batchv1.Job, error) {
443+
func createLookoutMigrationJob(lookout *installv1alpha1.Lookout, serviceAccountName string) (*batchv1.Job, error) {
444444
runAsUser := int64(1000)
445445
runAsGroup := int64(2000)
446446
var terminationGracePeriodSeconds int64
@@ -483,6 +483,7 @@ func createLookoutMigrationJob(lookout *installv1alpha1.Lookout) (*batchv1.Job,
483483
Labels: AllLabels(lookout.Name, lookout.Labels),
484484
},
485485
Spec: corev1.PodSpec{
486+
ServiceAccountName: serviceAccountName,
486487
RestartPolicy: "Never",
487488
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
488489
SecurityContext: &corev1.PodSecurityContext{

internal/controller/install/lookout_controller_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ func Test_createLookoutMigrationJob(t *testing.T) {
491491
assert.Equal(t, "postgres3000", job.Spec.Template.Spec.InitContainers[0].Env[0].Value)
492492
assert.Equal(t, "PGPORT", job.Spec.Template.Spec.InitContainers[0].Env[1].Name)
493493
assert.Equal(t, "4000", job.Spec.Template.Spec.InitContainers[0].Env[1].Value)
494+
assert.Equal(t, "sa", job.Spec.Template.Spec.ServiceAccountName)
494495
},
495496
wantErr: false,
496497
},
@@ -508,6 +509,7 @@ func Test_createLookoutMigrationJob(t *testing.T) {
508509
assert.Equal(t, "", job.Spec.Template.Spec.InitContainers[0].Env[0].Value)
509510
assert.Equal(t, "PGPORT", job.Spec.Template.Spec.InitContainers[0].Env[1].Name)
510511
assert.Equal(t, "", job.Spec.Template.Spec.InitContainers[0].Env[1].Value)
512+
assert.Equal(t, "sa", job.Spec.Template.Spec.ServiceAccountName)
511513
},
512514
wantErr: false,
513515
},
@@ -532,7 +534,7 @@ func Test_createLookoutMigrationJob(t *testing.T) {
532534
if tt.modifyInput != nil {
533535
tt.modifyInput(&cr)
534536
}
535-
rslt, err := createLookoutMigrationJob(&cr)
537+
rslt, err := createLookoutMigrationJob(&cr, "sa")
536538

537539
if tt.wantErr {
538540
assert.Error(t, err)

internal/controller/install/scheduler_controller.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ func generateSchedulerInstallComponents(scheduler *installv1alpha1.Scheduler, sc
231231
}
232232
}
233233

234-
job, err := createSchedulerMigrationJob(scheduler)
234+
job, err := createSchedulerMigrationJob(scheduler, serviceAccountName)
235235
if err != nil {
236236
return nil, err
237237
}
@@ -431,7 +431,7 @@ func createSchedulerIngressGrpc(scheduler *installv1alpha1.Scheduler) (*networki
431431
}
432432

433433
// createSchedulerMigrationJob returns a batch Job or an error if the app config is not correct
434-
func createSchedulerMigrationJob(scheduler *installv1alpha1.Scheduler) (*batchv1.Job, error) {
434+
func createSchedulerMigrationJob(scheduler *installv1alpha1.Scheduler, serviceAccountName string) (*batchv1.Job, error) {
435435
runAsUser := int64(1000)
436436
runAsGroup := int64(2000)
437437
var terminationGracePeriodSeconds int64
@@ -474,6 +474,7 @@ func createSchedulerMigrationJob(scheduler *installv1alpha1.Scheduler) (*batchv1
474474
Labels: AllLabels(scheduler.Name, scheduler.Labels),
475475
},
476476
Spec: corev1.PodSpec{
477+
ServiceAccountName: serviceAccountName,
477478
RestartPolicy: "Never",
478479
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
479480
SecurityContext: &corev1.PodSecurityContext{

internal/controller/install/scheduler_controller_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,7 @@ func Test_createSchedulerMigrationJob(t *testing.T) {
713713
assert.Equal(t, "postgres3000", job.Spec.Template.Spec.InitContainers[0].Env[0].Value)
714714
assert.Equal(t, "PGPORT", job.Spec.Template.Spec.InitContainers[0].Env[1].Name)
715715
assert.Equal(t, "4000", job.Spec.Template.Spec.InitContainers[0].Env[1].Value)
716+
assert.Equal(t, "sa", job.Spec.Template.Spec.ServiceAccountName)
716717
},
717718
wantErr: false,
718719
},
@@ -730,6 +731,7 @@ func Test_createSchedulerMigrationJob(t *testing.T) {
730731
assert.Equal(t, "", job.Spec.Template.Spec.InitContainers[0].Env[0].Value)
731732
assert.Equal(t, "PGPORT", job.Spec.Template.Spec.InitContainers[0].Env[1].Name)
732733
assert.Equal(t, "", job.Spec.Template.Spec.InitContainers[0].Env[1].Value)
734+
assert.Equal(t, "sa", job.Spec.Template.Spec.ServiceAccountName)
733735
},
734736
wantErr: false,
735737
},
@@ -754,7 +756,7 @@ func Test_createSchedulerMigrationJob(t *testing.T) {
754756
if tt.modifyInput != nil {
755757
tt.modifyInput(&cr)
756758
}
757-
rslt, err := createSchedulerMigrationJob(&cr)
759+
rslt, err := createSchedulerMigrationJob(&cr, "sa")
758760

759761
if tt.wantErr {
760762
assert.Error(t, err)

0 commit comments

Comments
 (0)