Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
correct the way to update PVC (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
erdrix authored Jun 8, 2021
1 parent 7bc712f commit 82df9b6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/resources/nifi/nifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,16 @@ func (r *Reconciler) reconcileNifiPVC(log logr.Logger, desiredPVC *corev1.Persis
if err := patch.DefaultAnnotator.SetLastAppliedAnnotation(desiredPVC); err != nil {
return errors.WrapIf(err, "could not apply last state to annotation")
}
desiredPVC = currentPVC

if isDesiredStorageValueInvalid(desiredPVC, currentPVC) {
return errorfactory.New(errorfactory.InternalError{}, errors.New("could not modify pvc size"),
"one can not reduce the size of a PVC", "kind", desiredType)
}
resReq := desiredPVC.Spec.Resources.Requests
labels := desiredPVC.Labels
desiredPVC = currentPVC.DeepCopy()
desiredPVC.Spec.Resources.Requests = resReq
desiredPVC.Labels = labels

if err := r.Client.Update(context.TODO(), desiredPVC); err != nil {
return errorfactory.New(errorfactory.APIFailure{}, err, "updating resource failed", "kind", desiredType)
Expand All @@ -506,6 +515,10 @@ func (r *Reconciler) reconcileNifiPVC(log logr.Logger, desiredPVC *corev1.Persis
return nil
}

func isDesiredStorageValueInvalid(desired, current *corev1.PersistentVolumeClaim) bool {
return desired.Spec.Resources.Requests.Storage().Value() < current.Spec.Resources.Requests.Storage().Value()
}

func (r *Reconciler) reconcileNifiPod(log logr.Logger, desiredPod *corev1.Pod) error {
currentPod := desiredPod.DeepCopy()
desiredType := reflect.TypeOf(desiredPod)
Expand Down

0 comments on commit 82df9b6

Please sign in to comment.