14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
+ # ============================ Example ================================
18
+ # apiVersion: v1
19
+ # kind: Pod
20
+ # metadata:
21
+ # name: busybox
22
+ # namespace: default
23
+ # spec:
24
+ # containers:
25
+ # - name: busybox
26
+ # image: busybox
27
+ # command:
28
+ # - sleep
29
+ # - "3600"
30
+ # imagePullPolicy: IfNotPresent
31
+ # volumeMounts:
32
+ # - name: test
33
+ # mountPath: /data
34
+ # volumes:
35
+ # - name: test
36
+ # flexVolume:
37
+ # driver: "k8s/nfs"
38
+ # fsType: "nfs"
39
+ # options:
40
+ # server: nfs.example.k8s.io
41
+ # share: "/share/test1"
42
+ # =====================================================================
43
+
44
+
17
45
# Notes:
18
46
# - Please install "jq" package before using this driver.
19
47
usage () {
@@ -44,8 +72,28 @@ ismounted() {
44
72
domount () {
45
73
MNTPATH=$1
46
74
47
- NFS_SERVER=$( echo $2 | jq -r ' .server' )
48
- SHARE=$( echo $2 | jq -r ' .share' )
75
+ local NFS_SERVER=$( echo $2 | jq -r ' .server' )
76
+ local SHARE=$( echo $2 | jq -r ' .share' )
77
+ local PROTOCOL=$( echo $2 | jq -r ' .protocol' )
78
+ local ATIME=$( echo $2 | jq -r ' .atime' )
79
+ local READONLY=$( echo $2 | jq -r ' .readonly' )
80
+
81
+ if [ -n " ${PROTOCOL} " ]; then
82
+ PROTOCOL=" tcp"
83
+ fi
84
+
85
+ if [ -n " ${ATIME} " ]; then
86
+ ATIME=" 0"
87
+ fi
88
+
89
+ if [ -n " ${READONLY} " ]; then
90
+ READONLY=" 0"
91
+ fi
92
+
93
+ if [ " ${PROTOCOL} " != " tcp" ] && [ " ${PROTOCOL} " != " udp" ] ; then
94
+ err " { \" status\" : \" Failure\" , \" message\" : \" Invalid protocol ${PROTOCOL} \" }"
95
+ exit 1
96
+ fi
49
97
50
98
if [ $( ismounted) -eq 1 ] ; then
51
99
log ' {"status": "Success"}'
@@ -54,7 +102,16 @@ domount() {
54
102
55
103
mkdir -p ${MNTPATH} & > /dev/null
56
104
57
- mount -t nfs ${NFS_SERVER} :/${SHARE} ${MNTPATH} & > /dev/null
105
+ local NFSOPTS=" ${PROTOCOL} ,_netdev,soft,timeo=10,intr"
106
+ if [ " ${ATIME} " == " 0" ]; then
107
+ NFSOPTS=" ${NFSOPTS} ,noatime"
108
+ fi
109
+
110
+ if [ " ${READONLY} " != " 0" ]; then
111
+ NFSOPTS=" ${NFSOPTS} ,ro"
112
+ fi
113
+
114
+ mount -t nfs -o${NFSOPTS} ${NFS_SERVER} :/${SHARE} ${MNTPATH} & > /dev/null
58
115
if [ $? -ne 0 ]; then
59
116
err " { \" status\" : \" Failure\" , \" message\" : \" Failed to mount ${NFS_SERVER} :${SHARE} at ${MNTPATH} \" }"
60
117
exit 1
0 commit comments