Skip to content

Commit dc3e555

Browse files
authored
Merge pull request #381 from andyzhangx/disable-get-volume-stats
feat: disable GET_VOLUME_STATS by default
2 parents 35357c4 + 7b25f5b commit dc3e555

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1620
-209
lines changed

charts/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ The following table lists the configurable parameters of the latest SMB CSI Driv
3636

3737
| Parameter | Description | Default |
3838
|---------------------------------------------------|------------------------------------------------------------|-------------------------------------------------------------------|
39+
| `driver.name` | alternative driver name | `smb.csi.k8s.io` |
40+
| `feature.enableGetVolumeStats` | allow GET_VOLUME_STATS on agent node | `false` |
3941
| `image.baseRepo` | base repository of driver images | `mcr.microsoft.com` |
4042
| `image.smb.repository` | csi-driver-smb docker image | `/k8s/csi/smb-csi` |
4143
| `image.smb.tag` | csi-driver-smb docker image tag | `latest` |
43 Bytes
Binary file not shown.

charts/latest/csi-driver-smb/templates/csi-smb-node-windows.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ spec:
9393
- --endpoint=$(CSI_ENDPOINT)
9494
- --nodeid=$(KUBE_NODE_NAME)
9595
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
96+
- "--enable-get-volume-stats={{ .Values.feature.enableGetVolumeStats }}"
9697
ports:
9798
- containerPort: {{ .Values.node.livenessProbe.healthPort }}
9899
name: healthz

charts/latest/csi-driver-smb/templates/csi-smb-node.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ spec:
101101
- "--endpoint=$(CSI_ENDPOINT)"
102102
- "--nodeid=$(KUBE_NODE_NAME)"
103103
- "--metrics-address=0.0.0.0:{{ .Values.node.metricsPort }}"
104+
- "--enable-get-volume-stats={{ .Values.feature.enableGetVolumeStats }}"
104105
ports:
105106
- containerPort: {{ .Values.node.livenessProbe.healthPort }}
106107
name: healthz

charts/latest/csi-driver-smb/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ rbac:
2828
driver:
2929
name: smb.csi.k8s.io
3030

31+
feature:
32+
enableGetVolumeStats: false
33+
3134
controller:
3235
name: csi-smb-controller
3336
replicas: 2

go.mod

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module github.com/kubernetes-csi/csi-driver-smb
33
go 1.16
44

