Skip to content

Add support to configure MaxVolumesPerNode #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/driver/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package driver
import (
"fmt"
"os"
"strconv"

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

maxVolumesPerNode := constants.DefaultVolumesPerNode
if val := os.Getenv("MAX_VOLUMES_PER_NODE"); val != "" {
maxVolumesPerNode, err = strconv.Atoi(val)
if err != nil {
return nil, fmt.Errorf("MAX_VOLUMES_PER_NODE does not contain valid number")
}
}

klog.V(3).Infof("NodeGetInfo: Node region %s", region)
klog.V(3).Infof("NodeGetInfo: Node zone %s", zone)
klog.V(3).Infof("NodeGetInfo: Max volumes per node %s", zone)

topology := &csi.Topology{
Segments: map[string]string{
Expand All @@ -300,7 +310,7 @@ func (ns *nodeServer) NodeGetInfo(_ context.Context, req *csi.NodeGetInfoRequest
}
resp := &csi.NodeGetInfoResponse{
NodeId: ns.NodeID,
MaxVolumesPerNode: constants.DefaultVolumesPerNode,
MaxVolumesPerNode: int64(maxVolumesPerNode),
AccessibleTopology: topology,
}
klog.V(2).Info("NodeGetInfo: ", resp)
Expand Down
49 changes: 47 additions & 2 deletions pkg/driver/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package driver

import (
"errors"
"os"
"fmt"
"reflect"
"testing"

Expand Down Expand Up @@ -618,6 +618,7 @@ func TestNodeGetInfo(t *testing.T) {
testCases := []struct {
testCaseName string
driverStatsUtils utils.StatsUtils
envVars map[string]string
req *csi.NodeGetInfoRequest
expectedResp *csi.NodeGetInfoResponse
expectedErr error
Expand All @@ -630,6 +631,9 @@ func TestNodeGetInfo(t *testing.T) {
return "test-region", "test-zone", nil
},
}),
envVars: map[string]string{
"KUBE_NODE_NAME": "testNode",
},
expectedResp: &csi.NodeGetInfoResponse{
NodeId: testNodeID,
MaxVolumesPerNode: constants.DefaultVolumesPerNode,
Expand All @@ -642,12 +646,53 @@ func TestNodeGetInfo(t *testing.T) {
},
expectedErr: nil,
},
{
testCaseName: "Positive: Custom max volumes per node",
req: &csi.NodeGetInfoRequest{},
driverStatsUtils: utils.NewFakeStatsUtilsImpl(utils.FakeStatsUtilsFuncStruct{
GetRegionAndZoneFn: func(nodeName string) (string, string, error) {
return "test-region", "test-zone", nil
},
}),
envVars: map[string]string{
"KUBE_NODE_NAME": "testNode",
"MAX_VOLUMES_PER_NODE": "4",
},
expectedResp: &csi.NodeGetInfoResponse{
NodeId: testNodeID,
MaxVolumesPerNode: 4,
AccessibleTopology: &csi.Topology{
Segments: map[string]string{
constants.NodeRegionLabel: "test-region",
constants.NodeZoneLabel: "test-zone",
},
},
},
expectedErr: nil,
},
{
testCaseName: "Negative: invalid custom max volumes per node",
req: &csi.NodeGetInfoRequest{},
driverStatsUtils: utils.NewFakeStatsUtilsImpl(utils.FakeStatsUtilsFuncStruct{
GetRegionAndZoneFn: func(nodeName string) (string, string, error) {
return "test-region", "test-zone", nil
},
}),
envVars: map[string]string{
"KUBE_NODE_NAME": "testNode",
"MAX_VOLUMES_PER_NODE": "foobar",
},
expectedResp: nil,
expectedErr: fmt.Errorf("MAX_VOLUMES_PER_NODE does not contain valid number"),
},
}

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

_ = os.Setenv("KUBE_NODE_NAME", "testNode")
for k, v := range tc.envVars {
t.Setenv(k, v)
}

nodeServer := nodeServer{
NodeID: testNodeID,
Expand Down