blob: 09c40687918e850d05a8108931c4e7e2e5178678 [file] [log] [blame]
Vasyl Saienko4a2832d2024-05-16 09:00:03 +03001#!/bin/bash
2set -x
3set -e
4# allow access to the local variables from prepare-metadata.py
5set -a
6
7# ensure we don't re-source this in the same environment
8[[ -z "$_INSTALL_SCRIPT" ]] || return 0
9declare -r -g _INSTALL_SCRIPT=1
10
11#
12# Variables in this block are passed from heat template
13#
14CONTROL_NETWORK_CIDR=${CONTROL_NETWORK_CIDR:-$control_network_cidr}
15PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$private_floating_interface}
16PUBLIC_INTERFACE_IP=${PUBLIC_INTERFACE_IP:-$private_floating_interface_ip}
17PUBLIC_INTERFACE_CIDR=${PUBLIC_INTERFACE_CIDR:-$private_floating_network_cidr}
18DEFAULT_INTERFACE=${DEFAULT_INTERFACE:-$default_interface}
19STORAGE_BACKEND_INTERFACE=${STORAGE_BACKEND_INTERFACE:-$storage_backend_interface}
20STORAGE_BACKEND_INTERFACE_IP=${STORAGE_BACKEND_INTERFACE_IP:-$storage_backend_network_interface_ip}
21STORAGE_BACKEND_NETWORK=${STORAGE_BACKEND_NETWORK:-$storage_backend_network_cidr}
22STORAGE_FRONTEND_INTERFACE=${STORAGE_FRONTEND_INTERFACE:-$storage_frontend_interface}
23STORAGE_FRONTEND_INTERFACE_IP=${STORAGE_FRONTEND_INTERFACE_IP:-$storage_frontend_network_interface_ip}
24STORAGE_FRONTEND_NETWORK=${STORAGE_FRONTEND_NETWORK:-$storage_frontend_network_cidr}
25STORAGE_FRONTEND_NETWORK_NETMASK=$(echo ${STORAGE_FRONTEND_NETWORK} | cut -d'/' -f2)
26
27IRONIC_BAREMETAL_NETWORK=${IRONIC_BAREMETAL_NETWORK:-$ironic_baremetal_network_cidr}
28IRONIC_BAREMETAL_INTERFACE_IP=${IRONIC_BAREMETAL_INTERFACE_IP:-$ironic_baremetal_interface_ip}
29IRONIC_BAREMETAL_TUNNEL_NETWORK=${IRONIC_BAREMETAL_TUNNEL_NETWORK:-$ironic_baremetal_tunnel_cidr}
30TUNNEL_INTERFACE_IP=${TUNNEL_INTERFACE_IP:-$tunnel_interface_ip}
31FRR_BGP_NEIGHBORS=${FRR_BGP_NEIGHBORS:-$frr_bgp_neighbors}
32FRR_EVPN_TUNNELS_RANGE=${FRR_EVPN_TUNNELS_RANGE:-$frr_evpn_tunnels_range}
33FRR_EVPN_VXLAN_DST_PORT=${FRR_EVPN_VXLAN_DST_PORT:-$frr_evpn_vxlan_dst_port}
34
35NODE_TYPE=${NODE_TYPE:-$node_type}
36KUBERNETES_INSTALLER=${KUBERNETES_INSTALLER:-$kubernetes_installer}
37UCP_MASTER_HOST=${UCP_MASTER_HOST:-$ucp_master_host}
38NODE_METADATA=${NODE_METADATA:-'$node_metadata'}
39DOCKER_EE_URL=${DOCKER_EE_URL:-$docker_ee_url}
40DOCKER_EE_RELEASE=${DOCKER_EE_RELEASE:-$docker_ee_release}
41DOCKER_EE_PACKAGES=${DOCKER_EE_PACKAGES:-$docker_ee_packages}
42DOCKER_UCP_IMAGE=${DOCKER_UCP_IMAGE:-$docker_ucp_image}
43BINARY_BASE_URL=${BINARY_BASE_URL:-$binary_base_url}
44UCP_DOCKER_SWARM_DATA_PORT=${UCP_DOCKER_SWARM_DATA_PORT:-$docker_ucp_swarm_data_port}
45FLOATING_NETWORK_PREFIXES=${FLOATING_NETWORK_PREFIXES:-$private_floating_network_cidr}
46IRONIC_MT_ENABLED=${IRONIC_MT_ENABLED:-$ironic_mt_enabled}
47
48HUGE_PAGES=${HUGE_PAGES:-$huge_pages}
49TUNGSTENFABRIC_ENABLED=${TUNGSTENFABRIC_ENABLED:-$tungstenfabric_enabled}
50SINGLE_NODE=${SINGLE_NODE:-$single_node}
51DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL:-$docker_default_address_pool}
52LVM_LOOP_DEVICE_SIZE=${LVM_LOOP_DEVICE_SIZE:-$lvm_loop_device_size}
53CINDER_LVM_LOOP_DEVICE_SIZE=${CINDER_LVM_LOOP_DEVICE_SIZE:-$cinder_lvm_loop_device_size}
54SECURE_OVERLAY_ENABLED=${SECURE_OVERLAY_ENABLED:-$secure_overlay_enabled}
55KUBECTL_VERSION=${KUBECTL_VERSION:-$kubectl_version}
56
57DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-$devops_utils_refspec}
58
59#
60# End of block
61#
62
63DEVOPS_UTILS_REPO=${DEVOPS_UTILS_REPO:-'https://gerrit.mcp.mirantis.com/oscore-tools/devops-utils'}
64DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-'master'}
65DEVOPS_UTILS_DST=/usr/share/devops-utils
66
67#Wait external network
68sed -i 's/#DNS=/DNS=4.2.2.1/g' /etc/systemd/resolved.conf
69systemctl restart systemd-resolved
70curl --connect-timeout 10 --retry 6 --retry-delay 10 ${DEVOPS_UTILS_REPO} || (sleep 1; /bin/false)
71
72git clone ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_DST}
73pushd ${DEVOPS_UTILS_DST}
74if echo "$DEVOPS_UTILS_REFSPEC" |grep -q "^refs"; then
75 git fetch ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_REFSPEC}
76 git checkout FETCH_HEAD
77else
78 git checkout ${DEVOPS_UTILS_REFSPEC}
79fi
80git log --oneline -10
81popd
82
83
84source ${DEVOPS_UTILS_DST}/de/heat-templates/scripts/functions.sh
85
86function wait_condition_send {
87 local status=${1:-SUCCESS}
88 local reason=${2:-\"empty\"}
89 local data=${3:-\"empty\"}
90 local data_binary="{\"status\": \"$status\", \"reason\": \"$reason\", \"data\": $data}"
91 echo "Trying to send signal to wait condition 5 times: $data_binary"
92 WAIT_CONDITION_NOTIFY_EXIT_CODE=2
93 i=0
94 while (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} != 0 && ${i} < 5 )); do
95 $wait_condition_notify -k --data-binary "$data_binary" && WAIT_CONDITION_NOTIFY_EXIT_CODE=0 || WAIT_CONDITION_NOTIFY_EXIT_CODE=2
96 i=$((i + 1))
97 sleep 1
98 done
99 if (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} !=0 && "${status}" == "SUCCESS" ))
100 then
101 status="FAILURE"
102 reason="Can't reach metadata service to report about SUCCESS."
103 fi
104 if [ "$status" == "FAILURE" ]; then
105 exit 1
106 fi
107}
108
109# Exit on any errors
110function handle_exit {
111 if [ $? != 0 ] ; then
112 wait_condition_send "FAILURE" "Script terminated with an error."
113 fi
114}
115trap handle_exit EXIT
116
117if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
118 case "$NODE_TYPE" in
119 # Please keep the "prepare_metadata_files", "disable-rp-filter", "network_config" and "prepare_network" functions
120 # at the very beginning in the same order.
121 ucp)
122 setup_bind_mounts
123 wait_for_external_network
124 prepare_metadata_files
125 disable_rp_filter
126 network_config
127 prepare_network
128 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
129 prepare_docker_config
130 fi
131 install_required_packages
132 install_kubectl
133 configure_ntp
134 configure_atop
135 workaround_default_forward_policy
136 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
137 install_docker
138 swarm_init
139 create_ucp_config
140 cache_images
141 install_ucp
142 download_bundles
143 rm_ucp_config
144 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
145 download_k0s
146 install_k0s
147 fi
148 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
149 wait_for_node
150 set_node_labels
151 collect_ceph_metadata
152 configure_contrack
153 disable_iptables_for_bridges
154 fi
155 if [[ "${SINGLE_NODE}" == true ]]; then
156 nested_virt_config
157 disable_master_taint
158 collect_interfaces_metadata
159 fi
160 cron_disable_calico_offloading
161 ;;
162 master)
163 setup_bind_mounts
164 wait_for_external_network
165 nested_virt_config
166 prepare_metadata_files
167 disable_rp_filter
168 network_config
169 prepare_network
170 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
171 prepare_docker_config
172 fi
173 install_required_packages
174 install_kubectl
175 configure_ntp
176 configure_atop
177 workaround_default_forward_policy
178 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
179 install_docker
180 cache_images
181 download_bundles
182 join_node manager
183 fi
184 wait_for_node
185 set_node_labels
186 collect_ceph_metadata
187 configure_contrack
188 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
189 disable_iptables_for_bridges
190 fi
191 collect_interfaces_metadata
192 cron_disable_calico_offloading
193 increase_iscsi_timeout
194 ;;
195 worker)
196 setup_bind_mounts
197 wait_for_external_network
198 if [[ "${CONFIGURE_HUGE_PAGES}" == true ]]; then
199 configure_huge_pages
200 fi
201 nested_virt_config
202 prepare_metadata_files
203 disable_rp_filter
204 network_config
205 prepare_network
206 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
207 prepare_docker_config
208 fi
209 install_required_packages
210 install_kubectl
211 enable_iscsi
212 configure_ntp
213 configure_atop
214 workaround_default_forward_policy
215 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
216 install_docker
217 cache_images
218 download_bundles
219 join_node worker
220 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
221 download_k0s
222 download_k8s_metadata
223 join_k0s_node worker
224 fi
225 wait_for_node
226 set_node_labels
227 collect_ceph_metadata
228 configure_contrack
229 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
230 disable_iptables_for_bridges
231 fi
232 collect_interfaces_metadata
233 configure_lvm
234 cron_disable_calico_offloading
235 increase_iscsi_timeout
236 ;;
237 frr)
238 wait_for_external_network
239 prepare_metadata_files
240 disable_rp_filter
241 network_config
242 prepare_network
243 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
244 prepare_docker_config
245 fi
246 install_required_packages
247 configure_ntp
248 configure_atop
249 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
250 install_docker
251 cache_images
252 download_bundles
253 fi
254 workaround_default_forward_policy
255 configure_contrack
256 disable_iptables_for_bridges
257 install_frr
258 cron_disable_calico_offloading
259 increase_iscsi_timeout
260 ;;
261 *)
262 echo "Usage: $0 {ucp|master|worker}"
263 exit 1
264 esac
265
266 wait_condition_send "SUCCESS" "Instance successfuly started." "${HW_METADATA}"
267fi