forked from metal3-io/metal3-dev-env
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_launch_mgmt_cluster.sh
executable file
·182 lines (160 loc) · 4.96 KB
/
03_launch_mgmt_cluster.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
175
176
177
178
179
180
181
182
#!/bin/bash
set -xe
# shellcheck disable=SC1091
source lib/logging.sh
# shellcheck disable=SC1091
source lib/common.sh
eval "$(go env)"
export GOPATH
# Environment variables
# M3PATH : Path to clone the metal3 dev env repo
# BMOPATH : Path to clone the baremetal operator repo
# CAPBMPATH: Path to clone the CAPI operator repo
#
# BMOREPO : Baremetal operator repository URL
# BMOBRANCH : Baremetal operator repository branch to checkout
# CAPBMREPO : CAPI operator repository URL
# CAPBMBRANCH : CAPI repository branch to checkout
# FORCE_REPO_UPDATE : discard existing directories
#
# BMO_RUN_LOCAL : run the baremetal operator locally (not in Kubernetes cluster)
# CAPBM_RUN_LOCAL : run the CAPI operator locally
M3PATH="${GOPATH}/src/github.com/metal3-io"
BMOPATH="${M3PATH}/baremetal-operator"
CAPBMPATH="${M3PATH}/cluster-api-provider-baremetal"
CAPIPATH="${M3PATH}/cluster-api"
CABPKPATH="${M3PATH}/cluster-api-bootstrap-provider-kubeadm"
BMOREPO="${BMOREPO:-https://github.com/metal3-io/baremetal-operator.git}"
BMOBRANCH="${BMOBRANCH:-master}"
CAPBMREPO="${CAPBMREPO:-https://github.com/metal3-io/cluster-api-provider-baremetal.git}"
CAPBMBRANCH="${CAPBMBRANCH:-master}"
CAPIREPO="${CAPIREPO:-https://github.com/kubernetes-sigs/cluster-api.git}"
CAPIBRANCH="${CAPIBRANCH:-master}"
CABPKREPO="${CABPKREPO:-https://github.com/kubernetes-sigs/cluster-api-bootstrap-provider-kubeadm.git}"
CABPKBRANCH="${CABPKBRANCH:-master}"
FORCE_REPO_UPDATE="${FORCE_REPO_UPDATE:-false}"
BMO_RUN_LOCAL="${BMO_RUN_LOCAL:-false}"
CAPBM_RUN_LOCAL="${CAPBM_RUN_LOCAL:-false}"
function clone_repos() {
mkdir -p "${M3PATH}"
if [[ -d ${BMOPATH} && "${FORCE_REPO_UPDATE}" == "true" ]]; then
rm -rf "${BMOPATH}"
fi
if [ ! -d "${BMOPATH}" ] ; then
pushd "${M3PATH}"
git clone "${BMOREPO}"
popd
fi
pushd "${BMOPATH}"
git checkout "${BMOBRANCH}"
git pull -r || true
popd
if [[ -d "${CAPBMPATH}" && "${FORCE_REPO_UPDATE}" == "true" ]]; then
rm -rf "${CAPBMPATH}"
fi
if [ ! -d "${CAPBMPATH}" ] ; then
pushd "${M3PATH}"
git clone "${CAPBMREPO}"
popd
fi
pushd "${CAPBMPATH}"
git checkout "${CAPBMBRANCH}"
git pull -r || true
popd
if [[ -d "${CAPIPATH}" && "${FORCE_REPO_UPDATE}" == "true" ]]; then
rm -rf "${CAPIPATH}"
fi
if [ ! -d "${CAPIPATH}" ] ; then
pushd "${M3PATH}"
git clone "${CAPIREPO}"
popd
fi
pushd "${CAPIPATH}"
git checkout "${CAPIBRANCH}"
git pull -r || true
popd
if [[ -d "${CABPKPATH}" && "${FORCE_REPO_UPDATE}" == "true" ]]; then
rm -rf "${CABPKPATH}"
fi
if [ ! -d "${CABPKPATH}" ] ; then
pushd "${M3PATH}"
git clone "${CABPKREPO}"
popd
fi
pushd "${CABPKPATH}"
git checkout "${CABPKBRANCH}"
git pull -r || true
popd
}
function launch_baremetal_operator() {
pushd "${BMOPATH}"
if [ "${BMO_RUN_LOCAL}" = true ]; then
touch bmo.out.log
touch bmo.err.log
make deploy
kubectl scale deployment metal3-baremetal-operator -n metal3 --replicas=0
nohup make run >> bmo.out.log 2>>bmo.err.log &
else
make deploy
fi
popd
}
function make_bm_hosts() {
while read -r name address user password mac; do
go run "${BMOPATH}"/cmd/make-bm-worker/main.go \
-address "$address" \
-password "$password" \
-user "$user" \
-boot-mac "$mac" \
"$name"
done
}
function apply_bm_hosts() {
list_nodes | make_bm_hosts > bmhosts_crs.yaml
kubectl apply -f bmhosts_crs.yaml -n metal3
}
#
# Launch the cluster-api controller manager (v1alpha1) in the metal3 namespace.
#
function launch_cluster_api_provider_baremetal() {
pushd "${CAPBMPATH}"
if [ "${CAPBM_RUN_LOCAL}" = true ]; then
touch capbm.out.log
touch capbm.err.log
make deploy
kubectl scale statefulset cluster-api-provider-baremetal-controller-manager -n metal3 --replicas=0
nohup make run >> capbm.out.log 2>> capbm.err.log &
else
make deploy
fi
popd
}
#
# Launch the cluster-api-controller manager (v1alpha2) in the system namespace.
#
function launch_core_cluster_api() {
pushd "${CAPIPATH}"
make generate
sed -i'' 's/capi-system/metal3/' config/default/kustomization.yaml
kustomize build config/default | kubectl apply -f -
popd
}
#
# Launch the cluster-api-bootstrap-provider-kubeadm-controller manager (v1alpha2) in the metal3 namespace.
#
function launch_cluster_api_bootstrap_provider_kubeadm() {
pushd "${CABPKPATH}"
sed -i'' 's/cabpk-system/metal3/' config/default/kustomization.yaml
make deploy
popd
}
clone_repos
sudo su -l -c 'minikube start' "${USER}"
sudo su -l -c 'minikube ssh sudo ip addr add 172.22.0.2/24 dev eth2' "${USER}"
launch_baremetal_operator
apply_bm_hosts
launch_cluster_api_provider_baremetal
if [ "${V1ALPHA2_SWITCH}" == true ]; then
launch_core_cluster_api
launch_cluster_api_bootstrap_provider_kubeadm
fi