Skip to content

Commit a53cb60

Browse files
authored
Add some options to the NFS FlexVolume example
Add default options: * _netdev * soft * intr * timeo=10 Add params to the flex volume: * protocol * atime * readonly Add example pod
1 parent bbe33f4 commit a53cb60

File tree

1 file changed

+60
-3
lines changed
  • staging/volumes/flexvolume

1 file changed

+60
-3
lines changed

staging/volumes/flexvolume/nfs

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,34 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

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+
1745
# Notes:
1846
# - Please install "jq" package before using this driver.
1947
usage() {
@@ -44,8 +72,28 @@ ismounted() {
4472
domount() {
4573
MNTPATH=$1
4674

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
4997

5098
if [ $(ismounted) -eq 1 ] ; then
5199
log '{"status": "Success"}'
@@ -54,7 +102,16 @@ domount() {
54102

55103
mkdir -p ${MNTPATH} &> /dev/null
56104

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
58115
if [ $? -ne 0 ]; then
59116
err "{ \"status\": \"Failure\", \"message\": \"Failed to mount ${NFS_SERVER}:${SHARE} at ${MNTPATH}\"}"
60117
exit 1

0 commit comments

Comments
 (0)