forked from kruize/kruize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·168 lines (155 loc) · 3.63 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
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
#!/bin/bash
#
# Copyright (c) 2019, 2019 IBM Corporation and others.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
KRUIZE_VERSION=$(cat .kruize-version)
DEPLOY_TEMPLATE="manifests/kruize.yaml_template"
DEPLOY_MANIFEST="manifests/kruize.yaml"
SA_TEMPLATE="manifests/kruize-sa_rbac.yaml_template"
SA_MANIFEST="manifests/kruize-sa_rbac.yaml"
SA_NAME="kruize-sa"
SERVICE_MONITOR_MANIFEST="manifests/servicemonitor/kruize-service-monitor.yaml"
KRUIZE_DOCKER_REPO="dinogun/kruize"
KRUIZE_DOCKER_IMAGE=${KRUIZE_DOCKER_REPO}:${KRUIZE_VERSION}
KRUIZE_PORT="31313"
ROOT_DIR="${PWD}"
SCRIPTS_DIR="${ROOT_DIR}/scripts"
# source all the helpers scripts
. ${SCRIPTS_DIR}/docker-helpers.sh
. ${SCRIPTS_DIR}/icp-helpers.sh
. ${SCRIPTS_DIR}/minikube-helpers.sh
. ${SCRIPTS_DIR}/openshift-helpers.sh
# Defaults for the script
# ICP is the default cluster type
cluster_type="icp"
# Call setup by default (and not terminate)
setup=1
# Default mode is interactive
non_interactive=0
# Default namespace is kube-system
kruize_ns="kube-system"
# Default userid is "admin"
user="admin"
# docker: loop timeout is turned off by default
timeout=-1
function usage() {
echo
echo "Usage: $0 [-a] [-k url] [-c [docker|icp|minikube|openshift]] [-i docker-image] [-s|t] [-u user] [-p password] [-n namespace] [--timeout=x, x in seconds, for docker only]"
echo " -s = start(default), -t = terminate"
exit -1
}
# Check error code from last command, exit on error
check_err() {
err=$?
if [ ${err} -ne 0 ]; then
echo "$*"
exit -1
fi
}
# Check if the cluster_type is one of icp or openshift
function check_cluster_type() {
case "${cluster_type}" in
docker|icp|minikube|openshift)
;;
*)
echo "Error: unsupported cluster type: ${cluster_type}"
exit -1
esac
}
function check_running() {
check_pod=$1
echo "Info: Waiting for ${check_pod} to come up..."
while true;
do
sleep 2
${kubectl_cmd} get pods | grep ${check_pod}
pod_stat=$(${kubectl_cmd} get pods | grep ${check_pod} | awk '{ print $3 }' | grep -v 'Terminating')
case "${pod_stat}" in
"ContainerCreating"|"Terminating"|"Pending")
sleep 2
;;
"Running")
echo "Info: ${check_pod} deploy succeeded: ${pod_stat}"
err=0
break;
;;
*)
echo "Error: ${check_pod} deploy failed: ${pod_stat}"
err=-1
break;
;;
esac
done
${kubectl_cmd} get pods | grep ${check_pod}
echo
}
# Iterate through the commandline options
while getopts ac:i:k:n:p:stu:-: gopts
do
case ${gopts} in
-)
case "${OPTARG}" in
timeout=*)
timeout=${OPTARG#*=}
if [ -z "${timeout}" ]; then
usage
fi
;;
*)
if [ "${OPTERR}" == 1 ] && [ "${OPTSPEC:0:1}" != ":" ]; then
echo "Unknown option --${OPTARG}" >&2
usage
fi
;;
esac
;;
a)
non_interactive=1
;;
c)
cluster_type="${OPTARG}"
check_cluster_type
;;
i)
KRUIZE_DOCKER_IMAGE="${OPTARG}"
;;
k)
kurl="${OPTARG}"
;;
n)
kruize_ns="${OPTARG}"
;;
p)
password="${OPTARG}"
;;
s)
setup=1
;;
t)
setup=0
;;
u)
user="${OPTARG}"
;;
[?])
usage
esac
done
# Call the proper setup function based on the cluster_type
if [ ${setup} == 1 ]; then
${cluster_type}_start
else
${cluster_type}_terminate
fi