@@ -101,10 +101,10 @@ func (r *Reconciler) reconcileVolumeSnapshots(ctx context.Context,
101101 if snapshotWithLatestError != nil {
102102 r .Recorder .Event (postgrescluster , corev1 .EventTypeWarning , "VolumeSnapshotError" ,
103103 * snapshotWithLatestError .Status .Error .Message )
104- for _ , snapshot := range snapshots . Items {
104+ for _ , snapshot := range snapshots {
105105 if snapshot .Status != nil && snapshot .Status .Error != nil &&
106106 snapshot .Status .Error .Time .Before (snapshotWithLatestError .Status .Error .Time ) {
107- err = r .deleteControlled (ctx , postgrescluster , & snapshot )
107+ err = r .deleteControlled (ctx , postgrescluster , snapshot )
108108 if err != nil {
109109 return err
110110 }
@@ -123,7 +123,7 @@ func (r *Reconciler) reconcileVolumeSnapshots(ctx context.Context,
123123 // the dedicated pvc.
124124 var snapshotForPvcUpdateIdx int
125125 snapshotFoundForPvcUpdate := false
126- for idx , snapshot := range snapshots . Items {
126+ for idx , snapshot := range snapshots {
127127 if snapshot .GetAnnotations ()[naming .PGBackRestBackupJobCompletion ] == pvcUpdateTimeStamp {
128128 snapshotForPvcUpdateIdx = idx
129129 snapshotFoundForPvcUpdate = true
@@ -132,11 +132,11 @@ func (r *Reconciler) reconcileVolumeSnapshots(ctx context.Context,
132132
133133 // If a snapshot exists for the latest backup that has been restored into the dedicated pvc
134134 // and the snapshot is Ready, delete all other snapshots.
135- if snapshotFoundForPvcUpdate && snapshots . Items [snapshotForPvcUpdateIdx ].Status .ReadyToUse != nil &&
136- * snapshots . Items [snapshotForPvcUpdateIdx ].Status .ReadyToUse {
137- for idx , snapshot := range snapshots . Items {
135+ if snapshotFoundForPvcUpdate && snapshots [snapshotForPvcUpdateIdx ].Status .ReadyToUse != nil &&
136+ * snapshots [snapshotForPvcUpdateIdx ].Status .ReadyToUse {
137+ for idx , snapshot := range snapshots {
138138 if idx != snapshotForPvcUpdateIdx {
139- err = r .deleteControlled (ctx , postgrescluster , & snapshot )
139+ err = r .deleteControlled (ctx , postgrescluster , snapshot )
140140 if err != nil {
141141 return err
142142 }
@@ -523,16 +523,16 @@ func (r *Reconciler) getLatestCompleteBackupJob(ctx context.Context,
523523// getSnapshotWithLatestError takes a VolumeSnapshotList and returns a pointer to the
524524// snapshot that has most recently had an error. If no snapshot errors exist
525525// then it returns nil.
526- func getSnapshotWithLatestError (snapshots * volumesnapshotv1.VolumeSnapshotList ) * volumesnapshotv1.VolumeSnapshot {
526+ func getSnapshotWithLatestError (snapshots [] * volumesnapshotv1.VolumeSnapshot ) * volumesnapshotv1.VolumeSnapshot {
527527 zeroTime := metav1 .NewTime (time.Time {})
528- snapshotWithLatestError := volumesnapshotv1.VolumeSnapshot {
528+ snapshotWithLatestError := & volumesnapshotv1.VolumeSnapshot {
529529 Status : & volumesnapshotv1.VolumeSnapshotStatus {
530530 Error : & volumesnapshotv1.VolumeSnapshotError {
531531 Time : & zeroTime ,
532532 },
533533 },
534534 }
535- for _ , snapshot := range snapshots . Items {
535+ for _ , snapshot := range snapshots {
536536 if snapshot .Status != nil && snapshot .Status .Error != nil &&
537537 snapshotWithLatestError .Status .Error .Time .Before (snapshot .Status .Error .Time ) {
538538 snapshotWithLatestError = snapshot
@@ -543,12 +543,12 @@ func getSnapshotWithLatestError(snapshots *volumesnapshotv1.VolumeSnapshotList)
543543 return nil
544544 }
545545
546- return & snapshotWithLatestError
546+ return snapshotWithLatestError
547547}
548548
549549// getSnapshotsForCluster gets all the VolumeSnapshots for a given postgrescluster.
550550func (r * Reconciler ) getSnapshotsForCluster (ctx context.Context , cluster * v1beta1.PostgresCluster ) (
551- * volumesnapshotv1.VolumeSnapshotList , error ) {
551+ [] * volumesnapshotv1.VolumeSnapshot , error ) {
552552
553553 selectSnapshots , err := naming .AsSelector (naming .Cluster (cluster .Name ))
554554 if err != nil {
@@ -561,18 +561,18 @@ func (r *Reconciler) getSnapshotsForCluster(ctx context.Context, cluster *v1beta
561561 client.MatchingLabelsSelector {Selector : selectSnapshots },
562562 ))
563563
564- return snapshots , err
564+ return initialize . Pointers ( snapshots . Items ... ) , err
565565}
566566
567567// getLatestReadySnapshot takes a VolumeSnapshotList and returns the latest ready VolumeSnapshot.
568- func getLatestReadySnapshot (snapshots * volumesnapshotv1.VolumeSnapshotList ) * volumesnapshotv1.VolumeSnapshot {
568+ func getLatestReadySnapshot (snapshots [] * volumesnapshotv1.VolumeSnapshot ) * volumesnapshotv1.VolumeSnapshot {
569569 zeroTime := metav1 .NewTime (time.Time {})
570- latestReadySnapshot := volumesnapshotv1.VolumeSnapshot {
570+ latestReadySnapshot := & volumesnapshotv1.VolumeSnapshot {
571571 Status : & volumesnapshotv1.VolumeSnapshotStatus {
572572 CreationTime : & zeroTime ,
573573 },
574574 }
575- for _ , snapshot := range snapshots . Items {
575+ for _ , snapshot := range snapshots {
576576 if snapshot .Status != nil && snapshot .Status .ReadyToUse != nil && * snapshot .Status .ReadyToUse &&
577577 latestReadySnapshot .Status .CreationTime .Before (snapshot .Status .CreationTime ) {
578578 latestReadySnapshot = snapshot
@@ -583,17 +583,17 @@ func getLatestReadySnapshot(snapshots *volumesnapshotv1.VolumeSnapshotList) *vol
583583 return nil
584584 }
585585
586- return & latestReadySnapshot
586+ return latestReadySnapshot
587587}
588588
589589// deleteSnapshots takes a postgrescluster and a snapshot list and deletes all snapshots
590590// in the list that are controlled by the provided postgrescluster.
591591func (r * Reconciler ) deleteSnapshots (ctx context.Context ,
592- postgrescluster * v1beta1.PostgresCluster , snapshots * volumesnapshotv1.VolumeSnapshotList ) error {
592+ postgrescluster * v1beta1.PostgresCluster , snapshots [] * volumesnapshotv1.VolumeSnapshot ) error {
593593
594- for i := range snapshots . Items {
594+ for i := range snapshots {
595595 err := errors .WithStack (client .IgnoreNotFound (
596- r .deleteControlled (ctx , postgrescluster , & snapshots . Items [i ])))
596+ r .deleteControlled (ctx , postgrescluster , snapshots [i ])))
597597 if err != nil {
598598 return err
599599 }
0 commit comments