Skip to content

Commit d89436e

Browse files
committed
Add support to configure MaxVolumesPerNode
Add support to configure the MaxVolumesPerNode value within the NodeGetInfo response. Value can be configured using the MAX_VOLUMES_PER_NODE environment variable Signed-off-by: Benjamin Isinger <[email protected]>
1 parent b6c6f1a commit d89436e

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

pkg/driver/nodeserver.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package driver
1313
import (
1414
"fmt"
1515
"os"
16+
"strconv"
1617

1718
"github.com/IBM/ibm-object-csi-driver/pkg/constants"
1819
"github.com/IBM/ibm-object-csi-driver/pkg/mounter"
@@ -289,8 +290,17 @@ func (ns *nodeServer) NodeGetInfo(_ context.Context, req *csi.NodeGetInfoRequest
289290
return nil, err
290291
}
291292

293+
maxVolumesPerNode := constants.DefaultVolumesPerNode
294+
if val := os.Getenv("MAX_VOLUMES_PER_NODE"); val != "" {
295+
maxVolumesPerNode, err = strconv.Atoi(val)
296+
if err != nil {
297+
return nil, fmt.Errorf("MAX_VOLUMES_PER_NODE does not contain valid number")
298+
}
299+
}
300+
292301
klog.V(3).Infof("NodeGetInfo: Node region %s", region)
293302
klog.V(3).Infof("NodeGetInfo: Node zone %s", zone)
303+
klog.V(3).Infof("NodeGetInfo: Max volumes per node %s", zone)
294304

295305
topology := &csi.Topology{
296306
Segments: map[string]string{
@@ -300,7 +310,7 @@ func (ns *nodeServer) NodeGetInfo(_ context.Context, req *csi.NodeGetInfoRequest
300310
}
301311
resp := &csi.NodeGetInfoResponse{
302312
NodeId: ns.NodeID,
303-
MaxVolumesPerNode: constants.DefaultVolumesPerNode,
313+
MaxVolumesPerNode: int64(maxVolumesPerNode),
304314
AccessibleTopology: topology,
305315
}
306316
klog.V(2).Info("NodeGetInfo: ", resp)

pkg/driver/nodeserver_test.go

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package driver
1818

1919
import (
2020
"errors"
21-
"os"
21+
"fmt"
2222
"reflect"
2323
"testing"
2424

@@ -618,6 +618,7 @@ func TestNodeGetInfo(t *testing.T) {
618618
testCases := []struct {
619619
testCaseName string
620620
driverStatsUtils utils.StatsUtils
621+
envVars map[string]string
621622
req *csi.NodeGetInfoRequest
622623
expectedResp *csi.NodeGetInfoResponse
623624
expectedErr error
@@ -630,6 +631,9 @@ func TestNodeGetInfo(t *testing.T) {
630631
return "test-region", "test-zone", nil
631632
},
632633
}),
634+
envVars: map[string]string{
635+
"KUBE_NODE_NAME": "testNode",
636+
},
633637
expectedResp: &csi.NodeGetInfoResponse{
634638
NodeId: testNodeID,
635639
MaxVolumesPerNode: constants.DefaultVolumesPerNode,
@@ -642,12 +646,53 @@ func TestNodeGetInfo(t *testing.T) {
642646
},
643647
expectedErr: nil,
644648
},
649+
{
650+
testCaseName: "Positive: Custom max volumes per node",
651+
req: &csi.NodeGetInfoRequest{},
652+
driverStatsUtils: utils.NewFakeStatsUtilsImpl(utils.FakeStatsUtilsFuncStruct{
653+
GetRegionAndZoneFn: func(nodeName string) (string, string, error) {
654+
return "test-region", "test-zone", nil
655+
},
656+
}),
657+
envVars: map[string]string{
658+
"KUBE_NODE_NAME": "testNode",
659+
"MAX_VOLUMES_PER_NODE": "4",
660+
},
661+
expectedResp: &csi.NodeGetInfoResponse{
662+
NodeId: testNodeID,
663+
MaxVolumesPerNode: 4,
664+
AccessibleTopology: &csi.Topology{
665+
Segments: map[string]string{
666+
constants.NodeRegionLabel: "test-region",
667+
constants.NodeZoneLabel: "test-zone",
668+
},
669+
},
670+
},
671+
expectedErr: nil,
672+
},
673+
{
674+
testCaseName: "Negative: invalid custom max volumes per node",
675+
req: &csi.NodeGetInfoRequest{},
676+
driverStatsUtils: utils.NewFakeStatsUtilsImpl(utils.FakeStatsUtilsFuncStruct{
677+
GetRegionAndZoneFn: func(nodeName string) (string, string, error) {
678+
return "test-region", "test-zone", nil
679+
},
680+
}),
681+
envVars: map[string]string{
682+
"KUBE_NODE_NAME": "testNode",
683+
"MAX_VOLUMES_PER_NODE": "foobar",
684+
},
685+
expectedResp: nil,
686+
expectedErr: fmt.Errorf("MAX_VOLUMES_PER_NODE does not contain valid number"),
687+
},
645688
}
646689

647690
for _, tc := range testCases {
648691
t.Log("Testcase being executed", zap.String("testcase", tc.testCaseName))
649692

650-
_ = os.Setenv("KUBE_NODE_NAME", "testNode")
693+
for k, v := range tc.envVars {
694+
t.Setenv(k, v)
695+
}
651696

652697
nodeServer := nodeServer{
653698
NodeID: testNodeID,

0 commit comments

Comments
 (0)