mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
Fix nil pointer error in nodevolumelimits csi logging
This commit is contained in:
parent
14549722e4
commit
5e2f12e943
@ -257,12 +257,16 @@ func (nodes NodeInfoLister) HavePodsWithRequiredAntiAffinityList() ([]*framework
|
|||||||
var _ storagelisters.CSINodeLister = CSINodeLister{}
|
var _ storagelisters.CSINodeLister = CSINodeLister{}
|
||||||
|
|
||||||
// CSINodeLister declares a storagev1.CSINode type for testing.
|
// CSINodeLister declares a storagev1.CSINode type for testing.
|
||||||
type CSINodeLister storagev1.CSINode
|
type CSINodeLister []storagev1.CSINode
|
||||||
|
|
||||||
// Get returns a fake CSINode object.
|
// Get returns a fake CSINode object.
|
||||||
func (n CSINodeLister) Get(name string) (*storagev1.CSINode, error) {
|
func (n CSINodeLister) Get(name string) (*storagev1.CSINode, error) {
|
||||||
csiNode := storagev1.CSINode(n)
|
for _, cn := range n {
|
||||||
return &csiNode, nil
|
if cn.Name == name {
|
||||||
|
return &cn, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("csiNode %q not found", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// List lists all CSINodes in the indexer.
|
// List lists all CSINodes in the indexer.
|
||||||
|
@ -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)
|
return fmt.Errorf("looking up provisioner name for volume %v: %w", vol, err)
|
||||||
}
|
}
|
||||||
if !isCSIMigrationOn(csiNode, inTreeProvisionerName) {
|
if !isCSIMigrationOn(csiNode, inTreeProvisionerName) {
|
||||||
|
csiNodeName := ""
|
||||||
|
if csiNode != nil {
|
||||||
|
csiNodeName = csiNode.Name
|
||||||
|
}
|
||||||
klog.V(5).InfoS("CSI Migration is not enabled for provisioner", "provisioner", inTreeProvisionerName,
|
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
|
return nil
|
||||||
}
|
}
|
||||||
// Do translation for the in-tree volume.
|
// Do translation for the in-tree volume.
|
||||||
|
@ -305,6 +305,16 @@ func TestCSILimits(t *testing.T) {
|
|||||||
test: "should count in-tree volumes if migration is enabled",
|
test: "should count in-tree volumes if migration is enabled",
|
||||||
wantStatus: framework.NewStatus(framework.Unschedulable, ErrReasonMaxVolumeCountExceeded),
|
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,
|
newPod: pendingVolumePod,
|
||||||
existingPods: []*v1.Pod{inTreeTwoVolPod},
|
existingPods: []*v1.Pod{inTreeTwoVolPod},
|
||||||
@ -541,8 +551,8 @@ func getFakeCSIPVLister(volumeName string, driverNames ...string) fakeframework.
|
|||||||
}
|
}
|
||||||
pvLister = append(pvLister, pv)
|
pvLister = append(pvLister, pv)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return pvLister
|
return pvLister
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -599,10 +609,11 @@ func getFakeCSIStorageClassLister(scName, provisionerName string) fakeframework.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getFakeCSINodeLister(csiNode *storagev1.CSINode) fakeframework.CSINodeLister {
|
func getFakeCSINodeLister(csiNode *storagev1.CSINode) fakeframework.CSINodeLister {
|
||||||
|
csiNodeLister := fakeframework.CSINodeLister{}
|
||||||
if csiNode != nil {
|
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) {
|
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() {
|
initCSINode := func() {
|
||||||
csiNode = &storagev1.CSINode{
|
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{
|
Spec: storagev1.CSINodeSpec{
|
||||||
Drivers: []storagev1.CSINodeDriver{},
|
Drivers: []storagev1.CSINodeDriver{},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user