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 |
| 69 | sed -i 's/#DNS=/DNS=4.2.2.1/g' /etc/systemd/resolved.conf |
| 70 | systemctl restart systemd-resolved |
| 71 | curl --connect-timeout 10 --retry 6 --retry-delay 10 ${DEVOPS_UTILS_REPO} || (sleep 1; /bin/false) |
| 72 | |
| 73 | git clone ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_DST} |
| 74 | pushd ${DEVOPS_UTILS_DST} |
| 75 | if echo "$DEVOPS_UTILS_REFSPEC" |grep -q "^refs"; then |
| 76 | git fetch ${DEVOPS_UTILS_REPO} ${DEVOPS_UTILS_REFSPEC} |
| 77 | git checkout FETCH_HEAD |
| 78 | else |
| 79 | git checkout ${DEVOPS_UTILS_REFSPEC} |
| 80 | fi |
| 81 | git log --oneline -10 |
| 82 | popd |
| 83 | |
| 84 | |
| 85 | source ${DEVOPS_UTILS_DST}/de/heat-templates/scripts/functions.sh |
| 86 | |
| 87 | function wait_condition_send { |
| 88 | local status=${1:-SUCCESS} |
| 89 | local reason=${2:-\"empty\"} |
| 90 | local data=${3:-\"empty\"} |
| 91 | local data_binary="{\"status\": \"$status\", \"reason\": \"$reason\", \"data\": $data}" |
| 92 | echo "Trying to send signal to wait condition 5 times: $data_binary" |
| 93 | WAIT_CONDITION_NOTIFY_EXIT_CODE=2 |
| 94 | i=0 |
| 95 | while (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} != 0 && ${i} < 5 )); do |
| 96 | $wait_condition_notify -k --data-binary "$data_binary" && WAIT_CONDITION_NOTIFY_EXIT_CODE=0 || WAIT_CONDITION_NOTIFY_EXIT_CODE=2 |
| 97 | i=$((i + 1)) |
| 98 | sleep 1 |
| 99 | done |
| 100 | if (( ${WAIT_CONDITION_NOTIFY_EXIT_CODE} !=0 && "${status}" == "SUCCESS" )) |
| 101 | then |
| 102 | status="FAILURE" |
| 103 | reason="Can't reach metadata service to report about SUCCESS." |
| 104 | fi |
| 105 | if [ "$status" == "FAILURE" ]; then |
| 106 | exit 1 |
| 107 | fi |
| 108 | } |
| 109 | |
| 110 | # Exit on any errors |
| 111 | function handle_exit { |
| 112 | if [ $? != 0 ] ; then |
| 113 | wait_condition_send "FAILURE" "Script terminated with an error." |
| 114 | fi |
| 115 | } |
| 116 | trap handle_exit EXIT |
| 117 | |
| 118 | if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then |
| 119 | case "$NODE_TYPE" in |
| 120 | # Please keep the "prepare_metadata_files", "disable-rp-filter", "network_config" and "prepare_network" functions |
| 121 | # at the very beginning in the same order. |
| 122 | ucp) |
| 123 | setup_bind_mounts |
| 124 | wait_for_external_network |
| 125 | prepare_metadata_files |
| 126 | disable_rp_filter |
| 127 | network_config |
| 128 | prepare_network |
| 129 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 130 | prepare_docker_config |
| 131 | fi |
| 132 | install_required_packages |
| 133 | install_kubectl |
| 134 | configure_ntp |
| 135 | configure_atop |
| 136 | workaround_default_forward_policy |
| 137 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 138 | install_docker |
| 139 | swarm_init |
| 140 | create_ucp_config |
| 141 | cache_images |
| 142 | install_ucp |
| 143 | download_bundles |
| 144 | rm_ucp_config |
| 145 | elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then |
| 146 | download_k0s |
| 147 | install_k0s |
| 148 | fi |
| 149 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 150 | wait_for_node |
| 151 | set_node_labels |
| 152 | collect_ceph_metadata |
| 153 | configure_contrack |
| 154 | disable_iptables_for_bridges |
| 155 | fi |
| 156 | if [[ "${SINGLE_NODE}" == true ]]; then |
| 157 | nested_virt_config |
| 158 | disable_master_taint |
| 159 | collect_interfaces_metadata |
| 160 | fi |
| 161 | cron_disable_calico_offloading |
| 162 | ;; |
| 163 | master) |
| 164 | setup_bind_mounts |
| 165 | wait_for_external_network |
| 166 | nested_virt_config |
| 167 | prepare_metadata_files |
| 168 | disable_rp_filter |
| 169 | network_config |
| 170 | prepare_network |
| 171 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 172 | prepare_docker_config |
| 173 | fi |
| 174 | install_required_packages |
| 175 | install_kubectl |
| 176 | configure_ntp |
| 177 | configure_atop |
| 178 | workaround_default_forward_policy |
| 179 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 180 | install_docker |
| 181 | cache_images |
| 182 | download_bundles |
| 183 | join_node manager |
| 184 | fi |
| 185 | wait_for_node |
| 186 | set_node_labels |
| 187 | collect_ceph_metadata |
| 188 | configure_contrack |
| 189 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 190 | disable_iptables_for_bridges |
| 191 | fi |
| 192 | collect_interfaces_metadata |
| 193 | cron_disable_calico_offloading |
| 194 | increase_iscsi_timeout |
| 195 | ;; |
| 196 | worker) |
| 197 | setup_bind_mounts |
| 198 | wait_for_external_network |
| 199 | if [[ "${CONFIGURE_HUGE_PAGES}" == true ]]; then |
| 200 | configure_huge_pages |
| 201 | fi |
| 202 | nested_virt_config |
| 203 | prepare_metadata_files |
| 204 | disable_rp_filter |
| 205 | network_config |
| 206 | prepare_network |
| 207 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 208 | prepare_docker_config |
| 209 | fi |
| 210 | install_required_packages |
| 211 | install_kubectl |
| 212 | enable_iscsi |
| 213 | configure_ntp |
| 214 | configure_atop |
| 215 | workaround_default_forward_policy |
| 216 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 217 | install_docker |
| 218 | cache_images |
| 219 | download_bundles |
| 220 | join_node worker |
| 221 | elif [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then |
| 222 | download_k0s |
| 223 | download_k8s_metadata |
| 224 | join_k0s_node worker |
| 225 | fi |
| 226 | wait_for_node |
| 227 | set_node_labels |
| 228 | collect_ceph_metadata |
| 229 | configure_contrack |
| 230 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 231 | disable_iptables_for_bridges |
| 232 | fi |
| 233 | collect_interfaces_metadata |
| 234 | configure_lvm |
| 235 | cron_disable_calico_offloading |
| 236 | increase_iscsi_timeout |
| 237 | ;; |
| 238 | frr) |
| 239 | wait_for_external_network |
| 240 | prepare_metadata_files |
| 241 | disable_rp_filter |
| 242 | network_config |
| 243 | prepare_network |
| 244 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 245 | prepare_docker_config |
| 246 | fi |
| 247 | install_required_packages |
| 248 | configure_ntp |
| 249 | configure_atop |
| 250 | if [[ "${KUBERNETES_INSTALLER}" == "ucp" ]]; then |
| 251 | install_docker |
| 252 | cache_images |
| 253 | download_bundles |
| 254 | fi |
| 255 | workaround_default_forward_policy |
| 256 | configure_contrack |
| 257 | disable_iptables_for_bridges |
| 258 | install_frr |
| 259 | cron_disable_calico_offloading |
| 260 | increase_iscsi_timeout |
| 261 | ;; |
| 262 | *) |
| 263 | echo "Usage: $0 {ucp|master|worker}" |
| 264 | exit 1 |
| 265 | esac |
| 266 | |
| 267 | wait_condition_send "SUCCESS" "Instance successfuly started." "${HW_METADATA}" |
| 268 | fi |