Skip to content

Commit 66883b9

Browse files
committed
Pass slices of *batchv1.Job rather than *batchv1.JobList
1 parent c8da193 commit 66883b9

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

internal/controller/postgrescluster/volumes.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ func (r *Reconciler) reconcileDirMoveJobs(ctx context.Context,
354354
if cluster.Spec.DataSource != nil &&
355355
cluster.Spec.DataSource.Volumes != nil {
356356

357-
moveJobs := &batchv1.JobList{}
358-
if err := r.Client.List(ctx, moveJobs, &client.ListOptions{
357+
var list batchv1.JobList
358+
if err := r.Client.List(ctx, &list, &client.ListOptions{
359359
Namespace: cluster.Namespace,
360360
LabelSelector: naming.DirectoryMoveJobLabels(cluster.Name).AsSelector(),
361361
}); err != nil {
@@ -364,6 +364,7 @@ func (r *Reconciler) reconcileDirMoveJobs(ctx context.Context,
364364

365365
var err error
366366
var pgDataReturn, pgWALReturn, repoReturn bool
367+
var moveJobs = initialize.Pointers(list.Items...)
367368

368369
if cluster.Spec.DataSource.Volumes.PGDataVolume != nil &&
369370
cluster.Spec.DataSource.Volumes.PGDataVolume.
@@ -405,19 +406,19 @@ func (r *Reconciler) reconcileDirMoveJobs(ctx context.Context,
405406
// main control loop should continue or return early to allow time for the job
406407
// to complete.
407408
func (r *Reconciler) reconcileMovePGDataDir(ctx context.Context,
408-
cluster *v1beta1.PostgresCluster, moveJobs *batchv1.JobList) (bool, error) {
409+
cluster *v1beta1.PostgresCluster, moveJobs []*batchv1.Job) (bool, error) {
409410

410411
moveDirJob := &batchv1.Job{}
411412
moveDirJob.ObjectMeta = naming.MovePGDataDirJob(cluster)
412413

413414
// check for an existing Job
414-
for i := range moveJobs.Items {
415-
if moveJobs.Items[i].Name == moveDirJob.Name {
416-
if jobCompleted(&moveJobs.Items[i]) {
415+
for i := range moveJobs {
416+
if moveJobs[i].Name == moveDirJob.Name {
417+
if jobCompleted(moveJobs[i]) {
417418
// if the Job is completed, return as this only needs to run once
418419
return false, nil
419420
}
420-
if !jobFailed(&moveJobs.Items[i]) {
421+
if !jobFailed(moveJobs[i]) {
421422
// if the Job otherwise exists and has not failed, return and
422423
// give the Job time to finish
423424
return true, nil
@@ -530,19 +531,19 @@ func (r *Reconciler) reconcileMovePGDataDir(ctx context.Context,
530531
// main control loop should continue or return early to allow time for the job
531532
// to complete.
532533
func (r *Reconciler) reconcileMoveWALDir(ctx context.Context,
533-
cluster *v1beta1.PostgresCluster, moveJobs *batchv1.JobList) (bool, error) {
534+
cluster *v1beta1.PostgresCluster, moveJobs []*batchv1.Job) (bool, error) {
534535

535536
moveDirJob := &batchv1.Job{}
536537
moveDirJob.ObjectMeta = naming.MovePGWALDirJob(cluster)
537538

538539
// check for an existing Job
539-
for i := range moveJobs.Items {
540-
if moveJobs.Items[i].Name == moveDirJob.Name {
541-
if jobCompleted(&moveJobs.Items[i]) {
540+
for i := range moveJobs {
541+
if moveJobs[i].Name == moveDirJob.Name {
542+
if jobCompleted(moveJobs[i]) {
542543
// if the Job is completed, return as this only needs to run once
543544
return false, nil
544545
}
545-
if !jobFailed(&moveJobs.Items[i]) {
546+
if !jobFailed(moveJobs[i]) {
546547
// if the Job otherwise exists and has not failed, return and
547548
// give the Job time to finish
548549
return true, nil
@@ -649,19 +650,19 @@ func (r *Reconciler) reconcileMoveWALDir(ctx context.Context,
649650
// indicating whether the main control loop should continue or return early
650651
// to allow time for the job to complete.
651652
func (r *Reconciler) reconcileMoveRepoDir(ctx context.Context,
652-
cluster *v1beta1.PostgresCluster, moveJobs *batchv1.JobList) (bool, error) {
653+
cluster *v1beta1.PostgresCluster, moveJobs []*batchv1.Job) (bool, error) {
653654

654655
moveDirJob := &batchv1.Job{}
655656
moveDirJob.ObjectMeta = naming.MovePGBackRestRepoDirJob(cluster)
656657

657658
// check for an existing Job
658-
for i := range moveJobs.Items {
659-
if moveJobs.Items[i].Name == moveDirJob.Name {
660-
if jobCompleted(&moveJobs.Items[i]) {
659+
for i := range moveJobs {
660+
if moveJobs[i].Name == moveDirJob.Name {
661+
if jobCompleted(moveJobs[i]) {
661662
// if the Job is completed, return as this only needs to run once
662663
return false, nil
663664
}
664-
if !jobFailed(&moveJobs.Items[i]) {
665+
if !jobFailed(moveJobs[i]) {
665666
// if the Job otherwise exists and has not failed, return and
666667
// give the Job time to finish
667668
return true, nil

0 commit comments

Comments
 (0)