Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -x |
| 3 | set -e |
| 4 | # allow access to the local variables from prepare-metadata.py |
| 5 | set -a |
| 6 | |
| 7 | # ensure we don't re-source this in the same environment |
| 8 | [[ -z "$_INSTALL_SCRIPT" ]] || return 0 |
| 9 | declare -r -g _INSTALL_SCRIPT=1 |
| 10 | |
| 11 | # |
| 12 | # Variables in this block are passed from heat template |
| 13 | # |
| 14 | CONTROL_NETWORK_CIDR=${CONTROL_NETWORK_CIDR:-$control_network_cidr} |
| 15 | PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-$private_floating_interface} |
| 16 | PUBLIC_INTERFACE_IP=${PUBLIC_INTERFACE_IP:-$private_floating_interface_ip} |
| 17 | PUBLIC_INTERFACE_CIDR=${PUBLIC_INTERFACE_CIDR:-$private_floating_network_cidr} |
| 18 | DEFAULT_INTERFACE=${DEFAULT_INTERFACE:-$default_interface} |
| 19 | STORAGE_BACKEND_INTERFACE=${STORAGE_BACKEND_INTERFACE:-$storage_backend_interface} |
| 20 | STORAGE_BACKEND_INTERFACE_IP=${STORAGE_BACKEND_INTERFACE_IP:-$storage_backend_network_interface_ip} |
| 21 | STORAGE_BACKEND_NETWORK=${STORAGE_BACKEND_NETWORK:-$storage_backend_network_cidr} |
| 22 | STORAGE_FRONTEND_INTERFACE=${STORAGE_FRONTEND_INTERFACE:-$storage_frontend_interface} |
| 23 | STORAGE_FRONTEND_INTERFACE_IP=${STORAGE_FRONTEND_INTERFACE_IP:-$storage_frontend_network_interface_ip} |
| 24 | STORAGE_FRONTEND_NETWORK=${STORAGE_FRONTEND_NETWORK:-$storage_frontend_network_cidr} |
| 25 | STORAGE_FRONTEND_NETWORK_NETMASK=$(echo ${STORAGE_FRONTEND_NETWORK} | cut -d'/' -f2) |
| 26 | |
| 27 | IRONIC_BAREMETAL_NETWORK=${IRONIC_BAREMETAL_NETWORK:-$ironic_baremetal_network_cidr} |
| 28 | IRONIC_BAREMETAL_INTERFACE_IP=${IRONIC_BAREMETAL_INTERFACE_IP:-$ironic_baremetal_interface_ip} |
| 29 | IRONIC_BAREMETAL_TUNNEL_NETWORK=${IRONIC_BAREMETAL_TUNNEL_NETWORK:-$ironic_baremetal_tunnel_cidr} |
| 30 | TUNNEL_INTERFACE_IP=${TUNNEL_INTERFACE_IP:-$tunnel_interface_ip} |
| 31 | FRR_BGP_NEIGHBORS=${FRR_BGP_NEIGHBORS:-$frr_bgp_neighbors} |
| 32 | FRR_EVPN_TUNNELS_RANGE=${FRR_EVPN_TUNNELS_RANGE:-$frr_evpn_tunnels_range} |
| 33 | FRR_EVPN_VXLAN_DST_PORT=${FRR_EVPN_VXLAN_DST_PORT:-$frr_evpn_vxlan_dst_port} |
| 34 | |
| 35 | NODE_TYPE=${NODE_TYPE:-$node_type} |
| 36 | KUBERNETES_INSTALLER=${KUBERNETES_INSTALLER:-$kubernetes_installer} |
| 37 | UCP_MASTER_HOST=${UCP_MASTER_HOST:-$ucp_master_host} |
| 38 | NODE_METADATA=${NODE_METADATA:-'$node_metadata'} |
| 39 | DOCKER_EE_URL=${DOCKER_EE_URL:-$docker_ee_url} |
| 40 | DOCKER_EE_RELEASE=${DOCKER_EE_RELEASE:-$docker_ee_release} |
| 41 | DOCKER_EE_PACKAGES=${DOCKER_EE_PACKAGES:-$docker_ee_packages} |
| 42 | DOCKER_UCP_IMAGE=${DOCKER_UCP_IMAGE:-$docker_ucp_image} |
| 43 | BINARY_BASE_URL=${BINARY_BASE_URL:-$binary_base_url} |
| 44 | UCP_DOCKER_SWARM_DATA_PORT=${UCP_DOCKER_SWARM_DATA_PORT:-$docker_ucp_swarm_data_port} |
Mykyta Karpin | 9df830a | 2024-09-12 14:25:01 +0200 | [diff] [blame] | 45 | UCP_AUDIT_LOG_LEVEL=${UCP_AUDIT_LOG_LEVEL:-$ucp_audit_log_level} |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 46 | FLOATING_NETWORK_PREFIXES=${FLOATING_NETWORK_PREFIXES:-$private_floating_network_cidr} |
| 47 | IRONIC_MT_ENABLED=${IRONIC_MT_ENABLED:-$ironic_mt_enabled} |
| 48 | |
| 49 | HUGE_PAGES=${HUGE_PAGES:-$huge_pages} |
| 50 | TUNGSTENFABRIC_ENABLED=${TUNGSTENFABRIC_ENABLED:-$tungstenfabric_enabled} |
| 51 | SINGLE_NODE=${SINGLE_NODE:-$single_node} |
| 52 | DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL:-$docker_default_address_pool} |
| 53 | LVM_LOOP_DEVICE_SIZE=${LVM_LOOP_DEVICE_SIZE:-$lvm_loop_device_size} |
| 54 | CINDER_LVM_LOOP_DEVICE_SIZE=${CINDER_LVM_LOOP_DEVICE_SIZE:-$cinder_lvm_loop_device_size} |
| 55 | SECURE_OVERLAY_ENABLED=${SECURE_OVERLAY_ENABLED:-$secure_overlay_enabled} |
| 56 | KUBECTL_VERSION=${KUBECTL_VERSION:-$kubectl_version} |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 57 | KUBERNETES_CONTAINER_RUNTIME=${KUBERNETES_CONTAINER_RUNTIME:-$kubernetes_container_runtime} |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 58 | |
| 59 | DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-$devops_utils_refspec} |
Vasyl Saienko | 3e8ba73 | 2024-09-09 14:07:49 +0300 | [diff] [blame] | 60 | K0S_VERSION=${K0S_VERSION:-$k0s_version} |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 61 | # |
| 62 | # End of block |
| 63 | # |
| 64 | |
| 65 | DEVOPS_UTILS_REPO=${DEVOPS_UTILS_REPO:-'https://gerrit.mcp.mirantis.com/oscore-tools/devops-utils'} |
| 66 | DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-'master'} |
| 67 | DEVOPS_UTILS_DST=/usr/share/devops-utils |
| 68 | |
| 69 | #Wait external network |
Vasyl Saienko | 5942552 | 2024-05-17 14:00:19 +0300 | [diff] [blame] | 70 | netplan apply |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 71 | systemctl restart systemd-resolved |
Vasyl Saienko | 5942552 | 2024-05-17 14:00:19 +0300 | [diff] [blame] | 72 | sleep 15 |
| 73 | curl --connect-timeout 10 --retry 12 --retry-delay 10 ${DEVOPS_UTILS_REPO} || (sleep 1; /bin/false) |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 74 | |
Vasyl Saienko | 183863f | 2024-05-18 14:18:39 +0300 | [diff] [blame] | 75 | if [[ ! -d ${DEVOPS_UTILS_DST} ]]; then |
| 76 | git clone ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_DST} |
| 77 | fi |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 78 | pushd ${DEVOPS_UTILS_DST} |
| 79 | if echo "$DEVOPS_UTILS_REFSPEC" |grep -q "^refs"; then |
| 80 | git fetch ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_REFSPEC} |
| 81 | git checkout FETCH_HEAD |
| 82 | else |
| 83 | git checkout ${DEVOPS_UTILS_REFSPEC} |
| 84 | fi |
| 85 | git log --oneline -10 |
| 86 | popd |
| 87 | |
| 88 | |
| 89 | source ${DEVOPS_UTILS_DST}/de/heat-templates/scripts/functions.sh |
| 90 | |
| 91 | function 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 |
| 115 | function handle_exit { |
| 116 | if [ $? != 0 ] ; then |
| 117 | wait_condition_send "FAILURE" "Script terminated with an error." |
| 118 | fi |
| 119 | } |
| 120 | trap handle_exit EXIT |
| 121 | |
| 122 | if [[ "${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 Saienko | 45280eb | 2024-06-24 11:45:13 +0000 | [diff] [blame] | 127 | configure_sysctl_limits |
Vasyl Saienko | f981351 | 2024-07-02 12:30:25 +0300 | [diff] [blame] | 128 | configure_logind_conf |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame] | 129 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 130 | 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 Saienko | 59e5b2a | 2024-09-09 08:57:18 +0300 | [diff] [blame] | 156 | wait_for_node |
| 157 | set_node_labels |
| 158 | collect_ceph_metadata |
| 159 | configure_contrack |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 160 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 161 | disable_iptables_for_bridges |
| 162 | fi |
| 163 | if [[ "${SINGLE_NODE}" == true ]]; then |
| 164 | nested_virt_config |
Vasyl Saienko | 59e5b2a | 2024-09-09 08:57:18 +0300 | [diff] [blame] | 165 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 166 | disable_master_taint |
| 167 | fi |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 168 | collect_interfaces_metadata |
| 169 | fi |
| 170 | cron_disable_calico_offloading |
| 171 | ;; |
| 172 | master) |
Vasyl Saienko | 45280eb | 2024-06-24 11:45:13 +0000 | [diff] [blame] | 173 | configure_sysctl_limits |
Vasyl Saienko | f981351 | 2024-07-02 12:30:25 +0300 | [diff] [blame] | 174 | configure_logind_conf |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame] | 175 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 176 | 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 Saienko | 45280eb | 2024-06-24 11:45:13 +0000 | [diff] [blame] | 209 | configure_sysctl_limits |
Vasyl Saienko | f981351 | 2024-07-02 12:30:25 +0300 | [diff] [blame] | 210 | configure_logind_conf |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame] | 211 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 212 | 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 Saienko | 45280eb | 2024-06-24 11:45:13 +0000 | [diff] [blame] | 254 | configure_sysctl_limits |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame] | 255 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 256 | 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}" |
| 285 | fi |