Skip to content

Commit

Permalink
Fix bug that aborted correct resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
glrf committed Jul 19, 2021
1 parent c0c498f commit 39cba17
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions controllers/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,6 @@ import (
// of the original PVC. This function might not run through successfully in a single run but may return an `errInProgress`, signifying
// that the caller needs to retry later.
func (r *StatefulSetReconciler) backupPVC(ctx context.Context, pi pvcInfo) error {
// Check if the original PVC still exists. If not there is a problem.
original := corev1.PersistentVolumeClaim{}
if err := r.Get(ctx, client.ObjectKey{Name: pi.Name, Namespace: pi.Namespace}, &original); err != nil {
if apierrors.IsNotFound(err) {
// If its not present we are in an inconsitent state
return newErrCritical("original pvc missing while trying to back it up")
}
return err
}

// Create the backupPVC with the correct size or return it if it already exists.
backup, err := r.getOrCreateBackup(ctx, pi)
if err != nil {
Expand All @@ -34,6 +24,15 @@ func (r *StatefulSetReconciler) backupPVC(ctx context.Context, pi pvcInfo) error
// We ran successfully before
return nil
}
// Check if the original PVC still exists. If not there is a problem.
original := corev1.PersistentVolumeClaim{}
if err := r.Get(ctx, client.ObjectKey{Name: pi.Name, Namespace: pi.Namespace}, &original); err != nil {
if apierrors.IsNotFound(err) {
// If its not present we are in an inconsitent state
return newErrCritical("original pvc missing while trying to back it up")
}
return err
}
q := backup.Spec.Resources.Requests[corev1.ResourceStorage] // Necessary because pointer receiver
if q.Cmp(original.Spec.Resources.Requests[corev1.ResourceStorage]) < 0 { // Returns -1 if q < size of original
// That is not the correct PVC, but some other PVC someone else created.
Expand Down

0 comments on commit 39cba17

Please sign in to comment.