-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelm.sh
More file actions
96 lines (83 loc) · 3.69 KB
/
helm.sh
File metadata and controls
96 lines (83 loc) · 3.69 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
88
89
90
91
92
93
94
95
96
#!/bin/bash -e
# If there is no current context, get one.
if [[ $(kubectl config current-context 2> /dev/null) == "" && "$SKIP_CLUSTER_CONFIG" != true ]]; then
# This tries to read environment variables. If not set, it grabs from gcloud
cluster=${CLOUDSDK_CONTAINER_CLUSTER:-$(gcloud config get-value container/cluster 2> /dev/null)}
region=${CLOUDSDK_COMPUTE_REGION:-$(gcloud config get-value compute/region 2> /dev/null)}
zone=${CLOUDSDK_COMPUTE_ZONE:-$(gcloud config get-value compute/zone 2> /dev/null)}
project=${GCLOUD_PROJECT:-$(gcloud config get-value core/project 2> /dev/null)}
function var_usage() {
cat <<EOF
No cluster is set. To set the cluster (and the region/zone where it is found), set the environment variables
CLOUDSDK_COMPUTE_REGION=<cluster region> (regional clusters)
CLOUDSDK_COMPUTE_ZONE=<cluster zone> (zonal clusters)
CLOUDSDK_CONTAINER_CLUSTER=<cluster name>
EOF
exit 1
}
[[ -z "$cluster" ]] && var_usage
[ ! "$zone" -o "$region" ] && var_usage
if [ -n "$region" ]; then
echo "Running: gcloud container clusters get-credentials --project=\"$project\" --region=\"$region\" \"$cluster\""
gcloud container clusters get-credentials --project="$project" --region="$region" "$cluster"
else
echo "Running: gcloud container clusters get-credentials --project=\"$project\" --zone=\"$zone\" \"$cluster\""
gcloud container clusters get-credentials --project="$project" --zone="$zone" "$cluster"
fi
fi
# if HELM_VERSION starts with v2, initialize Helm
if [[ $HELM_VERSION =~ ^v2 ]]; then
echo "Running: helm init --client-only"
helm init --client-only
else
echo "Skipped 'helm init --client-only' because not v2"
fi
# if GCS_PLUGIN_VERSION is set, install the plugin
if [[ -n $GCS_PLUGIN_VERSION ]]; then
echo "Installing helm GCS plugin version $GCS_PLUGIN_VERSION "
helm plugin install https://github.com/nouney/helm-gcs --version $GCS_PLUGIN_VERSION
fi
# if DIFF_PLUGIN_VERSION is set, install the plugin
if [[ -n $DIFF_PLUGIN_VERSION ]]; then
echo "Installing helm DIFF plugin version $DIFF_PLUGIN_VERSION "
helm plugin install https://github.com/databus23/helm-diff --version $DIFF_PLUGIN_VERSION
fi
# if HELMFILE_VERSION is set, install Helmfile
if [[ -n $HELMFILE_VERSION ]]; then
echo "Installing Helmfile version $HELMFILE_VERSION "
curl -SsL https://github.com/roboll/helmfile/releases/download/$HELMFILE_VERSION/helmfile_linux_amd64 > helmfile
chmod 700 helmfile
fi
# check if repo values provided then add that repo
if [[ -n $HELM_REPO_NAME && -n $HELM_REPO_URL ]]; then
echo "Adding chart helm repo $HELM_REPO_URL"
helm repo add $HELM_REPO_NAME $HELM_REPO_URL
fi
echo "Running: helm repo update"
helm repo list && helm repo update || true
# if 'TILLERLESS=true' is set, run a local tiller server with the secret backend
# see also https://github.com/helm/helm/blob/master/docs/securing_installation.md#running-tiller-locally
if [ "$TILLERLESS" = true ]; then
# create tiller-namespace if it doesn't exist (helm --init would usually do this with server-side tiller'
if [[ -n $TILLER_NAMESPACE ]]; then
echo "Creating tiller namespace $TILLER_NAMESPACE"
kubectl get namespace $TILLER_NAMESPACE || kubectl create namespace $TILLER_NAMESPACE
fi
echo "Starting local tiller server"
#default inherits --listen localhost:44134 and TILLER_NAMESPACE
#use the secret driver by default
tiller --storage=secret &
export HELM_HOST=localhost:44134
if [ "$DEBUG" = true ]; then
echo "Running: helm $@"
fi
helm "$@" && exitCode=$? || exitCode=$?
echo "Stopping local tiller server"
pkill tiller
exit $exitCode
else
if [ "$DEBUG" = true ]; then
echo "Running: helm $@"
fi
helm "$@"
fi