Skip to content

Commit

Permalink
Fix nil pointer error in nodevolumelimits csi logging
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylovestiramisu committed Jan 26, 2023
1 parent 429b61f commit aa95077
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
10 changes: 7 additions & 3 deletions pkg/scheduler/framework/fake/listers.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,16 @@ func (nodes NodeInfoLister) HavePodsWithRequiredAntiAffinityList() ([]*framework
var _ storagelisters.CSINodeLister = CSINodeLister{}

// CSINodeLister declares a storagev1.CSINode type for testing.
type CSINodeLister storagev1.CSINode
type CSINodeLister []storagev1.CSINode

// Get returns a fake CSINode object.
func (n CSINodeLister) Get(name string) (*storagev1.CSINode, error) {
csiNode := storagev1.CSINode(n)
return &csiNode, nil
for _, cn := range n {
if cn.Name == name {
return &cn, nil
}
}
return nil, fmt.Errorf("csiNode %q not found", name)
}

// List lists all CSINodes in the indexer.
Expand Down
6 changes: 5 additions & 1 deletion pkg/scheduler/framework/plugins/nodevolumelimits/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ func (pl *CSILimits) checkAttachableInlineVolume(vol v1.Volume, csiNode *storage
return fmt.Errorf("looking up provisioner name for volume %v: %w", vol, err)
}
if !isCSIMigrationOn(csiNode, inTreeProvisionerName) {
csiNodeName := ""
if csiNode != nil {
csiNodeName = csiNode.Name
}
klog.V(5).InfoS("CSI Migration is not enabled for provisioner", "provisioner", inTreeProvisionerName,
"pod", klog.KObj(pod), "csiNode", csiNode.Name)
"pod", klog.KObj(pod), "csiNode", csiNodeName)
return nil
}
// Do translation for the in-tree volume.
Expand Down
19 changes: 15 additions & 4 deletions pkg/scheduler/framework/plugins/nodevolumelimits/csi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ func TestCSILimits(t *testing.T) {
test: "should count in-tree volumes if migration is enabled",
wantStatus: framework.NewStatus(framework.Unschedulable, ErrReasonMaxVolumeCountExceeded),
},
{
newPod: inTreeInlineVolPod,
existingPods: []*v1.Pod{inTreeTwoVolPod},
filterName: "csi",
maxVols: 2,
driverNames: []string{csilibplugins.AWSEBSInTreePluginName, ebsCSIDriverName},
migrationEnabled: true,
limitSource: "node",
test: "nil csi node",
},
{
newPod: pendingVolumePod,
existingPods: []*v1.Pod{inTreeTwoVolPod},
Expand Down Expand Up @@ -540,8 +550,8 @@ func getFakeCSIPVLister(volumeName string, driverNames ...string) fakeframework.
}
pvLister = append(pvLister, pv)
}

}

return pvLister
}

Expand Down Expand Up @@ -598,10 +608,11 @@ func getFakeCSIStorageClassLister(scName, provisionerName string) fakeframework.
}

func getFakeCSINodeLister(csiNode *storagev1.CSINode) fakeframework.CSINodeLister {
csiNodeLister := fakeframework.CSINodeLister{}
if csiNode != nil {
return fakeframework.CSINodeLister(*csiNode)
csiNodeLister = append(csiNodeLister, *csiNode.DeepCopy())
}
return fakeframework.CSINodeLister{}
return csiNodeLister
}

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

initCSINode := func() {
csiNode = &storagev1.CSINode{
ObjectMeta: metav1.ObjectMeta{Name: "csi-node-for-max-pd-test-1"},
ObjectMeta: metav1.ObjectMeta{Name: "node-for-max-pd-test-1"},
Spec: storagev1.CSINodeSpec{
Drivers: []storagev1.CSINodeDriver{},
},
Expand Down

0 comments on commit aa95077

Please sign in to comment.