|
16 | 16 | # use NFS as the persistent volume storage area. It is **not** intended for |
17 | 17 | # production. |
18 | 18 | # |
19 | | -# This script makes some assumptions, i.e: |
| 19 | +# By default this script makes some assumptions, i.e: |
20 | 20 | # |
21 | 21 | # - You have sudo |
22 | 22 | # - You have your NFS filesystem mounted to the location you are running this |
|
25 | 25 | # - Your PV names will be one of "crunchy-pvNNN" where NNN is a natural number |
26 | 26 | # - Your NFS UID:GID is "nfsnobody:nfsnobody", which correspunds to "65534:65534" |
27 | 27 | # |
| 28 | +# If you want to modify this script defaults, execute the script with -h argument to see the usage help |
28 | 29 | # And awaaaay we go... |
| 30 | + |
29 | 31 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 32 | +PGO_NFS_IP=$(ip -o route get to 8.8.8.8 | sed -n 's/.*src \([0-9.]\+\).*/\1/p') |
| 33 | +PV_NAME_INPUT="crunchy-pv" |
| 34 | +OLD_PV_NAME_INPUT="crunchy-pv" |
| 35 | +SCRIPT_NAME="$(basename "$(test -L "$0" && readlink "$0" || echo "$0")")" |
| 36 | +PV_COUNT=10 |
| 37 | +NFS_MOUNT_PATH='/nfsfileshare' |
| 38 | + |
| 39 | +usage(){ |
| 40 | + echo "Usage: ./${SCRIPT_NAME} <options>" |
| 41 | + echo " |
| 42 | + Options : |
| 43 | + -n|--name persistent volume name. default is crunchy-pv |
| 44 | + -v|--old-name old persisten volume name. Useful when you want to delete old PVs and use a new name. |
| 45 | + default is crunchy-pv |
| 46 | + -c|--count PV count. how many PVs to create. default is 10 |
| 47 | + -m|--nfs-mount nfs mount path. default is /nfsfileshare |
| 48 | + -i|--nfs-ip nfs ip. default is ${PGO_NFS_IP} |
| 49 | + -h|--help show usage |
| 50 | + " |
| 51 | + exit 1 |
| 52 | + |
| 53 | +} |
| 54 | + |
| 55 | +if [[ $EUID > 0 ]] |
| 56 | + then echo "ERROR: Please run as root or use sudo" |
| 57 | + usage |
| 58 | +fi |
| 59 | + |
| 60 | +opts=$(getopt \ |
| 61 | + -o n:o:c:hm:i: \ |
| 62 | + --long 'name:,old-name:,count:,help,nfs-mount:,nfs-ip: ' \ |
| 63 | + --name "${SCRIPT_NAME}" \ |
| 64 | + -- "$@" |
| 65 | +) |
| 66 | + |
| 67 | +eval set --$opts |
| 68 | +while [[ $# -gt 0 ]]; do |
| 69 | + case "$1" in |
| 70 | + -h|--help) |
| 71 | + usage |
| 72 | + ;; |
| 73 | + -m|--nfs-mount) |
| 74 | + NFS_MOUNT_PATH=$2 |
| 75 | + shift 2 |
| 76 | + ;; |
| 77 | + -n|--name) |
| 78 | + PV_NAME_INPUT=$2 |
| 79 | + OLD_PV_NAME_INPUT=$2 |
| 80 | + shift 2 |
| 81 | + ;; |
| 82 | + -o|--old-name) |
| 83 | + OLD_PV_NAME_INPUT=$2 |
| 84 | + shift 2 |
| 85 | + ;; |
| 86 | + -c|--count) |
| 87 | + PV_COUNT=$2 |
| 88 | + shift 2 |
| 89 | + ;; |
| 90 | + -i|--nfs-ip) |
| 91 | + PGO_NFS_IP=$2 |
| 92 | + shift 2 |
| 93 | + ;; |
| 94 | + *) |
| 95 | + break |
| 96 | + ;; |
| 97 | + esac |
| 98 | +done |
| 99 | + |
| 100 | + |
| 101 | +PGO_CMD="kubectl" |
30 | 102 |
|
31 | 103 | echo "create the test PV and PVC using the NFS dir" |
32 | | -for i in {1..160} |
| 104 | +for i in $(seq 1 $PV_COUNT) |
33 | 105 | do |
34 | | - PV_NAME="crunchy-pv${i}" |
35 | | - NFS_PV_PATH="/nfsfileshare/${PV_NAME}" |
36 | | - |
37 | | - echo "deleting PV ${PV_NAME}" |
38 | | - $PGO_CMD delete pv "${PV_NAME}" |
| 106 | + PV_NAME="${PV_NAME_INPUT}${i}" |
| 107 | + OLD_PV_NAME="${OLD_PV_NAME_INPUT}${i}" |
| 108 | + NFS_PV_PATH="${NFS_MOUNT_PATH}/${PV_NAME}" |
| 109 | + |
| 110 | + echo "deleting PV ${OLD_PV_NAME}" |
| 111 | + $PGO_CMD delete pv "${OLD_PV_NAME}" |
39 | 112 | sudo rm -rf "${NFS_PV_PATH}" |
40 | 113 |
|
41 | 114 | # this is the manifest used to create the persistent volumes |
|
67 | 140 | sudo chmod ugo=rwx "${NFS_PV_PATH}" |
68 | 141 |
|
69 | 142 | # create the new persistent volume |
| 143 | + echo "creating PV ${PV_NAME}" |
70 | 144 | echo $MANIFEST | $PGO_CMD create -f - |
71 | 145 | done |
0 commit comments