Skip to content

Commit

Permalink
fix(expand): check volume size first
Browse files Browse the repository at this point in the history
Check if volume size can be scheduled by the replica scheduler before
expading the pv/pvc size.

Signed-off-by: James Lu <james.lu@suse.com>
  • Loading branch information
mantissahz authored and mergify[bot] committed Apr 13, 2024
1 parent db00c80 commit 946465b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions manager/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,15 @@ func (m *VolumeManager) Expand(volumeName string, size int64) (v *longhorn.Volum

size = util.RoundUpSize(size)

if v.Spec.Size >= size {
logrus.Infof("Volume %v expansion is not allowable since current size %v >= %v", v.Name, v.Spec.Size, size)
return v, nil
}

if _, err := m.scheduler.CheckReplicasSizeExpansion(v, v.Spec.Size, size); err != nil {
return nil, err
}

kubernetesStatus := &v.Status.KubernetesStatus
if kubernetesStatus.PVCName != "" && kubernetesStatus.LastPVCRefAt == "" {
waitForPVCExpansion, size, err := m.checkAndExpandPVC(kubernetesStatus.Namespace, kubernetesStatus.PVCName, size)
Expand All @@ -483,15 +492,6 @@ func (m *VolumeManager) Expand(volumeName string, size int64) (v *longhorn.Volum
logrus.Infof("CSI plugin call to expand volume %v to size %v", v.Name, size)
}

if v.Spec.Size >= size {
logrus.Infof("Volume %v expansion is not necessary since current size %v >= %v", v.Name, v.Spec.Size, size)
return v, nil
}

if _, err := m.scheduler.CheckReplicasSizeExpansion(v, v.Spec.Size, size); err != nil {
return nil, err
}

previousSize := v.Spec.Size
v.Spec.Size = size

Expand Down

0 comments on commit 946465b

Please sign in to comment.