Skip to content

Commit

Permalink
fix(volume): skip delegated modifier if sc is not changed
Browse files Browse the repository at this point in the history
  • Loading branch information
liubog2008 authored and ti-chi-bot committed Jun 20, 2023
1 parent c110753 commit 7a3a5e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
14 changes: 8 additions & 6 deletions pkg/manager/volumes/phase.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (p *podVolModifier) getVolumePhase(vol *ActualVolume) VolumePhase {
return VolumePhaseModified
}

if p.waitForNextTime(vol.PVC, vol.Desired.StorageClass) {
if p.waitForNextTime(vol.PVC, vol.StorageClass, vol.Desired.StorageClass) {
return VolumePhasePending
}

Expand Down Expand Up @@ -120,18 +120,20 @@ func (p *podVolModifier) validate(vol *ActualVolume) error {
return fmt.Errorf("volume expansion is not supported by storageclass %s", vol.StorageClass.Name)
}
}
m := p.getVolumeModifier(vol.Desired.StorageClass)

m := p.getVolumeModifier(vol.StorageClass, vol.Desired.StorageClass)
if m == nil {
return nil
}
desiredPVC := vol.PVC.DeepCopy()
desiredPVC.Spec.Resources.Requests[corev1.ResourceStorage] = desired

// if no pv permission but have sc permission: cannot change sc
if isStorageClassChanged(vol.GetStorageClassName(), vol.Desired.GetStorageClassName()) && vol.PV == nil {
return fmt.Errorf("cannot change storage class (%s to %s), because there is no permission to get persistent volume", vol.GetStorageClassName(), vol.Desired.GetStorageClassName())
}

desiredPVC := vol.PVC.DeepCopy()
desiredPVC.Spec.Resources.Requests[corev1.ResourceStorage] = desired

return m.Validate(vol.PVC, desiredPVC, vol.StorageClass, vol.Desired.StorageClass)
}

Expand All @@ -142,7 +144,7 @@ func isPVCRevisionChanged(pvc *corev1.PersistentVolumeClaim) bool {
return specRevision != statusRevision
}

func (p *podVolModifier) waitForNextTime(pvc *corev1.PersistentVolumeClaim, sc *storagev1.StorageClass) bool {
func (p *podVolModifier) waitForNextTime(pvc *corev1.PersistentVolumeClaim, actualSc, desciredSc *storagev1.StorageClass) bool {
str, ok := pvc.Annotations[annoKeyPVCLastTransitionTimestamp]
if !ok {
return false
Expand All @@ -153,7 +155,7 @@ func (p *podVolModifier) waitForNextTime(pvc *corev1.PersistentVolumeClaim, sc *
}
d := time.Since(timestamp)

m := p.getVolumeModifier(sc)
m := p.getVolumeModifier(actualSc, desciredSc)

waitDur := defaultModifyWaitingDuration
if m != nil {
Expand Down
13 changes: 9 additions & 4 deletions pkg/manager/volumes/pod_vol_modifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func (p *podVolModifier) modifyPVCAnnoStatus(ctx context.Context, vol *ActualVol
}

func (p *podVolModifier) modifyVolume(ctx context.Context, vol *ActualVolume) (bool, error) {
m := p.getVolumeModifier(vol.Desired.StorageClass)
m := p.getVolumeModifier(vol.StorageClass, vol.Desired.StorageClass)
if m == nil {
// skip modifying volume by delegation.VolumeModifier
return false, nil
Expand All @@ -521,11 +521,16 @@ func (p *podVolModifier) modifyVolume(ctx context.Context, vol *ActualVolume) (b
return m.ModifyVolume(ctx, pvc, vol.PV, vol.Desired.StorageClass)
}

func (p *podVolModifier) getVolumeModifier(sc *storagev1.StorageClass) delegation.VolumeModifier {
if sc == nil {
func (p *podVolModifier) getVolumeModifier(actualSc, desiredSc *storagev1.StorageClass) delegation.VolumeModifier {
if actualSc == nil || desiredSc == nil {
return nil
}
return p.modifiers[sc.Provisioner]
// sc is not changed
if actualSc.Name == desiredSc.Name {
return nil
}

return p.modifiers[desiredSc.Provisioner]
}

func isLeaderEvictedOrTimeout(tc *v1alpha1.TidbCluster, pod *corev1.Pod) bool {
Expand Down

0 comments on commit 7a3a5e7

Please sign in to comment.