Skip to content

Commit 2ed8f36

Browse files
authored
configurable volume attachment limit (#141)
* configurable volume attachment limit * volumeAttchLimit as flag * change default * use os env variable * remove MaxAllowedVolumesPerNode * log statements
1 parent decb9df commit 2ed8f36

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

deploy/kubernetes/driver/kubernetes/manifests/config-map.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,4 @@ data:
7474
BlockDriverMemoryLimit: "600Mi" #container:iks-vpc-block-driver, resource-type: memory-limit
7575
CSISnapshotterCPULimit: "80m" #container:csi-snapshotter, resource-type: cpu-limit
7676
CSISnapshotterMemoryLimit: "160Mi" #container:csi-snapshotter, resource-type: memory-limit
77+
VolumeAttachmentLimit: "12" #Volume Attachment Limit per node

deploy/kubernetes/driver/kubernetes/manifests/node-server.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ spec:
4747
valueFrom:
4848
fieldRef:
4949
fieldPath: spec.nodeName
50+
- name: VOLUME_ATTACHMENT_LIMIT
51+
value: "{{kube-system.addon-vpc-block-csi-driver-configmap.VolumeAttachmentLimit}}{{^kube-system.addon-vpc-block-csi-driver-configmap.VolumeAttachmentLimit}}12{{/kube-system.addon-vpc-block-csi-driver-configmap.VolumeAttachmentLimit}}"
5052
resources:
5153
limits:
5254
cpu: "{{kube-system.addon-vpc-block-csi-driver-configmap.CSIDriverRegistrarCPULimit}}{{^kube-system.addon-vpc-block-csi-driver-configmap.CSIDriverRegistrarCPULimit}}40m{{/kube-system.addon-vpc-block-csi-driver-configmap.CSIDriverRegistrarCPULimit}}"

pkg/ibmcsidriver/ibm_csi_driver.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ type IBMCSIDriver struct {
3535
vendorVersion string
3636
logger *zap.Logger
3737
region string
38-
39-
ids *CSIIdentityServer
40-
ns *CSINodeServer
41-
cs *CSIControllerServer
38+
ids *CSIIdentityServer
39+
ns *CSINodeServer
40+
cs *CSIControllerServer
4241

4342
vcap []*csi.VolumeCapability_AccessMode
4443
cscap []*csi.ControllerServiceCapability

pkg/ibmcsidriver/ibm_csi_driver_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ limitations under the License.
1818
package ibmcsidriver
1919

2020
import (
21-
testingexec "k8s.io/utils/exec/testing"
2221
"testing"
2322

23+
testingexec "k8s.io/utils/exec/testing"
24+
2425
cloudProvider "github.com/IBM/ibm-csi-common/pkg/ibmcloudprovider"
2526
nodeMetadata "github.com/IBM/ibm-csi-common/pkg/metadata"
2627
nodeInfo "github.com/IBM/ibm-csi-common/pkg/metadata/fake"

pkg/ibmcsidriver/node.go

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222
"os"
2323
"path/filepath"
24-
"runtime"
2524
"strconv"
2625
"strings"
2726
"sync"
@@ -79,10 +78,7 @@ func (su *VolumeStatUtils) FSInfo(path string) (int64, int64, int64, int64, int6
7978

8079
const (
8180
// DefaultVolumesPerNode is the default number of volumes attachable to a node
82-
DefaultVolumesPerNode = 4
83-
84-
// MaxVolumesPerNode is the maximum number of volumes attachable to a node
85-
MaxVolumesPerNode = 12
81+
DefaultVolumesPerNode = 12
8682

8783
// MinimumCoresWithMaximumAttachableVolumes is the minimum cores required to have maximum number of attachable volumes, currently 4 as per the docs.
8884
MinimumCoresWithMaximumAttachableVolumes = 4
@@ -380,12 +376,20 @@ func (csiNS *CSINodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInf
380376
},
381377
}
382378

383-
// maxVolumesPerNode is the maximum number of volumes attachable to a node; default is 4
384-
cores := runtime.NumCPU()
385-
if cores >= MinimumCoresWithMaximumAttachableVolumes {
386-
maxVolumesPerNode = MaxVolumesPerNode
379+
// If environment variable is set, use this value as maxVolumesPerNode
380+
value, ok := os.LookupEnv("VOLUME_ATTACHMENT_LIMIT")
381+
if !ok {
382+
ctxLogger.Warn("VOLUME_ATTACHMENT_LIMIT is not provided. Setting the default value:", zap.Reflect("MaxVolumesPerNode", maxVolumesPerNode))
383+
} else {
384+
volumeAttachmentLimit, err := strconv.ParseInt(value, 10, 64)
385+
if err != nil {
386+
ctxLogger.Warn("Invalid value for VOLUME_ATTACHMENT_LIMIT. Setting the default value:", zap.Reflect("MaxVolumesPerNode", maxVolumesPerNode))
387+
} else {
388+
maxVolumesPerNode = volumeAttachmentLimit
389+
}
387390
}
388-
ctxLogger.Info("Number of cores of the node and attachable volume limits.", zap.Reflect("Cores", cores), zap.Reflect("AttachableVolumeLimits", maxVolumesPerNode))
391+
392+
ctxLogger.Info("Attachable volume limits", zap.Reflect("AttachableVolumeLimits", maxVolumesPerNode))
389393

390394
resp := &csi.NodeGetInfoResponse{
391395
NodeId: csiNS.Metadata.GetWorkerID(),

pkg/ibmcsidriver/node_test.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ package ibmcsidriver
2020
import (
2121
"errors"
2222
"fmt"
23-
"k8s.io/utils/exec"
24-
testingexec "k8s.io/utils/exec/testing"
2523
"os"
2624
"reflect"
27-
"runtime"
2825
"strings"
2926
"testing"
3027

28+
"k8s.io/utils/exec"
29+
testingexec "k8s.io/utils/exec/testing"
30+
3131
"github.com/IBM/ibm-csi-common/pkg/utils"
3232
csi "github.com/container-storage-interface/spec/lib/go/csi"
3333
"github.com/stretchr/testify/assert"
@@ -471,11 +471,7 @@ func TestNodeGetCapabilities(t *testing.T) {
471471
}
472472

473473
func TestNodeGetInfo(t *testing.T) {
474-
cores := runtime.NumCPU()
475474
var maxVolumesPerNode int64 = DefaultVolumesPerNode
476-
if cores >= MinimumCoresWithMaximumAttachableVolumes {
477-
maxVolumesPerNode = MaxVolumesPerNode
478-
}
479475

480476
testCases := []struct {
481477
name string

0 commit comments

Comments
 (0)