Created
July 17, 2017 17:41
-
-
Save shrinandj/d78801a0d88dd5a47384ef64ed19a92c to your computer and use it in GitHub Desktop.
Kubernetes v1.6 flex volume driver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Copyright 2015 The Kubernetes Authors. | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
usage() { | |
err "Invalid usage. Usage: " | |
err "\t$0 init" | |
err "\t$0 mount <mount dir> <json params>" | |
err "\t$0 unmount <mount dir>" | |
exit 1 | |
} | |
err() { | |
echo -ne $* 1>&2 | |
} | |
log() { | |
echo -ne $* >&1 | |
} | |
domount() { | |
MNTPATH=$1 | |
mkdir "/tmp/target_dir" | |
mkdir -p ${MNTPATH} &> /dev/null | |
mount -o bind /tmp/target_dir ${MNTPATH} | |
if [ $? -ne 0 ]; then | |
err "{ \"status\": \"Failure\", \"message\": \"Failed to mount at ${MNTPATH}\"}" | |
exit 1 | |
fi | |
log "{\"status\": \"Success\"}" | |
exit 0 | |
} | |
unmount() { | |
MNTPATH=$1 | |
umount ${MNTPATH} &> /dev/null | |
if [ $? -ne 0 ]; then | |
err "{ \"status\": \"Failed\", \"message\": \"Failed to unmount volume at ${MNTPATH}\"}" | |
exit 1 | |
fi | |
log "{\"status\": \"Success\"}" | |
g "{\"status\": \"Success\"}" | |
exit 0 | |
} | |
op=$1 | |
if [ "$op" = "init" ]; then | |
log "{\"status\": \"Success\", \"capabilities\": {\"attach\": false}}" | |
exit 0 | |
fi | |
if [ $# -lt 2 ]; then | |
usage | |
fi | |
shift | |
case "$op" in | |
mount) | |
domount $* | |
;; | |
unmount) | |
unmount $* | |
;; | |
*) | |
log "{ \"status\": \"Not supported\" }" | |
exit 0 | |
esac | |
exit 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment