blob: 081e515e55fb5827341bbdb72913022c589c0dcc [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}
Vasyl Saienko92133c02024-05-16 10:18:51 +030056KUBERNETES_CONTAINER_RUNTIME=${KUBERNETES_CONTAINER_RUNTIME:-$kubernetes_container_runtime}
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030057
58DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-$devops_utils_refspec}
59
60#
61# End of block
62#
63
64DEVOPS_UTILS_REPO=${DEVOPS_UTILS_REPO:-'https://gerrit.mcp.mirantis.com/oscore-tools/devops-utils'}
65DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-'master'}
66DEVOPS_UTILS_DST=/usr/share/devops-utils
67
68#Wait external network
Vasyl Saienko59425522024-05-17 14:00:19 +030069netplan apply
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030070systemctl restart systemd-resolved
Vasyl Saienko59425522024-05-17 14:00:19 +030071sleep 15
72curl --connect-timeout 10 --retry 12 --retry-delay 10 ${DEVOPS_UTILS_REPO} || (sleep 1; /bin/false)
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030073
Vasyl Saienko183863f2024-05-18 14:18:39 +030074if [[ ! -d ${DEVOPS_UTILS_DST} ]]; then
75 git clone ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_DST}
76fi
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030077pushd ${DEVOPS_UTILS_DST}
78if echo "$DEVOPS_UTILS_REFSPEC" |grep -q "^refs"; then
79 git fetch ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_REFSPEC}
80 git checkout FETCH_HEAD
81else
82 git checkout ${DEVOPS_UTILS_REFSPEC}
83fi
84git log --oneline -10
85popd
86
87
88source ${DEVOPS_UTILS_DST}/de/heat-templates/scripts/functions.sh
89
90function wait_condition_send {
91 local status=${1:-SUCCESS}
92 local reason=${2:-\"empty\"}
93 local data=${3:-\"empty\"}
94 local data_binary="{\"status\": \"$status\", \"reason\": \"$reason\", \"data\": $data}"
95 echo "Trying to send signal to wait condition 5 times: $data_binary"
96 WAIT_CONDITION_NOTIFY_EXIT_CODE=2
97 i=0
98 while (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} != 0 && ${i} < 5 )); do
99 $wait_condition_notify -k --data-binary "$data_binary" && WAIT_CONDITION_NOTIFY_EXIT_CODE=0 || WAIT_CONDITION_NOTIFY_EXIT_CODE=2
100 i=$((i + 1))
101 sleep 1
102 done
103 if (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} !=0 && "${status}" == "SUCCESS" ))
104 then
105 status="FAILURE"
106 reason="Can't reach metadata service to report about SUCCESS."
107 fi
108 if [ "$status" == "FAILURE" ]; then
109 exit 1
110 fi
111}
112
113# Exit on any errors
114function handle_exit {
115 if [ $? != 0 ] ; then
116 wait_condition_send "FAILURE" "Script terminated with an error."
117 fi
118}
119trap handle_exit EXIT
120
121if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
122 case "$NODE_TYPE" in
123 # Please keep the "prepare_metadata_files", "disable-rp-filter", "network_config" and "prepare_network" functions
124 # at the very beginning in the same order.
125 ucp)
126 setup_bind_mounts
127 wait_for_external_network
128 prepare_metadata_files
129 disable_rp_filter
130 network_config
131 prepare_network
132 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
133 prepare_docker_config
134 fi
135 install_required_packages
136 install_kubectl
137 configure_ntp
138 configure_atop
139 workaround_default_forward_policy
140 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
141 install_docker
142 swarm_init
143 create_ucp_config
144 cache_images
145 install_ucp
146 download_bundles
147 rm_ucp_config
148 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
149 download_k0s
150 install_k0s
151 fi
152 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
153 wait_for_node
154 set_node_labels
155 collect_ceph_metadata
156 configure_contrack
157 disable_iptables_for_bridges
158 fi
159 if [[ "${SINGLE_NODE}" == true ]]; then
160 nested_virt_config
161 disable_master_taint
162 collect_interfaces_metadata
163 fi
164 cron_disable_calico_offloading
165 ;;
166 master)
167 setup_bind_mounts
168 wait_for_external_network
169 nested_virt_config
170 prepare_metadata_files
171 disable_rp_filter
172 network_config
173 prepare_network
174 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
175 prepare_docker_config
176 fi
177 install_required_packages
178 install_kubectl
179 configure_ntp
180 configure_atop
181 workaround_default_forward_policy
182 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
183 install_docker
184 cache_images
185 download_bundles
186 join_node manager
187 fi
188 wait_for_node
189 set_node_labels
190 collect_ceph_metadata
191 configure_contrack
192 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
193 disable_iptables_for_bridges
194 fi
195 collect_interfaces_metadata
196 cron_disable_calico_offloading
197 increase_iscsi_timeout
198 ;;
199 worker)
200 setup_bind_mounts
201 wait_for_external_network
202 if [[ "${CONFIGURE_HUGE_PAGES}" == true ]]; then
203 configure_huge_pages
204 fi
205 nested_virt_config
206 prepare_metadata_files
207 disable_rp_filter
208 network_config
209 prepare_network
210 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
211 prepare_docker_config
212 fi
213 install_required_packages
214 install_kubectl
215 enable_iscsi
216 configure_ntp
217 configure_atop
218 workaround_default_forward_policy
219 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
220 install_docker
221 cache_images
222 download_bundles
223 join_node worker
224 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
225 download_k0s
226 download_k8s_metadata
227 join_k0s_node worker
228 fi
229 wait_for_node
230 set_node_labels
231 collect_ceph_metadata
232 configure_contrack
233 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
234 disable_iptables_for_bridges
235 fi
236 collect_interfaces_metadata
237 configure_lvm
238 cron_disable_calico_offloading
239 increase_iscsi_timeout
240 ;;
241 frr)
242 wait_for_external_network
243 prepare_metadata_files
244 disable_rp_filter
245 network_config
246 prepare_network
247 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
248 prepare_docker_config
249 fi
250 install_required_packages
251 configure_ntp
252 configure_atop
253 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
254 install_docker
255 cache_images
256 download_bundles
257 fi
258 workaround_default_forward_policy
259 configure_contrack
260 disable_iptables_for_bridges
261 install_frr
262 cron_disable_calico_offloading
263 increase_iscsi_timeout
264 ;;
265 *)
266 echo "Usage: $0 {ucp|master|worker}"
267 exit 1
268 esac
269
270 wait_condition_send "SUCCESS" "Instance successfuly started." "${HW_METADATA}"
271fi