forked from cradlepoint/helm-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelm
More file actions
executable file
·87 lines (72 loc) · 2.36 KB
/
helm
File metadata and controls
executable file
·87 lines (72 loc) · 2.36 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#####
# helm-wrapper tool simplifies helm/tiller version and namespace management.
#
# See https://github.com/cradlepoint/helm-wrapper for installation instructions.
#
#####
set -e # exit on any error
# helper function to scan caller-supplied parameters
isParamSpecified() {
PARAM=$1
for P in "${@:2}"; do
if [ $P == "$PARAM" ]; then
return 0 # true
fi
done
return 1 # false
}
##############
# Step 1: figure out tiller namespace
# if caller did not specify --tiller-namespace then calculate it
if ! isParamSpecified "--tiller-namespace" $@; then
# check for TILLER_NAMESPACE env
if [ -n "$TILLER_NAMESPACE" ]; then
NS_DEBUG="helm-wrapper: using env TILLER_NAMESPACE $TILLER_NAMESPACE"
# check kubeconfig namespace
elif [ ! -z "`kubectl config current-context`" ] ; then
NS=$(kubectl config view --minify --output 'jsonpath={..namespace}')
if [ -n "$NS" ]; then
NS_DEBUG="helm-wrapper: using kubeconfig namespace $NS"
else
# use default tiller namespace
NS_DEBUG="helm-wrapper: using default kube-system namespace"
NS="kube-system"
fi
NS="--tiller-namespace $NS"
fi
else
NS_DEBUG="helm-wrapper: using --tiller-namespace"
fi
##############
# Step 2: match tiller version for server calls
# search for commands that require helm and tiller to match
TILLER_COMMANDS=(ls list history get install upgrade delete status)
TILLER_COMMAND_FOUND=false
for COMMAND in "${TILLER_COMMANDS[@]}"; do
if isParamSpecified $COMMAND $@; then
TILLER_COMMAND_FOUND=true
break
fi
done
HELM_LATEST=$(ls /usr/local/bin/helm-* | sort -V | tail -1)
if [ "$TILLER_COMMAND_FOUND" == "true" ]; then
# execute command using helm that matches tiller version
# output namespace info
(>&2 echo $NS_DEBUG)
# get server tiller version
SERVER_TILLER_VERSION=$(exec $HELM_LATEST $NS version --short | grep Server | sed 's/.*v\(.*\)+.*/\1/')
if [ -n "$SERVER_TILLER_VERSION" ]; then
HELM_CURRENT="/usr/local/bin/helm-v$SERVER_TILLER_VERSION"
if [ -f "$HELM_CURRENT" ]; then
exec $HELM_CURRENT $NS $@
else
(>&2 echo "helm-wrapper: error, helm client version $SERVER_TILLER_VERSION is not installed.")
fi
fi
else
# execute command using latest helm
# output namespace info for "helm init"
if isParamSpecified "init" $@; then (>&2 echo $NS_DEBUG) fi
exec $HELM_LATEST $NS $@
fi