Skip to content

Commit 9df3b58

Browse files
committed
feat: add feature flag for inline volume support
test: add ut fix fix fix fix fix
1 parent 8105a9d commit 9df3b58

File tree

9 files changed

+80
-7
lines changed

9 files changed

+80
-7
lines changed
34 Bytes
Binary file not shown.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ spec:
88
podInfoOnMount: true
99
volumeLifecycleModes:
1010
- Persistent
11+
{{- if .Values.feature.enableInlineVolume }}
1112
- Ephemeral
13+
{{- end }}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ roleRef:
9898
name: {{ .Values.rbac.name }}-external-resizer-role
9999
apiGroup: rbac.authorization.k8s.io
100100
---
101+
{{- if .Values.feature.enableInlineVolume }}
101102
kind: ClusterRole
102103
apiVersion: rbac.authorization.k8s.io/v1
103104
metadata:
@@ -107,7 +108,6 @@ rules:
107108
- apiGroups: [""]
108109
resources: ["secrets"]
109110
verbs: ["get"]
110-
111111
---
112112
kind: ClusterRoleBinding
113113
apiVersion: rbac.authorization.k8s.io/v1
@@ -122,4 +122,5 @@ roleRef:
122122
kind: ClusterRole
123123
name: csi-{{ .Values.rbac.name }}-node-secret-role
124124
apiGroup: rbac.authorization.k8s.io
125+
{{- end }}
125126
{{ end }}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ driver:
3939

4040
feature:
4141
enableGetVolumeStats: true
42+
enableInlineVolume: true
4243

4344
controller:
4445
name: csi-smb-controller

pkg/smb/nodeserver.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
147147
secrets := req.GetSecrets()
148148
gidPresent := checkGidPresentInMountFlags(mountFlags)
149149

150-
var source, subDir, secretName, secretNamespace string
150+
var source, subDir, secretName, secretNamespace, ephemeralVolMountOptions string
151+
var ephemeralVol bool
151152
subDirReplaceMap := map[string]string{}
152153
for k, v := range context {
153154
switch strings.ToLower(k) {
@@ -165,6 +166,10 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
165166
secretName = v
166167
case secretNamespaceField:
167168
secretNamespace = v
169+
case ephemeralField:
170+
ephemeralVol = strings.EqualFold(v, trueValue)
171+
case mountOptionsField:
172+
ephemeralVolMountOptions = v
168173
}
169174
}
170175

@@ -190,7 +195,13 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
190195
}
191196
}
192197

193-
if (username == "" || password == "") && (secretName != "" && secretNamespace != "") {
198+
if ephemeralVol {
199+
mountFlags = strings.Split(ephemeralVolMountOptions, ",")
200+
}
201+
202+
// in guest login, username and password options are not needed
203+
requireUsernamePwdOption := !hasGuestMountOptions(mountFlags)
204+
if ephemeralVol && requireUsernamePwdOption {
194205
klog.V(2).Infof("NodeStageVolume: getting username and password from secret %s in namespace %s", secretName, secretNamespace)
195206
var err error
196207
username, password, domain, err = d.GetUserNamePasswordFromSecret(ctx, secretName, secretNamespace)
@@ -199,9 +210,6 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
199210
}
200211
}
201212

