blob: 5a89193f184e2d05fa7a8a4c9d18b802e9a725c9 [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}
Vasyl Saienko3e8ba732024-09-09 14:07:49 +030059K0S_VERSION=${K0S_VERSION:-$k0s_version}
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030060#
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)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000126 configure_sysctl_limits
Vasyl Saienkof9813512024-07-02 12:30:25 +0300127 configure_logind_conf
dbiletskiy70af8192024-06-19 09:27:10 +0200128 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300129 setup_bind_mounts
130 wait_for_external_network
131 prepare_metadata_files
132 disable_rp_filter
133 network_config
134 prepare_network
135 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
136 prepare_docker_config
137 fi
138 install_required_packages
139 install_kubectl
140 configure_ntp
141 configure_atop
142 workaround_default_forward_policy
143 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
144 install_docker
145 swarm_init
146 create_ucp_config
147 cache_images
148 install_ucp
149 download_bundles
150 rm_ucp_config
151 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
152 download_k0s
153 install_k0s
154 fi
Vasyl Saienko59e5b2a2024-09-09 08:57:18 +0300155 wait_for_node
156 set_node_labels
157 collect_ceph_metadata
158 configure_contrack
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300159 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300160 disable_iptables_for_bridges
161 fi
162 if [[ "${SINGLE_NODE}" == true ]]; then
163 nested_virt_config
Vasyl Saienko59e5b2a2024-09-09 08:57:18 +0300164 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
165 disable_master_taint
166 fi
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300167 collect_interfaces_metadata
168 fi
169 cron_disable_calico_offloading
170 ;;
171 master)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000172 configure_sysctl_limits
Vasyl Saienkof9813512024-07-02 12:30:25 +0300173 configure_logind_conf
dbiletskiy70af8192024-06-19 09:27:10 +0200174 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300175 setup_bind_mounts
176 wait_for_external_network
177 nested_virt_config
178 prepare_metadata_files
179 disable_rp_filter
180 network_config
181 prepare_network
182 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
183 prepare_docker_config
184 fi
185 install_required_packages
186 install_kubectl
187 configure_ntp
188 configure_atop
189 workaround_default_forward_policy
190 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
191 install_docker
192 cache_images
193 download_bundles
194 join_node manager
195 fi
196 wait_for_node
197 set_node_labels
198 collect_ceph_metadata
199 configure_contrack
200 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
201 disable_iptables_for_bridges
202 fi
203 collect_interfaces_metadata
204 cron_disable_calico_offloading
205 increase_iscsi_timeout
206 ;;
207 worker)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000208 configure_sysctl_limits
Vasyl Saienkof9813512024-07-02 12:30:25 +0300209 configure_logind_conf
dbiletskiy70af8192024-06-19 09:27:10 +0200210 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300211 setup_bind_mounts
212 wait_for_external_network
213 if [[ "${CONFIGURE_HUGE_PAGES}" == true ]]; then
214 configure_huge_pages
215 fi
216 nested_virt_config
217 prepare_metadata_files
218 disable_rp_filter
219 network_config
220 prepare_network
221 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
222 prepare_docker_config
223 fi
224 install_required_packages
225 install_kubectl
226 enable_iscsi
227 configure_ntp
228 configure_atop
229 workaround_default_forward_policy
230 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
231 install_docker
232 cache_images
233 download_bundles
234 join_node worker
235 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
236 download_k0s
237 download_k8s_metadata
238 join_k0s_node worker
239 fi
240 wait_for_node
241 set_node_labels
242 collect_ceph_metadata
243 configure_contrack
244 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
245 disable_iptables_for_bridges
246 fi
247 collect_interfaces_metadata
248 configure_lvm
249 cron_disable_calico_offloading
250 increase_iscsi_timeout
251 ;;
252 frr)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000253 configure_sysctl_limits
dbiletskiy70af8192024-06-19 09:27:10 +0200254 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300255 wait_for_external_network
256 prepare_metadata_files
257 disable_rp_filter
258 network_config
259 prepare_network
260 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
261 prepare_docker_config
262 fi
263 install_required_packages
264 configure_ntp
265 configure_atop
266 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
267 install_docker
268 cache_images
269 download_bundles
270 fi
271 workaround_default_forward_policy
272 configure_contrack
273 disable_iptables_for_bridges
274 install_frr
275 cron_disable_calico_offloading
276 increase_iscsi_timeout
277 ;;
278 *)
279 echo "Usage: $0 {ucp|master|worker}"
280 exit 1
281 esac
282
283 wait_condition_send "SUCCESS" "Instance successfuly started." "${HW_METADATA}"
284fi