blob: 21bd2059ec41a4ab67fb80ef2ae21c0355cebad3 [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}
Mykyta Karpin9df830a2024-09-12 14:25:01 +020045UCP_AUDIT_LOG_LEVEL=${UCP_AUDIT_LOG_LEVEL:-$ucp_audit_log_level}
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030046FLOATING_NETWORK_PREFIXES=${FLOATING_NETWORK_PREFIXES:-$private_floating_network_cidr}
47IRONIC_MT_ENABLED=${IRONIC_MT_ENABLED:-$ironic_mt_enabled}
48
49HUGE_PAGES=${HUGE_PAGES:-$huge_pages}
50TUNGSTENFABRIC_ENABLED=${TUNGSTENFABRIC_ENABLED:-$tungstenfabric_enabled}
51SINGLE_NODE=${SINGLE_NODE:-$single_node}
52DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL:-$docker_default_address_pool}
53LVM_LOOP_DEVICE_SIZE=${LVM_LOOP_DEVICE_SIZE:-$lvm_loop_device_size}
54CINDER_LVM_LOOP_DEVICE_SIZE=${CINDER_LVM_LOOP_DEVICE_SIZE:-$cinder_lvm_loop_device_size}
55SECURE_OVERLAY_ENABLED=${SECURE_OVERLAY_ENABLED:-$secure_overlay_enabled}
56KUBECTL_VERSION=${KUBECTL_VERSION:-$kubectl_version}
Vasyl Saienko92133c02024-05-16 10:18:51 +030057KUBERNETES_CONTAINER_RUNTIME=${KUBERNETES_CONTAINER_RUNTIME:-$kubernetes_container_runtime}
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030058
59DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-$devops_utils_refspec}
Vasyl Saienko3e8ba732024-09-09 14:07:49 +030060K0S_VERSION=${K0S_VERSION:-$k0s_version}
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030061#
62# End of block
63#
64
65DEVOPS_UTILS_REPO=${DEVOPS_UTILS_REPO:-'https://gerrit.mcp.mirantis.com/oscore-tools/devops-utils'}
66DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-'master'}
67DEVOPS_UTILS_DST=/usr/share/devops-utils
68
69#Wait external network
Vasyl Saienko59425522024-05-17 14:00:19 +030070netplan apply
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030071systemctl restart systemd-resolved
Vasyl Saienko59425522024-05-17 14:00:19 +030072sleep 15
73curl --connect-timeout 10 --retry 12 --retry-delay 10 ${DEVOPS_UTILS_REPO} || (sleep 1; /bin/false)
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030074
Vasyl Saienko183863f2024-05-18 14:18:39 +030075if [[ ! -d ${DEVOPS_UTILS_DST} ]]; then
76 git clone ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_DST}
77fi
Vasyl Saienko4a2832d2024-05-16 09:00:03 +030078pushd ${DEVOPS_UTILS_DST}
79if echo "$DEVOPS_UTILS_REFSPEC" |grep -q "^refs"; then
80 git fetch ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_REFSPEC}
81 git checkout FETCH_HEAD
82else
83 git checkout ${DEVOPS_UTILS_REFSPEC}
84fi
85git log --oneline -10
86popd
87
88
89source ${DEVOPS_UTILS_DST}/de/heat-templates/scripts/functions.sh
90
91function wait_condition_send {
92 local status=${1:-SUCCESS}
93 local reason=${2:-\"empty\"}
94 local data=${3:-\"empty\"}
95 local data_binary="{\"status\": \"$status\", \"reason\": \"$reason\", \"data\": $data}"
96 echo "Trying to send signal to wait condition 5 times: $data_binary"
97 WAIT_CONDITION_NOTIFY_EXIT_CODE=2
98 i=0
99 while (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} != 0 && ${i} < 5 )); do
100 $wait_condition_notify -k --data-binary "$data_binary" && WAIT_CONDITION_NOTIFY_EXIT_CODE=0 || WAIT_CONDITION_NOTIFY_EXIT_CODE=2
101 i=$((i + 1))
102 sleep 1
103 done
104 if (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} !=0 && "${status}" == "SUCCESS" ))
105 then
106 status="FAILURE"
107 reason="Can't reach metadata service to report about SUCCESS."
108 fi
109 if [ "$status" == "FAILURE" ]; then
110 exit 1
111 fi
112}
113
114# Exit on any errors
115function handle_exit {
116 if [ $? != 0 ] ; then
117 wait_condition_send "FAILURE" "Script terminated with an error."
118 fi
119}
120trap handle_exit EXIT
121
122if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
123 case "$NODE_TYPE" in
124 # Please keep the "prepare_metadata_files", "disable-rp-filter", "network_config" and "prepare_network" functions
125 # at the very beginning in the same order.
126 ucp)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000127 configure_sysctl_limits
Vasyl Saienkof9813512024-07-02 12:30:25 +0300128 configure_logind_conf
dbiletskiy70af8192024-06-19 09:27:10 +0200129 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300130 setup_bind_mounts
131 wait_for_external_network
132 prepare_metadata_files
133 disable_rp_filter
134 network_config
135 prepare_network
136 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
137 prepare_docker_config
138 fi
139 install_required_packages
140 install_kubectl
141 configure_ntp
142 configure_atop
143 workaround_default_forward_policy
144 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
145 install_docker
146 swarm_init
147 create_ucp_config
148 cache_images
149 install_ucp
150 download_bundles
151 rm_ucp_config
152 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
153 download_k0s
154 install_k0s
155 fi
Vasyl Saienko59e5b2a2024-09-09 08:57:18 +0300156 wait_for_node
157 set_node_labels
158 collect_ceph_metadata
159 configure_contrack
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300160 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300161 disable_iptables_for_bridges
162 fi
163 if [[ "${SINGLE_NODE}" == true ]]; then
164 nested_virt_config
Vasyl Saienko59e5b2a2024-09-09 08:57:18 +0300165 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
166 disable_master_taint
167 fi
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300168 collect_interfaces_metadata
169 fi
170 cron_disable_calico_offloading
171 ;;
172 master)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000173 configure_sysctl_limits
Vasyl Saienkof9813512024-07-02 12:30:25 +0300174 configure_logind_conf
dbiletskiy70af8192024-06-19 09:27:10 +0200175 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300176 setup_bind_mounts
177 wait_for_external_network
178 nested_virt_config
179 prepare_metadata_files
180 disable_rp_filter
181 network_config
182 prepare_network
183 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
184 prepare_docker_config
185 fi
186 install_required_packages
187 install_kubectl
188 configure_ntp
189 configure_atop
190 workaround_default_forward_policy
191 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
192 install_docker
193 cache_images
194 download_bundles
195 join_node manager
196 fi
197 wait_for_node
198 set_node_labels
199 collect_ceph_metadata
200 configure_contrack
201 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
202 disable_iptables_for_bridges
203 fi
204 collect_interfaces_metadata
205 cron_disable_calico_offloading
206 increase_iscsi_timeout
207 ;;
208 worker)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000209 configure_sysctl_limits
Vasyl Saienkof9813512024-07-02 12:30:25 +0300210 configure_logind_conf
dbiletskiy70af8192024-06-19 09:27:10 +0200211 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300212 setup_bind_mounts
213 wait_for_external_network
214 if [[ "${CONFIGURE_HUGE_PAGES}" == true ]]; then
215 configure_huge_pages
216 fi
217 nested_virt_config
218 prepare_metadata_files
219 disable_rp_filter
220 network_config
221 prepare_network
222 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
223 prepare_docker_config
224 fi
225 install_required_packages
226 install_kubectl
227 enable_iscsi
228 configure_ntp
229 configure_atop
230 workaround_default_forward_policy
231 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
232 install_docker
233 cache_images
234 download_bundles
235 join_node worker
236 elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then
237 download_k0s
238 download_k8s_metadata
239 join_k0s_node worker
240 fi
241 wait_for_node
242 set_node_labels
243 collect_ceph_metadata
244 configure_contrack
245 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
246 disable_iptables_for_bridges
247 fi
248 collect_interfaces_metadata
249 configure_lvm
250 cron_disable_calico_offloading
251 increase_iscsi_timeout
252 ;;
253 frr)
Vasyl Saienko45280eb2024-06-24 11:45:13 +0000254 configure_sysctl_limits
dbiletskiy70af8192024-06-19 09:27:10 +0200255 disable_unattended_upgr
Vasyl Saienko4a2832d2024-05-16 09:00:03 +0300256 wait_for_external_network
257 prepare_metadata_files
258 disable_rp_filter
259 network_config
260 prepare_network
261 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
262 prepare_docker_config
263 fi
264 install_required_packages
265 configure_ntp
266 configure_atop
267 if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then
268 install_docker
269 cache_images
270 download_bundles
271 fi
272 workaround_default_forward_policy
273 configure_contrack
274 disable_iptables_for_bridges
275 install_frr
276 cron_disable_calico_offloading
277 increase_iscsi_timeout
278 ;;
279 *)
280 echo "Usage: $0 {ucp|master|worker}"
281 exit 1
282 esac
283
284 wait_condition_send "SUCCESS" "Instance successfuly started." "${HW_METADATA}"
285fi