Skip to content

Commit fbae1f7

Browse files
committedFeb 13, 2025·
Fix modifycontroller panic for non-csi volumes
1 parent 20072c0 commit fbae1f7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed
 

‎pkg/modifycontroller/controller.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,16 @@ func (ctrl *modifyController) syncPVC(key string) error {
268268
}
269269

270270
// Only trigger modify volume if the following conditions are met
271-
// 1. Non-empty vac name
272-
// 2. PVC is in Bound state
273-
// 3. PV CSI driver name matches local driver
271+
// 1. PV provisioned by CSI driver AND driver name matches local driver
272+
// 2. Non-empty vac name
273+
// 3. PVC is in Bound state
274+
if pv.Spec.CSI == nil || pv.Spec.CSI.Driver != ctrl.name {
275+
klog.V(7).InfoS("Skipping PV provisioned by different driver", "PV", klog.KObj(pv))
276+
return nil
277+
}
278+
274279
vacName := pvc.Spec.VolumeAttributesClassName
275-
if vacName != nil && *vacName != "" && pvc.Status.Phase == v1.ClaimBound && pv.Spec.CSI.Driver == ctrl.name {
280+
if vacName != nil && *vacName != "" && pvc.Status.Phase == v1.ClaimBound {
276281
_, _, err, _ := ctrl.modify(pvc, pv)
277282
if err != nil {
278283
return err

‎pkg/modifycontroller/controller_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/kubernetes-csi/external-resizer/pkg/util"
88
"google.golang.org/grpc/codes"
99
"google.golang.org/grpc/status"
10+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/client-go/tools/cache"
1112
"testing"
1213
"time"
@@ -156,6 +157,25 @@ func TestSyncPVC(t *testing.T) {
156157
pvcWithUncreatedPV := createTestPVC(pvcName, targetVac /*vacName*/, testVac /*curVacName*/, testVac /*targetVacName*/)
157158
pvcWithUncreatedPV.Spec.VolumeName = ""
158159

160+
nonCSIPVC := &v1.PersistentVolumeClaim{
161+
ObjectMeta: metav1.ObjectMeta{Name: pvcName, Namespace: pvcNamespace},
162+
Spec: v1.PersistentVolumeClaimSpec{
163+
VolumeAttributesClassName: &targetVac,
164+
VolumeName: pvName,
165+
},
166+
Status: v1.PersistentVolumeClaimStatus{
167+
Phase: v1.ClaimBound,
168+
},
169+
}
170+
nonCSIPV := &v1.PersistentVolume{
171+
ObjectMeta: metav1.ObjectMeta{
172+
Name: pvName,
173+
},
174+
Spec: v1.PersistentVolumeSpec{
175+
VolumeAttributesClassName: nil,
176+
},
177+
}
178+
159179
tests := []struct {
160180
name string
161181
pvc *v1.PersistentVolumeClaim
@@ -192,6 +212,12 @@ func TestSyncPVC(t *testing.T) {
192212
pv: basePV,
193213
callCSIModify: false,
194214
},
215+
{
216+
name: "Should NOT modify if PV wasn't provisioned by CSI driver",
217+
pvc: nonCSIPVC,
218+
pv: nonCSIPV,
219+
callCSIModify: false,
220+
},
195221
}
196222

197223
for _, test := range tests {

0 commit comments

Comments
 (0)
Please sign in to comment.