-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrap.sh
executable file
·174 lines (139 loc) · 4.07 KB
/
bootstrap.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
set -e
LANG=C
SLEEP_SECONDS=45
ARGO_NS="openshift-gitops"
GITOPS_OVERLAY=components/operators/openshift-gitops/operator/overlays/latest/
SEALED_SECRETS_FOLDER=components/operators/sealed-secrets-operator/overlays/default/
SEALED_SECRETS_SECRET=bootstrap/base/sealed-secrets-secret.yaml
OCP_VERSION=${OCP_VERSION}
TMP_DIR=generated
setup_bin() {
mkdir -p ${TMP_DIR}/bin
echo ${PATH} | grep -q "${TMP_DIR}/bin" || \
export PATH=$(pwd)/${TMP_DIR}/bin:$PATH
}
check_oc() {
which oc 2>&1 >/dev/null || download_oc
# echo "auto-complete: . <(oc completion bash)"
# . <(oc completion bash)
oc version
sleep 5
}
check_kustomize() {
which kustomize 2>&1 >/dev/null || download_kustomize
# echo "auto-complete: . <(kustomize completion bash)"
# . <(kustomize completion bash)
kustomize version
sleep 5
}
download_oc() {
DOWNLOAD_URL=https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable-${OCP_VERSION}/openshift-client-linux.tar.gz
curl "${DOWNLOAD_URL}" -L | tar vzx -C ${TMP_DIR}/bin oc
}
download_kustomize() {
cd ${TMP_DIR}/bin
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
cd ../..
}
# check login
check_oc_login(){
oc cluster-info | head -n1
oc whoami || exit 1
echo
sleep 5
}
# create a sealed secret
create_sealed_secret(){
read -r -p "Create [${SEALED_SECRETS_SECRET}]? [y/N] " input
case $input in
[yY][eE][sS]|[yY])
oc apply -k ${SEALED_SECRETS_FOLDER}
[ -e ${SEALED_SECRETS_SECRET} ] && return
# just wait for it
sleep 20
oc -n sealed-secrets -o yaml \
get secret \
-l sealedsecrets.bitnami.com/sealed-secrets-key=active \
> ${SEALED_SECRETS_SECRET}
;;
[nN][oO]|[nN]*)
echo
;;
*)
echo
;;
esac
}
# Validate sealed secrets secret exists
check_sealed_secret(){
if [ -f ${SEALED_SECRETS_SECRET} ]; then
echo "Exists: ${SEALED_SECRETS_SECRET}"
else
echo "Missing: ${SEALED_SECRETS_SECRET}"
echo "The master key is required to bootstrap sealed secrets and CANNOT be checked into git."
echo
create_sealed_secret
fi
}
install_gitops(){
echo ""
echo "Installing GitOps Operator."
kustomize build ${GITOPS_OVERLAY} | oc apply -f -
echo "Pause ${SLEEP_SECONDS} seconds for the creation of the gitops-operator..."
sleep ${SLEEP_SECONDS}
echo "Waiting for operator to start"
until oc get deployment gitops-operator-controller-manager -n openshift-operators
do
sleep 5;
done
echo "Waiting for openshift-gitops namespace to be created"
until oc get ns ${ARGO_NS}
do
sleep 5;
done
echo "Waiting for deployments to start"
until oc get deployment cluster -n ${ARGO_NS}
do
sleep 5;
done
echo "Waiting for all pods to be created"
deployments=(cluster kam openshift-gitops-applicationset-controller openshift-gitops-redis openshift-gitops-repo-server openshift-gitops-server)
for i in "${deployments[@]}";
do
echo "Waiting for deployment $i";
oc rollout status deployment $i -n ${ARGO_NS}
done
echo ""
echo "OpenShift GitOps successfully installed."
}
main(){
PS3="Please select a bootstrap folder: "
select bootstrap_dir in bootstrap/overlays/*/;
do
test -n "$bootstrap_dir" && break;
echo ">>> Invalid Selection";
done
echo "Selected: ${bootstrap_dir}"
install_gitops
echo "Apply overlay to override default instance"
kustomize build ${bootstrap_dir} | oc apply -f -
sleep 10
echo "Waiting for all pods to redeploy"
deployments=(cluster kam openshift-gitops-applicationset-controller openshift-gitops-redis openshift-gitops-repo-server openshift-gitops-server)
for i in "${deployments[@]}";
do
echo "Waiting for deployment $i";
oc rollout status deployment $i -n ${ARGO_NS}
done
echo ""
echo "Cluster has successfully deployed! Check the status of the sync here:"
route=$(oc get route openshift-gitops-server -o=jsonpath='{.spec.host}' -n ${ARGO_NS})
echo "https://${route}"
}
setup_bin
check_oc
check_kustomize
check_oc_login
check_sealed_secret
main