This repository was archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-credentials-helper.sh
More file actions
executable file
·59 lines (51 loc) · 1.68 KB
/
setup-credentials-helper.sh
File metadata and controls
executable file
·59 lines (51 loc) · 1.68 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
#!/bin/bash
: ${GOOGLE_CREDENTIALS:="$(cat "$PLUGIN_GOOGLE_CREDENTIALS_FILE" 2>/dev/null)"}
: ${PROJECT:="$PLUGIN_PROJECT"}
: ${CLUSTER:="$PLUGIN_CLUSTER"}
: ${ZONE:="$PLUGIN_ZONE"}
: ${UPGRADE_TILLER:="$PLUGIN_UPGRADE_TILLER"}
: ${SSH_KEY:="$PLUGIN_SSH_KEY"}
require_param() {
declare name="$1"
local env_name
env_name="$(echo "$name" | tr /a-z/ /A-Z/)"
if [ -z "${!env_name}" ] ; then
echo "You must define \"$name\" parameter or define $env_name environment variable" >&2
exit 2
fi
}
require_google_credentials() {
if [ -z "$GOOGLE_CREDENTIALS" ] ; then
echo "You must define \"google_credentials_file\" parameter or define GOOGLE_CREDENTIALS environment variable" >&2
exit 2
fi
}
run() {
echo "+" "$@"
"$@"
}
if [ ! -z "$GOOGLE_CREDENTIALS" ] ; then
echo "$GOOGLE_CREDENTIALS" > /run/google-credentials.json
gcloud auth activate-service-account --key-file=/run/google-credentials.json
fi
if [ ! -z "$CLUSTER" ] ; then
require_google_credentials
require_param "cluster"
require_param "project"
require_param "zone"
run gcloud container clusters get-credentials "$CLUSTER" --project "$PROJECT" --zone "$ZONE"
# Display kubernetees versions (usefull for debugging)
run kubectl version
# initialize helm
if [ "$UPGRADE_TILLER" == "true" ] || [ "$UPGRADE_TILLER" == "yes" ]; then
run helm init --upgrade
fi
fi
if [ ! -z "$SSH_KEY" ] ; then
require_param "home"
test -d "$HOME/.ssh" || mkdir -p "$HOME/.ssh"
echo "$SSH_KEY" > "$HOME/.ssh/id_rsa"
chmod 0400 "$HOME/.ssh/id_rsa"
echo "Installed ssh key into $HOME/.ssh/id_rsa"
ssh-keygen -y -f "$HOME/.ssh/id_rsa"
fi