Skip to content

Commit fb28204

Browse files
authored
Merge pull request #266 from andyzhangx/inline-volume
feat: add inline volume support
2 parents ae37851 + e86dc68 commit fb28204

File tree

14 files changed

+163
-10
lines changed

14 files changed

+163
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ REGISTRY_NAME ?= $(shell echo $(REGISTRY) | sed "s/.azurecr.io//g")
4242
IMAGE_TAG = $(REGISTRY)/$(IMAGENAME):$(IMAGE_VERSION)
4343
IMAGE_TAG_LATEST = $(REGISTRY)/$(IMAGENAME):latest
4444

45-
E2E_HELM_OPTIONS ?= --set image.nfs.repository=$(REGISTRY)/$(IMAGENAME) --set image.nfs.tag=$(IMAGE_VERSION) --set image.nfs.pullPolicy=Always
45+
E2E_HELM_OPTIONS ?= --set image.nfs.repository=$(REGISTRY)/$(IMAGENAME) --set image.nfs.tag=$(IMAGE_VERSION) --set image.nfs.pullPolicy=Always --set feature.enableInlineVolume=true
4646
E2E_HELM_OPTIONS += ${EXTRA_HELM_OPTIONS}
4747

4848
# Output type of docker buildx build

charts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The following table lists the configurable parameters of the latest NFS CSI Driv
4040
| `driver.name` | alternative driver name | `nfs.csi.k8s.io` |
4141
| `driver.mountPermissions` | mounted folder permissions name | `0777`
4242
| `feature.enableFSGroupPolicy` | enable `fsGroupPolicy` on a k8s 1.20+ cluster | `false` |
43+
| `feature.enableInlineVolume` | enable inline volume | `false` |
4344
| `image.nfs.repository` | csi-driver-nfs image | `mcr.microsoft.com/k8s/csi/nfs-csi` |
4445
| `image.nfs.tag` | csi-driver-nfs image tag | `latest` |
4546
| `image.nfs.pullPolicy` | csi-driver-nfs image pull policy | `IfNotPresent` |
25 Bytes
Binary file not shown.

charts/latest/csi-driver-nfs/templates/csi-nfs-driverinfo.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ spec:
66
attachRequired: false
77
volumeLifecycleModes:
88
- Persistent
9+
{{- if .Values.feature.enableInlineVolume}}
10+
- Ephemeral
11+
{{- end}}
912
{{- if .Values.feature.enableFSGroupPolicy}}
1013
fsGroupPolicy: File
1114
{{- end}}

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

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

3131
feature:
3232
enableFSGroupPolicy: false
33+
enableInlineVolume: false
3334

3435
controller:
3536
name: csi-nfs-controller

deploy/csi-nfs-driverinfo.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ spec:
77
attachRequired: false
88
volumeLifecycleModes:
99
- Persistent
10+
- Ephemeral
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
kind: Pod
3+
apiVersion: v1
4+
metadata:
5+
name: nginx-pod-inline-volume
6+
spec:
7+
nodeSelector:
8+
"kubernetes.io/os": linux
9+
containers:
10+
- image: mcr.microsoft.com/oss/nginx/nginx:1.19.5
11+
name: nginx-nfs
12+
command:
13+
- "/bin/bash"
14+
- "-c"
15+
- set -euo pipefail; while true; do echo $(date) >> /mnt/nfs/outfile; sleep 1; done
16+
volumeMounts:
17+
- name: persistent-storage
18+
mountPath: "/mnt/nfs"
19+
volumes:
20+
- name: persistent-storage
21+
csi:
22+
driver: nfs.csi.k8s.io
23+
volumeAttributes:
24+
server: nfs-server.default.svc.cluster.local # required
25+
share: / # required
26+
mountOptions: "nfsvers=4.1,sec=sys" # optional

hack/verify-examples.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rollout_and_wait() {
2020
trap "echo \"Failed to apply config \\\"$1\\\"\" >&2" err
2121

2222
APPNAME=$(kubectl apply -f $1 | grep -E "^(:?daemonset|deployment|statefulset|pod)" | awk '{printf $1}')
23-
if [[ -n $(expr "${APPNAME}" : "\(daemonset\|deployment\|statefulset\)" || true) ]]; then
23+
if [[ -n $(expr "${APPNAME}" : "\(daemonset\|deployment\|statefulset\|pod\)" || true) ]]; then
2424
kubectl rollout status $APPNAME --watch --timeout=5m
2525
else
2626
kubectl wait "${APPNAME}" --for condition=ready --timeout=5m

pkg/nfs/nodeserver.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ type NodeServer struct {
3838

3939
// NodePublishVolume mount the volume
4040
func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
41-
if req.GetVolumeCapability() == nil {
41+
volCap := req.GetVolumeCapability()
42+
if volCap == nil {
4243
return nil, status.Error(codes.InvalidArgument, "Volume capability missing in request")
4344
}
4445
volumeID := req.GetVolumeId()
@@ -49,6 +50,10 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
4950
if len(targetPath) == 0 {
5051
return nil, status.Error(codes.InvalidArgument, "Target path not provided")
5152
}
53+
mountOptions := volCap.GetMount().GetMountFlags()
54+
if req.GetReadonly() {
55+
mountOptions = append(mountOptions, "ro")
56+
}
5257

5358
var server, baseDir string
5459
for k, v := range req.GetVolumeContext() {
@@ -57,6 +62,10 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
5762
server = v
5863
case paramShare:
5964
baseDir = v
65+
case mountOptionsField:
66+
if v != "" {
67+
mountOptions = append(mountOptions, v)
68+
}
6069
}
6170
}
6271

@@ -83,11 +92,6 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8392
return &csi.NodePublishVolumeResponse{}, nil
8493
}
8594

86-
mountOptions := req.GetVolumeCapability().GetMount().GetMountFlags()
87-
if req.GetReadonly() {
88-
mountOptions = append(mountOptions, "ro")
89-
}
90-
9195
klog.V(2).Infof("NodePublishVolume: volumeID(%v) source(%s) targetPath(%s) mountflags(%v)", volumeID, source, targetPath, mountOptions)
9296
err = ns.mounter.Mount(source, targetPath, "nfs", mountOptions)
9397
if err != nil {

test/e2e/dynamic_provisioning_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,33 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
257257
}
258258
test.Run(cs, ns)
259259
})
260+
261+
ginkgo.It("should create a CSI inline volume [nfs.csi.k8s.io]", func() {
262+
pods := []testsuites.PodDetails{
263+
{
264+
Cmd: convertToPowershellCommandIfNecessary("echo 'hello world' > /mnt/test-1/data && grep 'hello world' /mnt/test-1/data"),
265+
Volumes: []testsuites.VolumeDetails{
266+
{
267+
ClaimSize: "10Gi",
268+
VolumeMount: testsuites.VolumeMountDetails{
269+
NameGenerate: "test-volume-",
270+
MountPathGenerate: "/mnt/test-",
271+
},
272+
},
273+
},
274+
},
275+
}
276+
277+
test := testsuites.DynamicallyProvisionedInlineVolumeTest{
278+
CSIDriver: testDriver,
279+
Pods: pods,
280+
Server: nfsServerAddress,
281+
Share: nfsShare,
282+
MountOptions: "nfsvers=4.1,sec=sys",
283+
ReadOnly: false,
284+
}
285+
test.Run(cs, ns)
286+
})
260287
})
261288

262289
func restClient(group string, version string) (restclientset.Interface, error) {

0 commit comments

Comments
 (0)