-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvke_wrapper
executable file
·66 lines (52 loc) · 1.81 KB
/
vke_wrapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# @file vke_wrapper
# To use this wrapper, create an alias:
# alias vke='./vke_wrapper'
# To ignore this alias, use:
# \vke ...
# Functionaliy introduced using this wrapper are to are listed in the README
# @author Alister Lewis-Bowen <alister@lewis-bowen.org>
[[ -n $DEBUG ]] && set -x
set -eou pipefail
VKE_FOLDERS=''
VKE_PROJECTS=''
VKE_FOLDER=''
VKE_PROJECT=''
VKE_CLUSTER=''
VKE_OBJ_NAME=''
VKE_VERSION=''
VKE_PASSTHROUGH='n'
VKE_BOLD="$(tput bold)"
VKE_RESET="$(tput sgr0)"
VKE_DUMMY_NAME='n0t-m3nt-t0-b3-f0und'
CMD="$*"
if [[ $# -gt 0 ]]; then
## Create a default region (the lowest ID)
VKE_DEFAULT_REGION=$(vke -o json info region list | jq -r -s 'sort_by(.regionId) | .[] | .items[1] | .name')
## Rough attempt at guessing the resource name
VKE_RESOURCE_NAME="${@: -1}"
## Look for context (folder & project) overrides
VKE_SUBCOMMAND=''
while [[ $# -gt 0 ]]; do
case "$1" in
cluster ) VKE_SUBCOMMAND='cluster'; shift ;;
-v | --version )
## Since --version has two meanings in the VKE cli...
if [[ "$VKE_SUBCOMMAND" == 'cluster' ]]; then
VKE_VERSION="$2"; shift; shift
fi
shift ;;
-h | --help ) VKE_PASSTHROUGH='y'; shift;;
* ) shift ;;
esac
done
if [[ "$VKE_PASSTHROUGH" == 'n' ]]; then
[[ ("VKE_SUBCOMMAND" == 'cluster') && ("$CMD" =~ upgrade) && ( -z "${VKE_VERSION}") ]] && {
# default to the latest version of K8s
VKE_VERSION=$(vke -o json cluster versions list -r "$VKE_DEFAULT_REGION" | jq -r '.items[] | select(.isDefault == true) | .version')
CMD="${CMD% *} -v $VKE_VERSION $VKE_RESOURCE_NAME"
}
fi
fi
## Pass it on
vke $CMD