Skip to content

Commit

Permalink
fix panic without PV permission (#4837) (#4840)
Browse files Browse the repository at this point in the history
Co-authored-by: csuzhangxc <csuzhangxc@gmail.com>
  • Loading branch information
ti-chi-bot and csuzhangxc committed Jan 13, 2023
1 parent 057dfdd commit c17e7b0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/manager/volumes/delegation/aws/ebs_modifier.go
Expand Up @@ -88,6 +88,11 @@ func (m *EBSModifier) Validate(spvc, dpvc *corev1.PersistentVolumeClaim, ssc, ds
}

func (m *EBSModifier) ModifyVolume(ctx context.Context, pvc *corev1.PersistentVolumeClaim, pv *corev1.PersistentVolume, sc *storagev1.StorageClass) ( /*wait*/ bool, error) {
if pv == nil {
klog.V(4).Infof("Persistent volume is nil, skip modifying PV for %s. This may be caused by no relevant permissions", pvc.Spec.VolumeName)
return false, nil
}

desired, err := m.getExpectedVolume(pvc, pv, sc)
if err != nil {
return false, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/manager/volumes/delegation/interface.go
Expand Up @@ -23,7 +23,8 @@ import (

type VolumeModifier interface {
MinWaitDuration() time.Duration
// ModifyVolume modifies the underlay volume of pvc to match the args of storageclass
// ModifyVolume modifies the underlay volume of pvc to match the args of storageclass.
// If no PV permission (e.g `-cluster-permission-pv=false`), the `pv` may be nil and will return `false, nil`.
ModifyVolume(ctx context.Context, pvc *corev1.PersistentVolumeClaim, pv *corev1.PersistentVolume, sc *storagev1.StorageClass) (bool, error)

Validate(spvc, dpvc *corev1.PersistentVolumeClaim, ssc, dsc *storagev1.StorageClass) error
Expand Down
5 changes: 5 additions & 0 deletions pkg/manager/volumes/pod_vol_modifier.go
Expand Up @@ -298,6 +298,11 @@ func getDesiredVolumeByName(vs []DesiredVolume, name v1alpha1.StorageVolumeName)
}

func (p *podVolModifier) getBoundPVFromPVC(pvc *corev1.PersistentVolumeClaim) (*corev1.PersistentVolume, error) {
if p.deps.PVLister == nil {
klog.V(4).Infof("Persistent volumes lister is unavailable, skip getting PV for %s. This may be caused by no relevant permissions", pvc.Spec.VolumeName)
return nil, nil
}

name := pvc.Spec.VolumeName

return p.deps.PVLister.Get(name)
Expand Down

0 comments on commit c17e7b0

Please sign in to comment.