-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·117 lines (101 loc) · 3.75 KB
/
deploy.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash
set -x
function usage () {
echo "Usage: $0 -p project -r region -c cluster -v version [-d] [-s selector] "
}
while getopts "p:r:c:v:s:d:x" flag
do
case "${flag}" in
p) PROJECT=${OPTARG};;
r) REGION=${OPTARG};;
c) CLUSTER=${OPTARG};;
v) TELEMETRY_COMPONENTS_VERSION=${OPTARG};;
s) SELECTOR=${OPTARG};;
d) debug="true" ;;
x) x="true";;
\?) usage;;
esac
done
if [[ $x == "true" ]]
then
error="false"
for variable in GOOGLE_CREDENTIALS CHART_ENVIRONMENT NAMESPACE_ENVIRONMENT VAULT_ENVIRONMENT VAULT_URL VAULT_TOKEN DATADOG_API_KEY STACKDRIVER_CREDENTIALS \
INGRESS_TLS_CRT INGRESS_TLS_KEY INGRESS_IP PROJECT REGION CLUSTER TELEMETRY_COMPONENTS_VERSION CLOUDABILITY_API_KEY PROJECT REGION CLUSTER TELEMETRY_COMPONENTS_VERSION
do
value=`echo ${!variable}`
if [[ -z "$value" ]]
then
if [[ "$error" == "false" ]]
then
error="true"
echo "ERROR required environment variable(s) has empty/null value"
fi
echo "Variable name = $variable"
echo " value = <${!variable}>"
fi
done
if [[ $error != "false" ]]
then
exit -2
fi
fi
if [ -n "$SELECTOR" ] && [ "$SELECTOR" != "all" ]
then
EXTRA_ARGS="--selector app=$SELECTOR"
else
EXTRA_ARGS=""
fi
if [[ -z "$PROJECT" || -z "$REGION" || -z "$CLUSTER" || -z "$TELEMETRY_COMPONENTS_VERSION" ]]
then
usage
exit -1
fi
if [[ $debug == "true" ]]
then
set -x
fi
echo "Installing Telemetry Componenets Version: $TELEMETRY_COMPONENTS_VERSION"
echo "PROJECT is $PROJECT"
echo "REGION is $REGION"
echo "CLUSTER is $CLUSTER"
cd /components
ls -l *
gcloud config set project $PROJECT
echo "$GOOGLE_CREDENTIALS" > creds.json
gcloud auth activate-service-account --key-file=creds.json
gcloud container clusters get-credentials $CLUSTER --region $REGION --project $PROJECT
if [ $? -ne 0 ]
then
echo "Error fetching cluster config."
exit 1
fi
# TODO figure out why this doesn't work when in the dockerfile (next 2 lines)
helm plugin install https://github.com/viglesiasce/helm-gcs.git --version v0.2.0
helm plugin install https://github.com/databus23/helm-diff
kubectl -f ./namespaces.yaml apply
# EXTRA_ARGS="--selector app=carbonelastic"
# helmfile --file helmfile.yaml --environment $PROJECT-$REGION $EXTRA_ARGS delete
# if [ $? -ne 0 ]
# then
# echo "ERROR DELETING Carbon Telemetry Components"
# exit 1
# fi
helmfile --file helmfile.yaml --environment $PROJECT-$REGION $EXTRA_ARGS apply
if [ $? -ne 0 ]
then
echo "ERROR APPLYING Carbon Telemetry Components"
exit 1
fi
#TODO add this code to mode datadog installs
# Do we need to do this sooner?
# Think this is no longer necessary as was able to put into datadog yaml ; kubectl patch ds datadog -n datadog --type=json -p='[{"op": "add", "path": "/spec/template/spec/priorityClassName", "value": "high-priority"}]'
# Need to develop a patch for this -> kubectl patch ds datadog -n datadog --type=json -p='[{"op": "add", "path": "/spec/template/spec/InitContainer", "value": '{"command":["sh","-c","conntrack -D -p udp --dport 8125 | true"],"image":"gcr.io/google-containers/toolbox:20190523-00","imagePullPolicy":"IfNotPresent","name":"conntrack","resources":{},"securityContext":{"allowPrivilegeEscalation":true,"capabilities":{"add":["NET_ADMIN"]}},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File"}'}]'
#new_initContainer = $(kubectl get DaemonSet -o=json datadog --namespace datadog | jq -r --arg new_ic "$new_ic" '.spec.template.spec.InitContainer += $new_ic' )
echo "Pausing after installations, before running tests for 2 minutes"
sleep 120
helmfile --file helmfile.yaml --environment $PROJECT-$REGION $EXTRA_ARGS test
if [ $? -ne 0 ]
then
echo "ERROR TESTING telemetry components"
exit 1
fi