Fix nil pointer error in nodevolumelimits csi logging

This commit is contained in:
Sunny Song 2023-01-18 12:12:39 -08:00
parent 14549722e4
commit 5e2f12e943
3 changed files with 27 additions and 8 deletions

View File

@ -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.

View File

@ -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.

View File

@ -305,6 +305,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},
@ -541,8 +551,8 @@ func getFakeCSIPVLister(volumeName string, driverNames ...string) fakeframework.
}
pvLister = append(pvLister, pv)
}
}
return pvLister
}
@ -599,10 +609,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) {
@ -623,7 +634,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{},
},