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} |
| 45 | FLOATING_NETWORK_PREFIXES=${FLOATING_NETWORK_PREFIXES:-$private_floating_network_cidr} |
| 46 | IRONIC_MT_ENABLED=${IRONIC_MT_ENABLED:-$ironic_mt_enabled} |
| 47 | |
| 48 | HUGE_PAGES=${HUGE_PAGES:-$huge_pages} |
| 49 | TUNGSTENFABRIC_ENABLED=${TUNGSTENFABRIC_ENABLED:-$tungstenfabric_enabled} |
| 50 | SINGLE_NODE=${SINGLE_NODE:-$single_node} |
| 51 | DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL:-$docker_default_address_pool} |
| 52 | LVM_LOOP_DEVICE_SIZE=${LVM_LOOP_DEVICE_SIZE:-$lvm_loop_device_size} |
| 53 | CINDER_LVM_LOOP_DEVICE_SIZE=${CINDER_LVM_LOOP_DEVICE_SIZE:-$cinder_lvm_loop_device_size} |
| 54 | SECURE_OVERLAY_ENABLED=${SECURE_OVERLAY_ENABLED:-$secure_overlay_enabled} |
| 55 | KUBECTL_VERSION=${KUBECTL_VERSION:-$kubectl_version} |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 56 | KUBERNETES_CONTAINER_RUNTIME=${KUBERNETES_CONTAINER_RUNTIME:-$kubernetes_container_runtime} |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 57 | |
| 58 | DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-$devops_utils_refspec} |
| 59 | |
| 60 | # |
| 61 | # End of block |
| 62 | # |
| 63 | |
| 64 | DEVOPS_UTILS_REPO=${DEVOPS_UTILS_REPO:-'https://gerrit.mcp.mirantis.com/oscore-tools/devops-utils'} |
| 65 | DEVOPS_UTILS_REFSPEC=${DEVOPS_UTILS_REFSPEC:-'master'} |
| 66 | DEVOPS_UTILS_DST=/usr/share/devops-utils |
| 67 | |
| 68 | #Wait external network |
Vasyl Saienko | 5942552 | 2024-05-17 14:00:19 +0300 | [diff] [blame] | 69 | netplan apply |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 70 | systemctl restart systemd-resolved |
Vasyl Saienko | 5942552 | 2024-05-17 14:00:19 +0300 | [diff] [blame] | 71 | sleep 15 |
| 72 | 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] | 73 | |
Vasyl Saienko | 183863f | 2024-05-18 14:18:39 +0300 | [diff] [blame] | 74 | if [[ ! -d ${DEVOPS_UTILS_DST} ]]; then |
| 75 | git clone ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_DST} |
| 76 | fi |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 77 | pushd ${DEVOPS_UTILS_DST} |
| 78 | if echo "$DEVOPS_UTILS_REFSPEC" |grep -q "^refs"; then |
| 79 | git fetch ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_REFSPEC} |
| 80 | git checkout FETCH_HEAD |
| 81 | else |
| 82 | git checkout ${DEVOPS_UTILS_REFSPEC} |
| 83 | fi |
| 84 | git log --oneline -10 |
| 85 | popd |
| 86 | |
| 87 | |
| 88 | source ${DEVOPS_UTILS_DST}/de/heat-templates/scripts/functions.sh |
| 89 | |
| 90 | function 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 |
| 114 | function handle_exit { |
| 115 | if [ $? != 0 ] ; then |
| 116 | wait_condition_send "FAILURE" "Script terminated with an error." |
| 117 | fi |
| 118 | } |
| 119 | trap handle_exit EXIT |
| 120 | |
| 121 | if [[ "${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) |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame^] | 126 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 127 | 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) |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame^] | 168 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 169 | 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) |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame^] | 202 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 203 | 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) |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame^] | 245 | disable_unattended_upgr |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 246 | 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}" |
| 275 | fi |