Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic without PV permission #4837

Merged
merged 2 commits into from Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment in the VolumeModifier interface to note the pv may be nil and the reason.

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