55
require (
6-
github.com/Azure/azure-sdk-for-go v49.1.0+incompatible
6+
github.com/Azure/azure-sdk-for-go v43.0.0+incompatible
77
github.com/Azure/go-autorest/autorest v0.11.12
88
github.com/Azure/go-autorest/autorest/adal v0.9.5
9-
github.com/Azure/go-autorest/autorest/to v0.3.0
9+
github.com/Azure/go-autorest/autorest/to v0.2.0
1010
github.com/container-storage-interface/spec v1.5.0
1111
github.com/golang/protobuf v1.4.3
1212
github.com/kubernetes-csi/csi-lib-utils v0.7.0
@@ -33,16 +33,6 @@ require (
3333
replace (
3434
bitbucket.org/bertimus9/systemstat => bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690
3535
cloud.google.com/go => cloud.google.com/go v0.38.0
36-
github.com/Azure/azure-sdk-for-go => github.com/Azure/azure-sdk-for-go v40.2.0+incompatible
37-
github.com/Azure/go-ansiterm => github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78
38-
github.com/Azure/go-autorest/autorest => github.com/Azure/go-autorest/autorest v0.11.1
39-
github.com/Azure/go-autorest/autorest/adal => github.com/Azure/go-autorest/autorest/adal v0.9.0
40-
github.com/Azure/go-autorest/autorest/date => github.com/Azure/go-autorest/autorest/date v0.3.0
41-
github.com/Azure/go-autorest/autorest/mocks => github.com/Azure/go-autorest/autorest/mocks v0.4.0
42-
github.com/Azure/go-autorest/autorest/to => github.com/Azure/go-autorest/autorest/to v0.3.0
43-
github.com/Azure/go-autorest/autorest/validation => github.com/Azure/go-autorest/autorest/validation v0.1.0
44-
github.com/Azure/go-autorest/logger => github.com/Azure/go-autorest/logger v0.2.0
45-
github.com/Azure/go-autorest/tracing => github.com/Azure/go-autorest/tracing v0.6.0
4636
github.com/BurntSushi/toml => github.com/BurntSushi/toml v0.3.1
4737
github.com/BurntSushi/xgb => github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802
4838
github.com/GoogleCloudPlatform/k8s-cloud-provider => github.com/GoogleCloudPlatform/k8s-cloud-provider v0.0.0-20190822182118-27a4ced34534

go.sum

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690/go.mod h1:Ulb78X89vxKYgdL24HMTiXYHlyHEvruOj1ZPlqeNEZM=
22
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
33
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
4-
github.com/Azure/azure-sdk-for-go v40.2.0+incompatible h1:JVGI3ws5ouCNwtQtwProxSff9uf2XiH/K8ydhuNhL1I=
5-
github.com/Azure/azure-sdk-for-go v40.2.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
4+
github.com/Azure/azure-sdk-for-go v35.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
5+
github.com/Azure/azure-sdk-for-go v43.0.0+incompatible h1:/wSNCu0e6EsHFR4Qa3vBEBbicaprEHMyyga9g8RTULI=
6+
github.com/Azure/azure-sdk-for-go v43.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
67
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
78
github.com/Azure/go-autorest v14.2.0+incompatible h1:V5VMDjClD3GiElqLWO7mz2MxNAK/vTfRHdAubSIPRgs=
89
github.com/Azure/go-autorest v14.2.0+incompatible/go.mod h1:r+4oMnoxhatjLLJ6zxSWATqVooLgysK6ZNox3g/xq24=
9-
github.com/Azure/go-autorest/autorest v0.11.1 h1:eVvIXUKiTgv++6YnWb42DUA1YL7qDugnKP0HljexdnQ=
10-
github.com/Azure/go-autorest/autorest v0.11.1/go.mod h1:JFgpikqFJ/MleTTxwepExTKnFUKKszPS8UavbQYUMuw=
11-
github.com/Azure/go-autorest/autorest/adal v0.9.0 h1:SigMbuFNuKgc1xcGhaeapbh+8fgsu+GxgDRFyg7f5lM=
12-
github.com/Azure/go-autorest/autorest/adal v0.9.0/go.mod h1:/c022QCutn2P7uY+/oQWWNcK9YU+MH96NgK+jErpbcg=
10+
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
11+
github.com/Azure/go-autorest/autorest v0.11.12 h1:gI8ytXbxMfI+IVbI9mP2JGCTXIuhHLgRlvQ9X4PsnHE=
12+
github.com/Azure/go-autorest/autorest v0.11.12/go.mod h1:eipySxLmqSyC5s5k1CLupqet0PSENBEDP93LQ9a8QYw=
13+
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
14+
github.com/Azure/go-autorest/autorest/adal v0.9.5 h1:Y3bBUV4rTuxenJJs41HU3qmqsb+auo+a3Lz+PlJPpL0=
15+
github.com/Azure/go-autorest/autorest/adal v0.9.5/go.mod h1:B7KF7jKIeC9Mct5spmyCB/A8CG/sEz1vwIRGv/bbw7A=
16+
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
1317
github.com/Azure/go-autorest/autorest/date v0.3.0 h1:7gUk1U5M/CQbp9WoqinNzJar+8KY+LPI6wiWrP/myHw=
1418
github.com/Azure/go-autorest/autorest/date v0.3.0/go.mod h1:BI0uouVdmngYNUzGWeSYnokU+TrmwEsOqdt8Y6sso74=
15-
github.com/Azure/go-autorest/autorest/mocks v0.4.0 h1:z20OWOSG5aCye0HEkDp6TPmP17ZcfeMxPi6HnSALa8c=
16-
github.com/Azure/go-autorest/autorest/mocks v0.4.0/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
17-
github.com/Azure/go-autorest/autorest/to v0.3.0 h1:zebkZaadz7+wIQYgC7GXaz3Wb28yKYfVkkBKwc38VF8=
18-
github.com/Azure/go-autorest/autorest/to v0.3.0/go.mod h1:MgwOyqaIuKdG4TL/2ywSsIWKAfJfgHDo8ObuUk3t5sA=
19+
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
20+
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
21+
github.com/Azure/go-autorest/autorest/mocks v0.4.1 h1:K0laFcLE6VLTOwNgSxaGbUcLPuGXlNkbVvq4cW4nIHk=
22+
github.com/Azure/go-autorest/autorest/mocks v0.4.1/go.mod h1:LTp+uSrOhSkaKrUy935gNZuuIPPVsHlr9DSOxSayd+k=
23+
github.com/Azure/go-autorest/autorest/to v0.2.0 h1:nQOZzFCudTh+TvquAtCRjM01VEYx85e9qbwt5ncW4L8=
24+
github.com/Azure/go-autorest/autorest/to v0.2.0/go.mod h1:GunWKJp1AEqgMaGLV+iocmRAJWqST1wQYhyyjXJ3SJc=
1925
github.com/Azure/go-autorest/autorest/validation v0.1.0 h1:ISSNzGUh+ZSzizJWOWzs8bwpXIePbGLW4z/AmUFGH5A=
2026
github.com/Azure/go-autorest/autorest/validation v0.1.0/go.mod h1:Ha3z/SqBeaalWQvokg3NZAlQTalVMtOIAs1aGK7G6u8=
27+
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
2128
github.com/Azure/go-autorest/logger v0.2.0 h1:e4RVHVZKC5p6UANLJHkM4OfR1UKZPj8Wt8Pcx+3oqrE=
2229
github.com/Azure/go-autorest/logger v0.2.0/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZmbF5NWuPV8+WeEW8=
30+
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
2331
github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo=
2432
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
2533
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
@@ -101,7 +109,6 @@ github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2
101109
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
102110
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
103111
github.com/daviddengcn/go-colortext v0.0.0-20160507010035-511bcaf42ccd/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
104-
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
105112
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
106113
github.com/dnaeon/go-vcr v1.0.1/go.mod h1:aBB1+wY4s93YsC3HHjMBMrwTj2R9FHDzUr9KyGc8n1E=
107114
github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BUmsJpcB+cRlLU7cSug=
@@ -125,6 +132,8 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo
125132
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
126133
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
127134
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
135+
github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk=
136+
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
128137
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
129138
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
130139
github.com/fvbommel/sortorder v1.0.1/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=

pkg/smb/nodeserver_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,45 @@ func TestNodeGetVolumeStats(t *testing.T) {
660660
err := os.RemoveAll(fakePath)
661661
assert.NoError(t, err)
662662
}
663+
664+
func TestCheckGidPresentInMountFlags(t *testing.T) {
665+
tests := []struct {
666+
desc string
667+
VolumeMountGroup string
668+
MountFlags []string
669+
expectedErr error
670+
result bool
671+
}{
672+
{
673+
desc: "[Error] VolumeMountGroup is different from gid in mount options",
674+
VolumeMountGroup: "2000",
675+
MountFlags: []string{"gid=3000"},
676+
expectedErr: status.Error(codes.InvalidArgument, "gid(3000) in storageClass and pod fsgroup(2000) are not equal"),
677+
result: false,
678+
},
679+
{
680+
desc: "[Success] Gid present in mount flags",
681+
VolumeMountGroup: "",
682+
MountFlags: []string{"gid=3000"},
683+
expectedErr: nil,
684+
result: true,
685+
},
686+
{
687+
desc: "[Success] Gid not present in mount flags",
688+
VolumeMountGroup: "",
689+
MountFlags: []string{},
690+
expectedErr: nil,
691+
result: false,
692+
},
693+
}
694+
695+
for _, test := range tests {
696+
gIDPresent, err := checkGidPresentInMountFlags(test.VolumeMountGroup, test.MountFlags)
697+
if !reflect.DeepEqual(err, test.expectedErr) {
698+
t.Errorf("[%s]: Unexpected Error: %v, expected error: %v", test.desc, err, test.expectedErr)
699+
}
700+
if gIDPresent != test.result {
701+
t.Errorf("[%s]: Expected result : %t, Actual result: %t", test.desc, test.result, gIDPresent)
702+
}
703+
}
704+
}

pkg/smb/smb.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,19 @@ type Driver struct {
3939
mounter *mount.SafeFormatAndMount
4040
// A map storing all volumes with ongoing operations so that additional operations
4141
// for that same volume (as defined by VolumeID) return an Aborted error
42-
volumeLocks *volumeLocks
43-
workingMountDir string
42+
volumeLocks *volumeLocks
43+
workingMountDir string
44+
enableGetVolumeStats bool
4445
}
4546

4647
// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
4748
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
48-
func NewDriver(nodeID, driverName string) *Driver {
49+
func NewDriver(nodeID, driverName string, enableGetVolumeStats bool) *Driver {
4950
driver := Driver{}
5051
driver.Name = driverName
5152
driver.Version = driverVersion
5253
driver.NodeID = nodeID
54+
driver.enableGetVolumeStats = enableGetVolumeStats
5355
driver.volumeLocks = newVolumeLocks()
5456
return &driver
5557
}
@@ -84,12 +86,15 @@ func (d *Driver) Run(endpoint, kubeconfig string, testMode bool) {
8486
csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER,
8587
})
8688

87-
d.AddNodeServiceCapabilities([]csi.NodeServiceCapability_RPC_Type{
88-
csi.NodeServiceCapability_RPC_GET_VOLUME_STATS,
89+
nodeCap := []csi.NodeServiceCapability_RPC_Type{
8990
csi.NodeServiceCapability_RPC_STAGE_UNSTAGE_VOLUME,
9091
csi.NodeServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
9192
csi.NodeServiceCapability_RPC_VOLUME_MOUNT_GROUP,
92-
})
93+
}
94+
if d.enableGetVolumeStats {
95+
nodeCap = append(nodeCap, csi.NodeServiceCapability_RPC_GET_VOLUME_STATS)
96+
}
97+
d.AddNodeServiceCapabilities(nodeCap)
9398

9499
s := csicommon.NewNonBlockingGRPCServer()
95100
// Driver d act as IdentityServer, ControllerServer and NodeServer

pkg/smb/smb_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ const (
3030
)
3131

3232
func NewFakeDriver() *Driver {
33-
return NewDriver(fakeNodeID, DefaultDriverName)
33+
return NewDriver(fakeNodeID, DefaultDriverName, true)
3434
}
3535

3636
func TestNewFakeDriver(t *testing.T) {
3737
// Test New fake driver.
38-
d := NewDriver(fakeNodeID, DefaultDriverName)
38+
d := NewDriver(fakeNodeID, DefaultDriverName, true)
3939
assert.NotNil(t, d)
4040
}
4141

0 commit comments

Comments
 (0)