This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
/
__helpers.sh
executable file
·73 lines (63 loc) · 1.8 KB
/
__helpers.sh
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
# google-project returns the name of the current project, accounting for a
# variety of common environments. If no project is found in any of the common
# places, an error is returned.
google-project() {
(
set -Eeuo pipefail
local project="${PROJECT:-${GOOGLE_PROJECT:-${GOOGLE_CLOUD_PROJECT:-${DEVSHELL_PROJECT_ID:-}}}}"
if [ -z "${project:-}" ]; then
echo "Missing project ID. Please set PROJECT, GOOGLE_PROJECT, or"
echo "GOOGLE_CLOUD_PROJECT to the ID of your project to continue:"
echo ""
echo " export GOOGLE_CLOUD_PROJECT=$(whoami)-foobar123"
echo ""
return 127
fi
echo "${project}"
)
}
# google-region returns the region in which resources should be created. This
# variable must be changed before running any commands.
google-region() {
(
echo "us-east4"
)
}
# gke-cluster-name is the name of the cluster for the given suffix.
gke-cluster-name() {
(
set -Eeuo pipefail
echo "gke_$(google-project)_$(google-region)_${1}"
)
}
# gke-latest-master-version returns the latest GKE master version.
gke-latest-master-version() {
(
set -Eeuo pipefail
gcloud container get-server-config \
--project="$(google-project)" \
--region="$(google-region)" \
--format='value(validMasterVersions[0])' \
2>/dev/null
)
}
# gke-latest-node-version returns the latest GKE node version.
gke-latest-node-version() {
(
set -Eeuo pipefail
gcloud container get-server-config \
--project="$(google-project)" \
--region="$(google-region)" \
--format='value(validNodeVersions[0])' \
2>/dev/null
)
}
vault-lb-ip() {
(
set -Eeuo pipefail
gcloud compute addresses describe vault \
--project="$(google-project)" \
--region="$(google-region)" \
--format='value(address)'
)
}