Skip to content

Commit aa95077

Browse files
Fix nil pointer error in nodevolumelimits csi logging
1 parent 429b61f commit aa95077

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

pkg/scheduler/framework/fake/listers.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,16 @@ func (nodes NodeInfoLister) HavePodsWithRequiredAntiAffinityList() ([]*framework
257257
var _ storagelisters.CSINodeLister = CSINodeLister{}
258258

259259
// CSINodeLister declares a storagev1.CSINode type for testing.
260-
type CSINodeLister storagev1.CSINode
260+
type CSINodeLister []storagev1.CSINode
261261

262262
// Get returns a fake CSINode object.
263263
func (n CSINodeLister) Get(name string) (*storagev1.CSINode, error) {
264-
csiNode := storagev1.CSINode(n)
265-
return &csiNode, nil
264+
for _, cn := range n {
265+
if cn.Name == name {
266+
return &cn, nil
267+
}
268+
}
269+
return nil, fmt.Errorf("csiNode %q not found", name)
266270
}
267271

268272
// List lists all CSINodes in the indexer.

pkg/scheduler/framework/plugins/nodevolumelimits/csi.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,12 @@ func (pl *CSILimits) checkAttachableInlineVolume(vol v1.Volume, csiNode *storage
231231
return fmt.Errorf("looking up provisioner name for volume %v: %w", vol, err)
232232
}
233233
if !isCSIMigrationOn(csiNode, inTreeProvisionerName) {
234+
csiNodeName := ""
235+
if csiNode != nil {
236+
csiNodeName = csiNode.Name
237+
}
234238
klog.V(5).InfoS("CSI Migration is not enabled for provisioner", "provisioner", inTreeProvisionerName,
235-
"pod", klog.KObj(pod), "csiNode", csiNode.Name)
239+
"pod", klog.KObj(pod), "csiNode", csiNodeName)
236240
return nil
237241
}
238242
// Do translation for the in-tree volume.

pkg/scheduler/framework/plugins/nodevolumelimits/csi_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ func TestCSILimits(t *testing.T) {
304304
test: "should count in-tree volumes if migration is enabled",
305305
wantStatus: framework.NewStatus(framework.Unschedulable, ErrReasonMaxVolumeCountExceeded),
306306
},
307+
{
308+
newPod: inTreeInlineVolPod,
309+
existingPods: []*v1.Pod{inTreeTwoVolPod},
310+
filterName: "csi",
311+
maxVols: 2,
312+
driverNames: []string{csilibplugins.AWSEBSInTreePluginName, ebsCSIDriverName},
313+
migrationEnabled: true,
314+
limitSource: "node",
315+
test: "nil csi node",
316+
},
307317
{
308318
newPod: pendingVolumePod,
309319
existingPods: []*v1.Pod{inTreeTwoVolPod},
@@ -540,8 +550,8 @@ func getFakeCSIPVLister(volumeName string, driverNames ...string) fakeframework.
540550
}
541551
pvLister = append(pvLister, pv)
542552
}
543-
544553
}
554+
545555
return pvLister
546556
}
547557

@@ -598,10 +608,11 @@ func getFakeCSIStorageClassLister(scName, provisionerName string) fakeframework.
598608
}
599609

600610
func getFakeCSINodeLister(csiNode *storagev1.CSINode) fakeframework.CSINodeLister {
611+
csiNodeLister := fakeframework.CSINodeLister{}
601612
if csiNode != nil {
602-
return fakeframework.CSINodeLister(*csiNode)
613+
csiNodeLister = append(csiNodeLister, *csiNode.DeepCopy())
603614
}
604-
return fakeframework.CSINodeLister{}
615+
return csiNodeLister
605616
}
606617

607618
func getNodeWithPodAndVolumeLimits(limitSource string, pods []*v1.Pod, limit int64, driverNames ...string) (*framework.NodeInfo, *storagev1.CSINode) {
@@ -622,7 +633,7 @@ func getNodeWithPodAndVolumeLimits(limitSource string, pods []*v1.Pod, limit int
622633

623634
initCSINode := func() {
624635
csiNode = &storagev1.CSINode{
625-
ObjectMeta: metav1.ObjectMeta{Name: "csi-node-for-max-pd-test-1"},
636+
ObjectMeta: metav1.ObjectMeta{Name: "node-for-max-pd-test-1"},
626637
Spec: storagev1.CSINodeSpec{
627638
Drivers: []storagev1.CSINodeDriver{},
628639
},

0 commit comments

Comments
 (0)