forked from GoogleCloudPlatform/cloud-builders-community
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkustomize.bash
45 lines (35 loc) · 1.46 KB
/
kustomize.bash
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
#!/bin/bash
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>
CLOUDSDK_CONTAINER_CLUSTER=<cluster name>
EOF
exit 1
}
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=${CLOUDSDK_CORE_PROJECT:-$(gcloud config get-value core/project 2>/dev/null)}
[[ -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" || exit
else
echo "Running: gcloud container clusters get-credentials --project=\"$project\" --zone=\"$zone\" \"$cluster\""
gcloud container clusters get-credentials --project="$project" --zone="$zone" "$cluster" || exit
fi
if [ "$APPLY" = true ]; then
KUBECTL_PIPE="kubectl apply -f -"
if [ "$DEBUG" = true ]; then
echo "Running: kustomize $@ | $KUBECTL_PIPE"
fi
kustomize "$@" | $KUBECTL_PIPE
else
if [ "$DEBUG" = true ]; then
echo "Running: kustomize $@"
fi
kustomize "$@"
fi