blob: 66d3a13386f19f1c0717d474184f6b6a65bb67f3 [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)
dbiletskiy70af8192024-06-19 09:27:10 +0200126 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300127 setup_bind_mounts
128 wait_for_external_network
129 prepare_metadata_files
130 disable_rp_filter
131 network_config
132 prepare_network
133 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
134 prepare_docker_config
135 fi
136 install_required_packages
137 install_kubectl
138 configure_ntp
139 configure_atop
140 workaround_default_forward_policy
141 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
142 install_docker
143 swarm_init
144 create_ucp_config
145 cache_images
146 install_ucp
147 download_bundles
148 rm_ucp_config
149 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
150 download_k0s
151 install_k0s
152 fi
153 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
154 wait_for_node
155 set_node_labels
156 collect_ceph_metadata
157 configure_contrack
158 disable_iptables_for_bridges
159 fi
160 if [[ "${SINGLE_NODE}" == true ]]; then
161 nested_virt_config
162 disable_master_taint
163 collect_interfaces_metadata
164 fi
165 cron_disable_calico_offloading
166 ;;
167 master)
dbiletskiy70af8192024-06-19 09:27:10 +0200168 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300169 setup_bind_mounts
170 wait_for_external_network
171 nested_virt_config
172 prepare_metadata_files
173 disable_rp_filter
174 network_config
175 prepare_network
176 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
177 prepare_docker_config
178 fi
179 install_required_packages
180 install_kubectl
181 configure_ntp
182 configure_atop
183 workaround_default_forward_policy
184 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
185 install_docker
186 cache_images
187 download_bundles
188 join_node manager
189 fi
190 wait_for_node
191 set_node_labels
192 collect_ceph_metadata
193 configure_contrack
194 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
195 disable_iptables_for_bridges
196 fi
197 collect_interfaces_metadata
198 cron_disable_calico_offloading
199 increase_iscsi_timeout
200 ;;
201 worker)
dbiletskiy70af8192024-06-19 09:27:10 +0200202 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300203 setup_bind_mounts
204 wait_for_external_network
205 if [[ "${CONFIGURE_HUGE_PAGES}" == true ]]; then
206 configure_huge_pages
207 fi
208 nested_virt_config
209 prepare_metadata_files
210 disable_rp_filter
211 network_config
212 prepare_network
213 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
214 prepare_docker_config
215 fi
216 install_required_packages
217 install_kubectl
218 enable_iscsi
219 configure_ntp
220 configure_atop
221 workaround_default_forward_policy
222 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
223 install_docker
224 cache_images
225 download_bundles
226 join_node worker
227 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
228 download_k0s
229 download_k8s_metadata
230 join_k0s_node worker
231 fi
232 wait_for_node
233 set_node_labels
234 collect_ceph_metadata
235 configure_contrack
236 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
237 disable_iptables_for_bridges
238 fi
239 collect_interfaces_metadata
240 configure_lvm
241 cron_disable_calico_offloading
242 increase_iscsi_timeout
243 ;;
244 frr)
dbiletskiy70af8192024-06-19 09:27:10 +0200245 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300246 wait_for_external_network
247 prepare_metadata_files
248 disable_rp_filter
249 network_config
250 prepare_network
251 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
252 prepare_docker_config
253 fi
254 install_required_packages
255 configure_ntp
256 configure_atop
257 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
258 install_docker
259 cache_images
260 download_bundles
261 fi
262 workaround_default_forward_policy
263 configure_contrack
264 disable_iptables_for_bridges
265 install_frr
266 cron_disable_calico_offloading
267 increase_iscsi_timeout
268 ;;
269 *)
270 echo "Usage: $0 {ucp|master|worker}"
271 exit 1
272 esac
273
274 wait_condition_send "SUCCESS" "Instance successfuly started." "${HW_METADATA}"
275fi