202-
// in guest login, username and password options are not needed
203-
requireUsernamePwdOption := !hasGuestMountOptions(mountFlags)
204-
205213
var mountOptions, sensitiveMountOptions []string
206214
if runtime.GOOS == "windows" {
207215
if domain == "" {

pkg/smb/nodeserver_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,37 @@ func TestNodePublishVolume(t *testing.T) {
413413
Readonly: true},
414414
expectedErr: testutil.TestError{},
415415
},
416+
{
417+
desc: "[Error] failed to create ephemeral Volume",
418+
req: &csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
419+
VolumeId: "vol_1",
420+
TargetPath: targetTest,
421+
StagingTargetPath: sourceTest,
422+
Readonly: true,
423+
VolumeContext: map[string]string{ephemeralField: "true"},
424+
},
425+
expectedErr: testutil.TestError{
426+
DefaultError: status.Error(codes.InvalidArgument, "source field is missing, current context: map[csi.storage.k8s.io/ephemeral:true secretnamespace:]"),
427+
},
428+
},
429+
{
430+
desc: "[error] failed request with ephemeral Volume",
431+
req: &csi.NodePublishVolumeRequest{VolumeCapability: &csi.VolumeCapability{AccessMode: &volumeCap},
432+
VolumeId: "vol_1",
433+
TargetPath: targetTest,
434+
StagingTargetPath: sourceTest,
435+
Readonly: true,
436+
VolumeContext: map[string]string{
437+
ephemeralField: "true",
438+
sourceField: "source",
439+
podNamespaceField: "podnamespace",
440+
},
441+
},
442+
skipOnWindows: true,
443+
expectedErr: testutil.TestError{
444+
DefaultError: status.Error(codes.Internal, "Error getting username and password from secret in namespace podnamespace: could not username and password from secret(): KubeClient is nil"),
445+
},
446+
},
416447
}
417448

418449
// Setup

test/e2e/dynamic_provisioning_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,16 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
535535
})
536536

537537
ginkgo.It("should create an CSI inline volume", func(ctx ginkgo.SpecContext) {
538+
if winServerVer == "windows-2022" && !isWindowsHostProcessDeployment {
539+
ginkgo.Skip("Skip inline volume test on Windows Server 2022")
540+
}
541+
542+
secretName := "smbcreds"
543+
ginkgo.By(fmt.Sprintf("creating secret %s in namespace %s", secretName, ns.Name))
544+
tsecret := testsuites.CopyTestSecret(ctx, cs, "default", ns, defaultSmbSecretName)
545+
tsecret.Create(ctx)
546+
defer tsecret.Cleanup(ctx)
547+
538548
pods := []testsuites.PodDetails{
539549
{
540550
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),

test/e2e/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const (
5050
defaultSmbSource = "//smb-server.default.svc.cluster.local/share"
5151
defaultSmbSecretName = "smbcreds"
5252
defaultSmbSecretNamespace = "default"
53+
accountNameForTest = "YW5keXNzZGZpbGUK"
5354
)
5455

5556
var (
@@ -173,7 +174,7 @@ var _ = ginkgo.BeforeSuite(func() {
173174
}
174175

175176
if isWindowsHostProcessDeployment {
176-
decodedBytes, err := base64.StdEncoding.DecodeString("YW5keXNzZGZpbGUK")
177+
decodedBytes, err := base64.StdEncoding.DecodeString(accountNameForTest)
177178
if err != nil {
178179
log.Printf("Error decoding base64 string: %v\n", err)
179180
return

test/e2e/testsuites/testsuites.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,25 @@ func NewTestSecret(c clientset.Interface, ns *v1.Namespace, name string, data ma
717717
}
718718
}
719719

720+
func CopyTestSecret(ctx context.Context, c clientset.Interface, sourceNamespace string, targetNamespace *v1.Namespace, secretName string) *TestSecret {
721+
secret, err := c.CoreV1().Secrets(sourceNamespace).Get(ctx, secretName, metav1.GetOptions{})
722+
framework.ExpectNoError(err)
723+
724+
return &TestSecret{
725+
client: c,
726+
namespace: targetNamespace,
727+
secret: &v1.Secret{
728+
ObjectMeta: metav1.ObjectMeta{
729+
Name: secretName,
730+
Namespace: targetNamespace.Name,
731+
},
732+
StringData: secret.StringData,
733+
Data: secret.Data,
734+
Type: v1.SecretTypeOpaque,
735+
},
736+
}
737+
}
738+
720739
func (t *TestSecret) Create(ctx context.Context) {
721740
var err error
722741
t.secret, err = t.client.CoreV1().Secrets(t.namespace.Name).Create(ctx, t.secret, metav1.CreateOptions{})

0 commit comments

Comments
 (0)