Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -x |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 3 | set -e |
Dennis Dmitriev | b12d234 | 2020-03-12 19:36:24 +0200 | [diff] [blame] | 4 | # allow access to the local variables from prepare-metadata.py |
| 5 | set -a |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 6 | |
Vasyl Saienko | 9824df4 | 2021-03-17 15:43:02 +0200 | [diff] [blame] | 7 | # ensure we don't re-source this in the same environment |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 8 | [[ -z "$_FUNCTIONS_SCRIPT" ]] || return 0 |
| 9 | declare -r -g _FUNCTIONS_SCRIPT=1 |
Vasyl Saienko | 9824df4 | 2021-03-17 15:43:02 +0200 | [diff] [blame] | 10 | |
Oleh Hryhorov | ca77209 | 2020-02-13 11:15:17 +0200 | [diff] [blame] | 11 | PUBLIC_INTERFACE_NETMASK=$(echo ${PUBLIC_INTERFACE_CIDR} | cut -d'/' -f2) |
Oleh Hryhorov | dccb1cd | 2020-03-04 15:52:55 +0200 | [diff] [blame] | 12 | STORAGE_BACKEND_NETWORK_NETMASK=$(echo ${STORAGE_BACKEND_NETWORK} | cut -d'/' -f2) |
Oleh Hryhorov | dccb1cd | 2020-03-04 15:52:55 +0200 | [diff] [blame] | 13 | STORAGE_FRONTEND_NETWORK_NETMASK=$(echo ${STORAGE_FRONTEND_NETWORK} | cut -d'/' -f2) |
Vasyl Saienko | 552250d | 2021-03-19 12:07:23 +0200 | [diff] [blame] | 14 | IRONIC_BAREMETAL_INTERFACE_IP=${IRONIC_BAREMETAL_INTERFACE_IP:-$ironic_baremetal_interface_ip} |
Vasyl Saienko | 4c46819 | 2020-05-19 11:51:13 +0300 | [diff] [blame] | 15 | IRONIC_BAREMETAL_NETWORK_NETMASK=$(echo ${IRONIC_BAREMETAL_NETWORK} | cut -d'/' -f2) |
Vasyl Saienko | d396420 | 2023-09-24 15:09:48 +0000 | [diff] [blame] | 16 | IRONIC_BAREMETAL_INTERFACE=$(ip route |grep ${IRONIC_BAREMETAL_NETWORK} | awk '/ src / {print $3}') |
Vasyl Saienko | 3dd0c27 | 2020-11-16 17:20:07 +0200 | [diff] [blame] | 17 | TUNNEL_INTERFACE_NETWORK_NETMASK=$(ip -o addr show |grep -w ${TUNNEL_INTERFACE_IP} | awk '{print $4}' |awk -F '/' '{print $2}') |
| 18 | TUNNEL_INTERFACE=$(ip -o addr show |grep -w ${TUNNEL_INTERFACE_IP}/${TUNNEL_INTERFACE_NETWORK_NETMASK} | awk '{print $2}') |
Michael Polenchuk | 486cadf | 2020-08-24 16:25:51 +0400 | [diff] [blame] | 19 | IRONIC_BAREMETAL_NETWORK_PREFIX=$(sed 's/[0-9]*\/[0-9]*$//' <<< $IRONIC_BAREMETAL_NETWORK) |
| 20 | IRONIC_BAREMETAL_TUNNEL_NETWORK_PREFIX=$(sed 's/[0-9]*\/[0-9]*$//' <<< $IRONIC_BAREMETAL_TUNNEL_NETWORK) |
Vasyl Saienko | 4a2832d | 2024-05-16 09:00:03 +0300 | [diff] [blame] | 21 | STORAGE_FRONTEND_NETWORK_NETMASK=$(echo ${STORAGE_FRONTEND_NETWORK} | cut -d'/' -f2) |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 22 | DOCKER_DEFAULT_ADDRESS_POOL=${DOCKER_DEFAULT_ADDRESS_POOL:-10.10.1.0/16} |
| 23 | # DOCKER_DEFAULT_ADDRESS_SIZE have to be less then netmask in DOCKER_DEFAULT_ADDRESS_POOL because |
| 24 | # to the fact that actual netmask for docker_gwbridge is given from it |
| 25 | DOCKER_DEFAULT_ADDRESS_SIZE=${DOCKER_DEFAULT_ADDRESS_SIZE:-24} |
Mykyta Karpin | 5ed5fd8 | 2020-01-27 18:23:29 +0200 | [diff] [blame] | 26 | DOCKER_EE_RELEASE=${DOCKER_EE_RELEASE:-stable-19.03} |
Vasyl Saienko | fa71410 | 2024-03-22 09:30:25 +0200 | [diff] [blame] | 27 | DOCKER_EE_PACKAGES=${DOCKER_EE_PACKAGES:-'docker-ee'} |
Vasyl Saienko | a94bf18 | 2023-04-01 10:42:17 +0000 | [diff] [blame] | 28 | BINARY_BASE_URL=${BINARY_BASE_URL:-"http://binary.mirantis.com"} |
Vasyl Saienko | 7c59592 | 2021-03-17 13:58:13 +0200 | [diff] [blame] | 29 | |
| 30 | ### COMMON FUNCTIONS ### |
| 31 | function get_interface_prefix { |
| 32 | local interface=$1 |
| 33 | local interface_ip |
| 34 | local interface_mask |
| 35 | |
| 36 | interface_ip=$(ip addr show dev ${interface} | grep -Po 'inet \K[\d.]+' | egrep -v "127.0.|172.17") |
| 37 | interface_mask=$(ip addr show dev ${interface} | grep -Po 'inet \K[\d.]+\/[\d]+' | egrep -v "127.0.|172.17" | cut -d'/' -f2) |
| 38 | echo "${interface_ip}/${interface_mask}" |
| 39 | } |
| 40 | ### END COMMON FUNCTIONS ### |
| 41 | |
Oleh Hryhorov | f4677af | 2021-04-26 18:00:15 +0300 | [diff] [blame] | 42 | DEFAULT_INTERFACE=${DEFAULT_INTERFACE:-$(ip route show |awk '/default/ {print $5}')} |
Vasyl Saienko | 7c59592 | 2021-03-17 13:58:13 +0200 | [diff] [blame] | 43 | |
Vasyl Saienko | 390c53a | 2021-03-18 12:45:11 +0200 | [diff] [blame] | 44 | if [[ -n ${CONTROL_NETWORK_CIDR} ]]; then |
Vasyl Saienko | d396420 | 2023-09-24 15:09:48 +0000 | [diff] [blame] | 45 | CONTROL_IP_ADDRESS=$(ip route |grep ${CONTROL_NETWORK_CIDR} | head -n1 | fgrep -v ' via ' | awk '/ src / {print $9}') |
Vasyl Saienko | 7c59592 | 2021-03-17 13:58:13 +0200 | [diff] [blame] | 46 | else |
| 47 | CONTROL_IP_ADDRESS=$(get_interface_prefix ${DEFAULT_INTERFACE} | awk -F '/' '{print $1}') |
Vasyl Saienko | e967706 | 2021-03-19 13:31:32 +0200 | [diff] [blame] | 48 | CONTROL_NETWORK_CIDR=$(ip route show dev ${DEFAULT_INTERFACE} | awk '/kernel/ {print $1}') |
Vasyl Saienko | 7c59592 | 2021-03-17 13:58:13 +0200 | [diff] [blame] | 49 | fi |
| 50 | |
| 51 | |
Oleh Hryhorov | b58460e | 2020-02-05 15:53:48 +0200 | [diff] [blame] | 52 | PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-ens4} |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 53 | UCP_USERNAME=${UCP_USERNAME:-admin} |
| 54 | UCP_PASSWORD=${UCP_PASSWORD:-administrator} |
| 55 | OS_CODENAME=$(lsb_release -c -s) |
Vasyl Saienko | 3ab29c9 | 2020-01-03 10:39:03 +0200 | [diff] [blame] | 56 | NODE_DEPLOYMENT_RETRIES=${NODE_DEPLOYMENT_RETRIES:-15} |
Vasyl Saienko | 7d7acea | 2020-01-03 16:59:05 +0200 | [diff] [blame] | 57 | FLOATING_NETWORK_PREFIXES=${FLOATING_NETWORK_PREFIXES:-10.11.12.0/24} |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 58 | PUBLIC_INTERFACE=${PUBLIC_INTERFACE:-ens4} |
Vasyl Saienko | 0fa6f19 | 2020-03-06 16:08:51 +0200 | [diff] [blame] | 59 | UCP_MASTER_HOST=${UCP_MASTER_HOST:-${CONTROL_IP_ADDRESS}} |
| 60 | UCP_IP_ADDRESS=${UCP_IP_ADDRESS:-$CONTROL_IP_ADDRESS} |
Vasyl Saienko | cfbedc7 | 2021-02-15 18:02:56 +0200 | [diff] [blame] | 61 | # Change default VXLAN port, need for https://mirantis.jira.com/browse/PRODX-11679 |
| 62 | UCP_DOCKER_SWARM_DATA_PORT=${UCP_DOCKER_SWARM_DATA_PORT:-4789} |
Vasyl Saienko | 06c7afe | 2022-07-01 17:53:56 +0000 | [diff] [blame] | 63 | UCP_DOCKER_CALICO_VXLAN_PORT=${UCP_DOCKER_CALICO_VXLAN_PORT:-${UCP_DOCKER_SWARM_DATA_PORT}} |
Vasyl Saienko | 0816634 | 2020-02-28 12:20:51 +0200 | [diff] [blame] | 64 | NTP_SERVERS=${NTP_SERVERS:-"ldap.scc.mirantis.net ldap.bud.mirantis.net"} |
Michael Polenchuk | 486cadf | 2020-08-24 16:25:51 +0400 | [diff] [blame] | 65 | IRONIC_BAREMETAL_VXLAN_INTERFACE='vxlan10' |
Mykyta Karpin | 6a153c5 | 2020-11-03 15:21:38 +0200 | [diff] [blame] | 66 | HUGE_PAGES_1G_SIZE=$(echo "${HUGE_PAGES}" | awk -F ',' '{print $1}') |
| 67 | HUGE_PAGES_2Mb_SIZE=$(echo "${HUGE_PAGES}" | awk -F ',' '{print $2}') |
| 68 | CONFIGURE_HUGE_PAGES=false |
Vasyl Saienko | 3dd0c27 | 2020-11-16 17:20:07 +0200 | [diff] [blame] | 69 | TUNNEL_INTERFACE_NETPLAN_MANAGE=true |
Anton Samoylov | 1d140ee | 2020-11-23 22:40:13 +0400 | [diff] [blame] | 70 | TUNGSTENFABRIC_ENABLED=${TUNGSTENFABRIC_ENABLED:-false} |
Mykyta Karpin | 6a153c5 | 2020-11-03 15:21:38 +0200 | [diff] [blame] | 71 | if [[ "${HUGE_PAGES_1G_SIZE}" -gt 0 ]] || [[ "${HUGE_PAGES_2Mb_SIZE}" -gt 0 ]]; then |
| 72 | CONFIGURE_HUGE_PAGES=true |
Anton Samoylov | 1d140ee | 2020-11-23 22:40:13 +0400 | [diff] [blame] | 73 | if [[ "${TUNGSTENFABRIC_ENABLED,,}" == false ]]; then |
| 74 | TUNNEL_INTERFACE_NETPLAN_MANAGE=false |
| 75 | fi |
Mykyta Karpin | 6a153c5 | 2020-11-03 15:21:38 +0200 | [diff] [blame] | 76 | fi |
Oleh Hryhorov | 43bbc8c | 2020-12-03 15:30:09 +0200 | [diff] [blame] | 77 | SINGLE_NODE=${SINGLE_NODE:-true} |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 78 | |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 79 | #FRR Options |
| 80 | FRR_BGP_AS_NUMBER=${FRR_BGP_AS_NUMBER:-64512} |
| 81 | FRR_ROUTER_ID=${TUNNEL_INTERFACE_IP} |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 82 | FRR_BGP_SOURCE_ADDRESS=${TUNNEL_INTERFACE_IP} |
| 83 | FRR_BGP_NEIGHBORS=${FRR_BGP_NEIGHBORS:-} |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 84 | FRR_EVPN_TUNNELS_RANGE=${FRR_EVPN_TUNNELS_RANGE:-'20 50'} |
Vasyl Saienko | b3b8c4e | 2021-02-26 10:54:27 +0200 | [diff] [blame] | 85 | FRR_EVPN_VXLAN_DST_PORT=${FRR_EVPN_VXLAN_DST_PORT:-4790} |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 86 | |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 87 | LVM_LOOP_DEVICE_SIZE=${LVM_LOOP_DEVICE_SIZE:-0} |
Vasyl Saienko | cd30206 | 2021-04-21 22:25:18 +0300 | [diff] [blame] | 88 | CINDER_LVM_LOOP_DEVICE_SIZE=${CINDER_LVM_LOOP_DEVICE_SIZE:-0} |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 89 | |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 90 | _KUBECTL_CMD="kubectl --kubeconfig /etc/kubernetes/admin.conf " |
| 91 | |
Vasyl Saienko | a51d1ca | 2020-01-02 15:59:16 +0200 | [diff] [blame] | 92 | function retry { |
| 93 | local retries=$1 |
| 94 | shift |
| 95 | local msg="$1" |
| 96 | shift |
| 97 | |
| 98 | local count=0 |
| 99 | until "$@"; do |
| 100 | exit=$? |
| 101 | wait=$((2 ** $count)) |
| 102 | count=$(($count + 1)) |
| 103 | if [ $count -lt $retries ]; then |
| 104 | echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." |
| 105 | sleep $wait |
| 106 | else |
| 107 | echo "Retry $count/$retries exited $exit, no more retries left." |
| 108 | echo "$msg" |
| 109 | return $exit |
| 110 | fi |
| 111 | done |
| 112 | return 0 |
| 113 | } |
| 114 | |
Vasyl Saienko | 300bb0b | 2023-04-19 06:52:53 +0000 | [diff] [blame] | 115 | function install_pkgs { |
| 116 | local pkgs="$@" |
| 117 | function _retry_install { |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 118 | apt update && DEBIAN_FRONTEND=noninteractive apt install -o DPkg::Options::=--force-confdef -y $pkgs |
Vasyl Saienko | 300bb0b | 2023-04-19 06:52:53 +0000 | [diff] [blame] | 119 | } |
| 120 | retry 10 "Labeling node failed" _retry_install |
| 121 | } |
| 122 | |
Vasyl Saienko | 806d5dc | 2022-02-01 14:18:09 +0200 | [diff] [blame] | 123 | function setup_bind_mounts { |
| 124 | mkdir -p /var/lib/persistant-data |
Vasyl Saienko | e310725 | 2023-06-06 07:02:58 +0000 | [diff] [blame] | 125 | for component in nova glance cinder docker; do |
Vasyl Saienko | 3cc01ca | 2023-09-25 12:23:43 +0000 | [diff] [blame] | 126 | if [[ -d /var/lib/${component} ]]; then |
| 127 | continue |
| 128 | fi |
Vasyl Saienko | 806d5dc | 2022-02-01 14:18:09 +0200 | [diff] [blame] | 129 | mkdir -p /var/lib/data/${component} /var/lib/${component} |
Vasyl Saienko | 3cc01ca | 2023-09-25 12:23:43 +0000 | [diff] [blame] | 130 | echo "/var/lib/data/${component} /var/lib/${component} none bind 0 0" >> /etc/fstab |
Vasyl Saienko | 806d5dc | 2022-02-01 14:18:09 +0200 | [diff] [blame] | 131 | done |
Vasyl Saienko | e310725 | 2023-06-06 07:02:58 +0000 | [diff] [blame] | 132 | |
| 133 | if [[ "${KUBERNETES_INSTALLER}" == "k0s" ]]; then |
| 134 | mkdir -p /var/lib/k0s/kubelet |
| 135 | mkdir -p /var/lib/kubelet |
| 136 | echo "/var/lib/k0s/kubelet /var/lib/kubelet none bind 0 0" >> /etc/fstab |
| 137 | fi |
| 138 | |
Vasyl Saienko | 806d5dc | 2022-02-01 14:18:09 +0200 | [diff] [blame] | 139 | mount -a |
| 140 | } |
| 141 | |
Vasyl Saienko | 392dc71 | 2020-04-07 15:56:10 +0300 | [diff] [blame] | 142 | function configure_atop { |
| 143 | sed -i 's/INTERVAL=600/INTERVAL=60/' /usr/share/atop/atop.daily |
| 144 | systemctl restart atop |
| 145 | } |
| 146 | |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame] | 147 | function disable_unattended_upgr { |
Vasyl Saienko | aadd2f8 | 2020-08-07 09:35:03 +0300 | [diff] [blame] | 148 | # Disable unattended upgrades |
| 149 | sed -i 's/1/0/' /etc/apt/apt.conf.d/20auto-upgrades |
Oleh Hryhorov | be7bdf7 | 2021-04-05 18:21:22 +0300 | [diff] [blame] | 150 | sed -i 's/APT::Periodic::Update-Package-Lists "1"/APT::Periodic::Update-Package-Lists "0"/g' /etc/apt/apt.conf.d/* |
dbiletskiy | 70af819 | 2024-06-19 09:27:10 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | function install_required_packages { |
Mykyta Karpin | d6cde5e | 2022-07-05 12:06:06 +0300 | [diff] [blame] | 154 | local pkg_list="apt-transport-https ca-certificates curl software-properties-common jq unzip atop iptables-persistent socat ntp rng-tools open-iscsi nfs-common" |
Vasyl Saienko | aadd2f8 | 2020-08-07 09:35:03 +0300 | [diff] [blame] | 155 | |
Vasyl Saienko | a7cfc32 | 2020-11-06 16:52:22 +0200 | [diff] [blame] | 156 | if [[ "${CONFIGURE_HUGE_PAGES}" == true ]]; then |
| 157 | pkg_list="$pkg_list dpdk-igb-uio-dkms" |
Anton Samoylov | ec019d5 | 2020-11-19 18:55:47 +0400 | [diff] [blame] | 158 | # linux-image-extra-$(uname -r) provides uio_pci_generic module, used by TF DPDK as default driver |
| 159 | if [[ "${TUNGSTENFABRIC_ENABLED,,}" == true ]]; then |
| 160 | pkg_list="$pkg_list linux-modules-extra-$(uname -r)" |
| 161 | fi |
Vasyl Saienko | a7cfc32 | 2020-11-06 16:52:22 +0200 | [diff] [blame] | 162 | fi |
Vasyl Saienko | 300bb0b | 2023-04-19 06:52:53 +0000 | [diff] [blame] | 163 | install_pkgs $pkg_list |
| 164 | # Since version 4 yq uses another syntax |
Oleksandr Kononenko | 231933b | 2024-02-05 16:46:35 +0200 | [diff] [blame] | 165 | if [[ ! -f /usr/bin/yq ]]; then |
| 166 | curl --retry 6 --retry-delay 5 -L ${BINARY_BASE_URL}/openstack/bin/utils/yq/yq-v3.3.2 -o /usr/bin/yq |
| 167 | chmod +x /usr/bin/yq |
| 168 | fi |
Mykyta Karpin | 5ed5fd8 | 2020-01-27 18:23:29 +0200 | [diff] [blame] | 169 | } |
| 170 | |
Oleksii Grudev | 4399e23 | 2021-02-24 19:08:25 +0200 | [diff] [blame] | 171 | function enable_iscsi { |
| 172 | systemctl enable iscsid |
| 173 | systemctl restart iscsid |
| 174 | } |
Mykyta Karpin | 5ed5fd8 | 2020-01-27 18:23:29 +0200 | [diff] [blame] | 175 | |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 176 | function configure_lvm { |
Vasyl Saienko | cd30206 | 2021-04-21 22:25:18 +0300 | [diff] [blame] | 177 | function _setup_lvm { |
| 178 | local device_num=$1 |
| 179 | local device_size=$2 |
| 180 | local vg_name=$3 |
Denis Biletskiy | 3b21a82 | 2022-05-10 10:29:29 +0300 | [diff] [blame] | 181 | if vgdisplay | grep ${vg_name}; then |
| 182 | echo "Volume group ${vg_name} is already initialize" |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 183 | else |
| 184 | #configure lvm only on compute nodes |
| 185 | if [[ ${NODE_METADATA} == *"openstack-compute-node"* ]]; then |
| 186 | truncate --size ${device_size}G /srv/disk${device_num} |
| 187 | cat <<EOF > /etc/systemd/system/setup-loopback-loop${device_num}.service |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 188 | [Unit] |
Vasyl Saienko | cd30206 | 2021-04-21 22:25:18 +0300 | [diff] [blame] | 189 | Description=Setup loop${device_num} device |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 190 | DefaultDependencies=no |
| 191 | After=systemd-udev-settle.service |
| 192 | Before=lvm2-activation-early.service |
| 193 | Wants=systemd-udev-settle.service |
| 194 | |
| 195 | [Service] |
Vasyl Saienko | cd30206 | 2021-04-21 22:25:18 +0300 | [diff] [blame] | 196 | ExecStart=-/sbin/losetup /dev/loop${device_num} /srv/disk${device_num} |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 197 | RemainAfterExit=true |
| 198 | Type=oneshot |
| 199 | |
| 200 | [Install] |
| 201 | WantedBy=local-fs.target |
| 202 | EOF |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 203 | systemctl enable setup-loopback-loop${device_num} |
| 204 | systemctl start setup-loopback-loop${device_num} |
| 205 | #adding short sleep to give time for service to start |
| 206 | sleep 3 |
| 207 | pvcreate /dev/loop${device_num} |
| 208 | vgcreate ${vg_name} /dev/loop${device_num} |
| 209 | fi |
Vasyl Saienko | cd30206 | 2021-04-21 22:25:18 +0300 | [diff] [blame] | 210 | fi |
| 211 | } |
| 212 | |
| 213 | if [[ "${LVM_LOOP_DEVICE_SIZE}" -gt 0 ]]; then |
Denis Biletskiy | 3b21a82 | 2022-05-10 10:29:29 +0300 | [diff] [blame] | 214 | _setup_lvm 10 ${LVM_LOOP_DEVICE_SIZE} nova-vol |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 215 | fi |
Vasyl Saienko | cd30206 | 2021-04-21 22:25:18 +0300 | [diff] [blame] | 216 | if [[ "${CINDER_LVM_LOOP_DEVICE_SIZE}" -gt 0 ]]; then |
Denis Biletskiy | 3b21a82 | 2022-05-10 10:29:29 +0300 | [diff] [blame] | 217 | _setup_lvm 11 ${CINDER_LVM_LOOP_DEVICE_SIZE} cinder-vol |
Vasyl Saienko | cd30206 | 2021-04-21 22:25:18 +0300 | [diff] [blame] | 218 | fi |
| 219 | |
Oleksii Grudev | 4e3c8b4 | 2021-03-02 19:02:45 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Mykyta Karpin | 5ed5fd8 | 2020-01-27 18:23:29 +0200 | [diff] [blame] | 222 | function install_docker { |
| 223 | function install_retry { |
Vasyl Saienko | fa71410 | 2024-03-22 09:30:25 +0200 | [diff] [blame] | 224 | curl --retry 6 --retry-delay 5 -fsSL "${DOCKER_EE_URL}/gpg" | sudo apt-key add - |
| 225 | add-apt-repository "deb [arch=amd64] ${DOCKER_EE_URL}/ ${OS_CODENAME} ${DOCKER_EE_RELEASE}" |
| 226 | install_pkgs ${DOCKER_EE_PACKAGES} |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 227 | if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then |
| 228 | NERDCTL_VERSION=1.7.6 |
| 229 | curl --retry 6 --retry-delay 5 -fsSL https://github.com/containerd/nerdctl/releases/download/v${NERDCTL_VERSION}/nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz --output nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz |
| 230 | tar zxvf nerdctl-${NERDCTL_VERSION}-linux-amd64.tar.gz -C /usr/local/bin |
| 231 | fi |
Mykyta Karpin | 5ed5fd8 | 2020-01-27 18:23:29 +0200 | [diff] [blame] | 232 | } |
| 233 | retry 10 "Failed to install docker" install_retry |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Mykyta Karpin | 7abaea0 | 2020-07-27 15:43:07 +0300 | [diff] [blame] | 236 | function prepare_docker_config { |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 237 | mkdir -p /etc/docker |
| 238 | cat <<EOF > /etc/docker/daemon.json |
| 239 | { |
Vasyl Saienko | a37de44 | 2024-05-02 17:15:47 +0300 | [diff] [blame] | 240 | "default-cgroupns-mode": "host", |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 241 | "default-address-pools": [ |
| 242 | { "base": "${DOCKER_DEFAULT_ADDRESS_POOL}", "size": ${DOCKER_DEFAULT_ADDRESS_SIZE} } |
Mykyta Karpin | 7abaea0 | 2020-07-27 15:43:07 +0300 | [diff] [blame] | 243 | ], |
| 244 | "log-driver": "json-file", |
| 245 | "log-opts": { |
| 246 | "max-size": "1g", |
| 247 | "max-file": "3" |
| 248 | } |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 249 | } |
| 250 | EOF |
| 251 | |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 252 | if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then |
| 253 | mkdir -p /etc/containerd/ |
| 254 | cat <<EOF> /etc/containerd/config.toml |
Vasyl Saienko | 05edc40 | 2024-06-11 11:17:21 +0300 | [diff] [blame] | 255 | version = 2 |
| 256 | [plugins] |
| 257 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes] |
| 258 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc] |
| 259 | runtime_type = "io.containerd.runc.v2" |
| 260 | [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] |
| 261 | SystemdCgroup = true |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 262 | EOF |
Vasyl Saienko | 05edc40 | 2024-06-11 11:17:21 +0300 | [diff] [blame] | 263 | systemctl restart containerd || /bin/true |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 264 | fi |
| 265 | |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Vasyl Saienko | e32453e | 2020-09-16 09:30:34 +0300 | [diff] [blame] | 268 | function pull_image { |
| 269 | local image="$1" |
| 270 | function pull_image_retry { |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 271 | if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then |
| 272 | nerdctl --address unix:///run/containerd/containerd.sock -n k8s.io pull $image |
| 273 | fi |
Vasyl Saienko | e32453e | 2020-09-16 09:30:34 +0300 | [diff] [blame] | 274 | docker pull ${image} |
| 275 | } |
| 276 | retry 10 "Can't pool docker image $image" pull_image_retry |
| 277 | } |
| 278 | |
Vasyl Saienko | 84ee4fd | 2020-09-02 10:00:18 +0300 | [diff] [blame] | 279 | function cache_images { |
| 280 | |
Vasyl Saienko | e32453e | 2020-09-16 09:30:34 +0300 | [diff] [blame] | 281 | # Cache UCP image with retries |
| 282 | pull_image "${DOCKER_UCP_IMAGE}" |
Vasyl Saienko | 84ee4fd | 2020-09-02 10:00:18 +0300 | [diff] [blame] | 283 | |
Vasyl Saienko | e32453e | 2020-09-16 09:30:34 +0300 | [diff] [blame] | 284 | local image_prefix=${DOCKER_UCP_IMAGE%/*} |
Oleksandr Kononenko | bf4ecf8 | 2024-02-01 11:02:53 +0200 | [diff] [blame] | 285 | for image in $(docker container run --rm --name ucp -v /var/run/docker.sock:/var/run/docker.sock ${DOCKER_UCP_IMAGE} images --list); do |
| 286 | pull_image "${image_prefix}/${image##*/}" |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 287 | if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then |
| 288 | nerdctl --address unix:///run/containerd/containerd.sock -n k8s.io tag ${image_prefix}/${image##*/} mirantis/${image##*/} |
| 289 | fi |
Oleksandr Kononenko | bf4ecf8 | 2024-02-01 11:02:53 +0200 | [diff] [blame] | 290 | docker tag ${image_prefix}/${image##*/} mirantis/${image##*/} |
| 291 | done |
Vasyl Saienko | 84ee4fd | 2020-09-02 10:00:18 +0300 | [diff] [blame] | 292 | } |
| 293 | |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 294 | function install_ucp { |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 295 | if docker ps --all | grep ucp-controller; then |
| 296 | echo "Docker UCP container is running" |
| 297 | else |
| 298 | local tmpd |
| 299 | tmpd=$(mktemp -d) |
| 300 | function docker_run_retry { |
| 301 | docker container run --rm --name ucp \ |
| 302 | -v /var/run/docker.sock:/var/run/docker.sock \ |
| 303 | ${DOCKER_UCP_IMAGE} install \ |
| 304 | --host-address $UCP_IP_ADDRESS \ |
| 305 | --admin-username $UCP_USERNAME \ |
| 306 | --admin-password $UCP_PASSWORD \ |
| 307 | --existing-config |
| 308 | } |
| 309 | retry 10 "Can't bring up docker UCP container" docker_run_retry |
| 310 | fi |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 311 | } |
| 312 | |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 313 | function download_k0s { |
| 314 | curl -sSLf https://get.k0s.sh | sudo sh |
| 315 | } |
| 316 | |
| 317 | function install_k0s { |
Vasyl Saienko | e310725 | 2023-06-06 07:02:58 +0000 | [diff] [blame] | 318 | mkdir -p /etc/k0s |
| 319 | k0s config create > /etc/k0s/k0s.yaml |
| 320 | k0s install controller -c /etc/k0s/k0s.yaml |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 321 | k0s start |
| 322 | |
Vasyl Saienko | e310725 | 2023-06-06 07:02:58 +0000 | [diff] [blame] | 323 | sleep 60 |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 324 | |
Vasyl Saienko | e2c68dd | 2022-01-27 17:10:12 +0200 | [diff] [blame] | 325 | mkdir -p /etc/kubernetes /root/.kube/ |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 326 | k0s kubeconfig admin > /etc/kubernetes/admin.conf |
| 327 | cp /etc/kubernetes/admin.conf /root/.kube/config |
| 328 | |
| 329 | mkdir -p /etc/k0s |
| 330 | k0s kubeconfig admin > /etc/k0s/admin.conf |
| 331 | k0s token create --role=worker > /etc/k0s/worker_token.yaml |
| 332 | k0s token create --role=controller > /etc/k0s/controller_token.yaml |
| 333 | |
Vasyl Saienko | 300bb0b | 2023-04-19 06:52:53 +0000 | [diff] [blame] | 334 | install_pkgs nginx |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 335 | rm -f /etc/nginx/sites-enabled/default |
| 336 | ln -s /etc/k0s/ /var/www/k0s |
| 337 | cat << EOF > /etc/nginx/sites-enabled/k0s |
| 338 | server { |
| 339 | listen *:80; |
| 340 | root /var/www; |
| 341 | |
| 342 | location /k0s { |
| 343 | autoindex on; |
| 344 | } |
| 345 | } |
| 346 | EOF |
| 347 | systemctl restart nginx |
| 348 | } |
| 349 | |
Oleh Hryhorov | cd1a3bd | 2020-12-04 13:21:06 +0200 | [diff] [blame] | 350 | function get_authtoken_retry { |
| 351 | # Download the bundle https://docs.docker.com/ee/ucp/user-access/cli/ |
| 352 | # Create an environment variable with the user security token |
| 353 | AUTHTOKEN=$(curl --retry 6 --retry-delay 5 -sk -d '{"username":"'$UCP_USERNAME'","password":"'$UCP_PASSWORD'"}' https://${UCP_MASTER_HOST}/auth/login | jq -r .auth_token) |
| 354 | if [ -z ${AUTHTOKEN} ]; then |
| 355 | return -1 |
| 356 | fi |
| 357 | } |
| 358 | |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 359 | function download_bundles { |
| 360 | local tmpd |
| 361 | tmpd=$(mktemp -d) |
Oleh Hryhorov | a075487 | 2020-01-24 16:45:05 +0200 | [diff] [blame] | 362 | |
| 363 | function download_bundles_retry { |
| 364 | # Download the client certificate bundle |
Vasyl Saienko | f3dba8c | 2020-02-14 10:07:23 +0200 | [diff] [blame] | 365 | curl --retry 6 --retry-delay 5 -k -H "Authorization: Bearer $AUTHTOKEN" https://${UCP_MASTER_HOST}/api/clientbundle -o ${tmpd}/bundle.zip |
Oleh Hryhorov | a075487 | 2020-01-24 16:45:05 +0200 | [diff] [blame] | 366 | } |
Oleh Hryhorov | b58460e | 2020-02-05 15:53:48 +0200 | [diff] [blame] | 367 | |
Vasyl Saienko | 9b68899 | 2020-02-13 13:50:53 +0200 | [diff] [blame] | 368 | retry 10 "Can't get AUTHTOKEN from master." get_authtoken_retry |
| 369 | retry 10 "Can't download bundle file from master." download_bundles_retry |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 370 | |
| 371 | pushd $tmpd |
| 372 | # Unzip the bundle. |
| 373 | unzip bundle.zip |
| 374 | |
| 375 | # Run the utility script. |
| 376 | eval "$(<env.sh)" |
Vasyl Saienko | f9f668c | 2020-01-04 11:36:35 +0200 | [diff] [blame] | 377 | mkdir -p /etc/kubernetes /root/.kube/ |
Vasyl Saienko | 5b37942 | 2020-01-04 12:24:08 +0200 | [diff] [blame] | 378 | cp kube.yml /etc/kubernetes/admin.conf |
| 379 | cp kube.yml /root/.kube/config |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 380 | popd |
| 381 | } |
| 382 | |
Vasyl Saienko | 3ab29c9 | 2020-01-03 10:39:03 +0200 | [diff] [blame] | 383 | function wait_for_node { |
| 384 | function retry_wait { |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 385 | ${_KUBECTL_CMD} get nodes |grep -w Ready |awk '{print $1}' |grep -q $(hostname) |
Vasyl Saienko | 3ab29c9 | 2020-01-03 10:39:03 +0200 | [diff] [blame] | 386 | } |
| 387 | retry $NODE_DEPLOYMENT_RETRIES "The node didn't come up." retry_wait |
| 388 | } |
| 389 | |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 390 | function download_k8s_metadata { |
| 391 | mkdir -p /etc/k0s/ |
| 392 | mkdir -p /etc/kubernetes |
| 393 | for f in worker_token.yaml controller_token.yaml admin.conf; do |
| 394 | curl --retry 6 --retry-delay 5 -L http://${UCP_MASTER_HOST}/k0s/${f} -o /etc/k0s/${f} |
| 395 | done |
| 396 | cp /etc/k0s/admin.conf /etc/kubernetes/admin.conf |
| 397 | mkdir -p /root/.kube/ |
| 398 | cp /etc/k0s/admin.conf /root/.kube/config |
| 399 | } |
| 400 | |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 401 | function join_node { |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 402 | if kubectl --kubeconfig /etc/kubernetes/admin.conf get nodes |grep -w Ready |awk '{print $1}' |grep -q $(hostname); then |
| 403 | echo "This node is already join" |
| 404 | else |
| 405 | local type=${1} |
| 406 | function retry_join_node { |
| 407 | env -i $(docker swarm join-token $type |grep 'docker swarm join' | xargs) |
Mykyta Karpin | e2d2fda | 2023-11-23 10:41:51 +0200 | [diff] [blame] | 408 | sleep 20 && systemctl restart docker && sleep 20 |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 409 | } |
| 410 | retry 10 "Failed to join node to swarm" retry_join_node |
| 411 | fi |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 412 | } |
| 413 | |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 414 | function join_k0s_node { |
| 415 | k0s install worker --token-file /etc/k0s/worker_token.yaml |
| 416 | k0s start |
| 417 | } |
| 418 | |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 419 | function create_ucp_config { |
Oleh Hryhorov | cd1a3bd | 2020-12-04 13:21:06 +0200 | [diff] [blame] | 420 | if [[ "${SINGLE_NODE}" == true ]]; then |
| 421 | max_pods="kubelet_max_pods = 220" |
| 422 | fi |
Michael Polenchuk | 06bfa15 | 2022-02-15 17:50:04 +0400 | [diff] [blame] | 423 | if [[ "${SECURE_OVERLAY_ENABLED,,}" == true ]]; then |
| 424 | secure_overlay="secure_overlay = true |
| 425 | calico_vxlan = false" |
| 426 | fi |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 427 | kubelet_custom_flags="" |
| 428 | if [[ $KUBERNETES_CONTAINER_RUNTIME == "crio" ]]; then |
Vasyl Saienko | 05edc40 | 2024-06-11 11:17:21 +0300 | [diff] [blame] | 429 | kubelet_custom_flags='custom_kubelet_flags=["--cgroup-driver=systemd", "--container-runtime-endpoint=unix:///run/containerd/containerd.sock"]' |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 430 | fi |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 431 | if docker config ls | grep com.docker.ucp.config ; then |
| 432 | echo "Config com.docker.ucp.config already exists" |
| 433 | else |
| 434 | echo " |
Vasyl Saienko | 2fcc70b | 2020-01-02 10:09:08 +0200 | [diff] [blame] | 435 | [scheduling_configuration] |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 436 | enable_admin_ucp_scheduling = true |
Vasyl Saienko | 2fcc70b | 2020-01-02 10:09:08 +0200 | [diff] [blame] | 437 | default_node_orchestrator = \"kubernetes\" |
Vasyl Saienko | ccd3a75 | 2020-01-02 10:21:54 +0200 | [diff] [blame] | 438 | [cluster_config] |
| 439 | dns = [\"172.18.208.44\"] |
Vasyl Saienko | 06c7afe | 2022-07-01 17:53:56 +0000 | [diff] [blame] | 440 | calico_vxlan_port = \"$UCP_DOCKER_CALICO_VXLAN_PORT\" |
Oleh Hryhorov | cd1a3bd | 2020-12-04 13:21:06 +0200 | [diff] [blame] | 441 | ${max_pods} |
Michael Polenchuk | 06bfa15 | 2022-02-15 17:50:04 +0400 | [diff] [blame] | 442 | ${secure_overlay} |
Vasyl Saienko | 92133c0 | 2024-05-16 10:18:51 +0300 | [diff] [blame] | 443 | ${kubelet_custom_flags} |
Vasyl Saienko | ccd3a75 | 2020-01-02 10:21:54 +0200 | [diff] [blame] | 444 | " | docker config create com.docker.ucp.config - |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 445 | fi |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | function swarm_init { |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 449 | if docker node ls | grep $HOSTNAME; then |
| 450 | echo "This node is already part of a swarm" |
| 451 | else |
| 452 | docker swarm init --advertise-addr ${UCP_IP_ADDRESS} --data-path-addr ${UCP_IP_ADDRESS} --listen-addr ${UCP_IP_ADDRESS} --data-path-port ${UCP_DOCKER_SWARM_DATA_PORT} |
Vasyl Saienko | 80b4c59 | 2023-10-13 14:24:00 +0000 | [diff] [blame] | 453 | sleep 5 && systemctl restart docker && sleep 5 |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 454 | fi |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | function rm_ucp_config { |
| 458 | docker config rm com.docker.ucp.config |
| 459 | } |
| 460 | |
Vasyl Saienko | b58c7a5 | 2020-01-02 09:14:40 +0200 | [diff] [blame] | 461 | function install_kubectl { |
Michael Polenchuk | 92ca1b3 | 2020-11-13 15:58:38 +0400 | [diff] [blame] | 462 | local kubectl=/usr/local/bin/kubectl |
Vasyl Saienko | a94bf18 | 2023-04-01 10:42:17 +0000 | [diff] [blame] | 463 | curl --retry 6 --retry-delay 5 -L ${BINARY_BASE_URL}/openstack/bin/utils/kubectl/kubectl-${KUBECTL_VERSION}-linux -o ${kubectl} |
Michael Polenchuk | 92ca1b3 | 2020-11-13 15:58:38 +0400 | [diff] [blame] | 464 | chmod +x ${kubectl} |
Ilya Menkov | 2d22bd0 | 2020-02-14 15:01:29 +0400 | [diff] [blame] | 465 | cat << EOF >> ~/.bashrc |
| 466 | source /usr/share/bash-completion/bash_completion |
| 467 | source <(kubectl completion bash) |
| 468 | EOF |
Vasyl Saienko | b58c7a5 | 2020-01-02 09:14:40 +0200 | [diff] [blame] | 469 | } |
| 470 | |
Vasyl Saienko | 0816634 | 2020-02-28 12:20:51 +0200 | [diff] [blame] | 471 | function configure_ntp { |
Vasyl Saienko | e2c68dd | 2022-01-27 17:10:12 +0200 | [diff] [blame] | 472 | echo "" > /etc/ntp.conf |
Vasyl Saienko | 0816634 | 2020-02-28 12:20:51 +0200 | [diff] [blame] | 473 | |
Anton Samoylov | 6d2cf7b | 2020-09-01 11:35:11 +0400 | [diff] [blame] | 474 | for server in $NTP_SERVERS; do |
| 475 | cat << EOF >> /etc/ntp.conf |
| 476 | server ${server} iburst |
| 477 | EOF |
| 478 | done |
| 479 | |
| 480 | cat << EOF >> /etc/ntp.conf |
| 481 | # Set general access to this service |
| 482 | restrict -4 default kod nomodify notrap nopeer noquery |
| 483 | restrict -6 default kod nomodify notrap nopeer noquery |
| 484 | |
| 485 | # Allow access from localhost |
| 486 | restrict 127.0.0.1 |
| 487 | restrict ::1 |
| 488 | |
| 489 | # Do not listen on any interface address by default |
| 490 | interface ignore wildcard |
| 491 | interface listen lo |
| 492 | interface listen ${DEFAULT_INTERFACE} |
| 493 | |
| 494 | # Location of drift file |
| 495 | driftfile /var/lib/ntp/ntp.drift |
| 496 | EOF |
| 497 | |
ibumarskov | 3537004 | 2022-04-19 14:27:02 +0400 | [diff] [blame] | 498 | systemctl disable systemd-timesyncd |
| 499 | systemctl enable ntp |
Anton Samoylov | 6d2cf7b | 2020-09-01 11:35:11 +0400 | [diff] [blame] | 500 | systemctl restart ntp |
Vasyl Saienko | 0816634 | 2020-02-28 12:20:51 +0200 | [diff] [blame] | 501 | } |
| 502 | |
Vasyl Saienko | 5af97c3 | 2022-01-25 09:45:45 +0200 | [diff] [blame] | 503 | function wait_for_external_network { |
| 504 | function _check_access { |
| 505 | curl --connect-timeout 10 ${DOCKER_UCP_IMAGE%%/*} || (sleep 1; /bin/false) |
| 506 | } |
| 507 | retry 180 "Failed to wait for external networks reachable." _check_access |
| 508 | } |
| 509 | |
Vasyl Saienko | 2fcc70b | 2020-01-02 10:09:08 +0200 | [diff] [blame] | 510 | function prepare_network { |
Dennis Dmitriev | ea89421 | 2020-03-12 21:36:43 +0200 | [diff] [blame] | 511 | if [ -z "${CONTROL_IP_ADDRESS}" ]; then |
Vasyl Saienko | 7c59592 | 2021-03-17 13:58:13 +0200 | [diff] [blame] | 512 | wait_condition_send "FAILURE" "CONTROL_IP_ADDRESS is not found." |
Dennis Dmitriev | ea89421 | 2020-03-12 21:36:43 +0200 | [diff] [blame] | 513 | exit 1 |
| 514 | fi |
| 515 | |
Vasyl Saienko | 2fcc70b | 2020-01-02 10:09:08 +0200 | [diff] [blame] | 516 | systemctl restart systemd-resolved |
Vasyl Saienko | c14c43d | 2020-01-08 13:06:18 +0200 | [diff] [blame] | 517 | # Make sure local hostname is present in /etc/hosts |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 518 | sed -i "s/127.0.0.1 localhost/127.0.0.1 localhost\n${CONTROL_IP_ADDRESS} $(hostname -s).cluster.local $(hostname -s)/" /etc/hosts |
Vasyl Saienko | 2fcc70b | 2020-01-02 10:09:08 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Vasyl Saienko | 7d7acea | 2020-01-03 16:59:05 +0200 | [diff] [blame] | 521 | function workaround_default_forward_policy { |
Vasyl Saienko | d67e35e | 2023-09-27 14:44:01 +0000 | [diff] [blame] | 522 | local should_run=0 |
| 523 | for net in $FLOATING_NETWORK_PREFIXES; do |
| 524 | if ! iptables -nvL DOCKER-USER |grep $net; then |
| 525 | should_run=1 |
| 526 | break |
| 527 | fi |
| 528 | done |
| 529 | if [[ $should_run == 0 ]]; then |
| 530 | echo "Iptables is already configured" |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 531 | else |
| 532 | cat << EOF > /etc/iptables/rules.v4 |
Vasyl Saienko | bd34d2a | 2020-03-10 16:25:17 +0200 | [diff] [blame] | 533 | *filter |
| 534 | :DOCKER-USER - [0:0] |
| 535 | EOF |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 536 | for net in $FLOATING_NETWORK_PREFIXES; do |
Vasyl Saienko | bd34d2a | 2020-03-10 16:25:17 +0200 | [diff] [blame] | 537 | cat << EOF >> /etc/iptables/rules.v4 |
| 538 | -A DOCKER-USER -d ${net} -j ACCEPT |
| 539 | -A DOCKER-USER -s ${net} -j ACCEPT |
Vasyl Saienko | bd34d2a | 2020-03-10 16:25:17 +0200 | [diff] [blame] | 540 | EOF |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 541 | done |
Vasyl Saienko | bd34d2a | 2020-03-10 16:25:17 +0200 | [diff] [blame] | 542 | |
| 543 | cat << EOF >> /etc/iptables/rules.v4 |
| 544 | -A DOCKER-USER -j RETURN |
Vasyl Saienko | 1785c35 | 2020-03-11 11:39:40 +0200 | [diff] [blame] | 545 | COMMIT |
Vasyl Saienko | bd34d2a | 2020-03-10 16:25:17 +0200 | [diff] [blame] | 546 | EOF |
Vasyl Saienko | 02df39a | 2020-05-20 16:39:35 +0300 | [diff] [blame] | 547 | |
| 548 | #Allow access to Internet from VMs for virtualized environment. |
| 549 | cat << EOF >> /etc/iptables/rules.v4 |
| 550 | *nat |
| 551 | :POSTROUTING ACCEPT - [0:0] |
| 552 | EOF |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 553 | for net in $FLOATING_NETWORK_PREFIXES; do |
Vasyl Saienko | 02df39a | 2020-05-20 16:39:35 +0300 | [diff] [blame] | 554 | cat << EOF >> /etc/iptables/rules.v4 |
| 555 | -A POSTROUTING -s ${net} -o ${DEFAULT_INTERFACE} -j MASQUERADE |
| 556 | EOF |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 557 | done |
Vasyl Saienko | 02df39a | 2020-05-20 16:39:35 +0300 | [diff] [blame] | 558 | |
| 559 | cat << EOF >> /etc/iptables/rules.v4 |
| 560 | COMMIT |
| 561 | EOF |
Denis | caa72dd | 2021-06-04 17:13:05 +0300 | [diff] [blame] | 562 | sudo netfilter-persistent reload |
| 563 | fi |
Vasyl Saienko | 7d7acea | 2020-01-03 16:59:05 +0200 | [diff] [blame] | 564 | } |
| 565 | |
Dennis Dmitriev | ea89421 | 2020-03-12 21:36:43 +0200 | [diff] [blame] | 566 | function disable_rp_filter { |
| 567 | # Run this func before "network_config" to create new interfaces with the default rp_filter value |
| 568 | cat << EOF > /etc/sysctl.d/99-disable-rp-filter.conf |
| 569 | net.ipv4.conf.all.rp_filter=0 |
| 570 | net.ipv4.conf.default.rp_filter=0 |
| 571 | EOF |
Vasyl Saienko | e61a98c | 2021-10-19 21:42:19 +0300 | [diff] [blame] | 572 | for iface in $(find /proc/sys/net/ipv4/conf/ -name "enp*" -o -name "ens*" -o -name "eth*"); do |
| 573 | echo 0 > $iface/rp_filter |
Oleh Hryhorov | 207137d | 2021-04-13 12:03:39 +0300 | [diff] [blame] | 574 | done |
| 575 | |
Dennis Dmitriev | ea89421 | 2020-03-12 21:36:43 +0200 | [diff] [blame] | 576 | sysctl -p /etc/sysctl.d/99-disable-rp-filter.conf |
| 577 | } |
| 578 | |
Vasyl Saienko | 45280eb | 2024-06-24 11:45:13 +0000 | [diff] [blame] | 579 | function configure_sysctl_limits { |
| 580 | cat << EOF > /etc/sysctl.d/99-limits.conf |
| 581 | fs.inotify.max_user_instances = 8192 |
| 582 | EOF |
| 583 | sysctl -p /etc/sysctl.d/99-limits.conf |
| 584 | } |
| 585 | |
Vasyl Saienko | 83f309e | 2020-05-06 11:14:28 +0300 | [diff] [blame] | 586 | function configure_contrack { |
| 587 | cat << EOF > /etc/sysctl.d/100-contrackd.conf |
| 588 | net.netfilter.nf_conntrack_log_invalid=255 |
| 589 | net.netfilter.nf_conntrack_tcp_be_liberal=1 |
| 590 | EOF |
| 591 | |
| 592 | sysctl -p /etc/sysctl.d/100-contrackd.conf |
| 593 | } |
| 594 | |
Vasyl Saienko | b377de0 | 2020-05-25 14:51:31 +0300 | [diff] [blame] | 595 | # NOTE(vsaienko): disable calling iptables when sending packets via bridge. |
| 596 | function disable_iptables_for_bridges { |
| 597 | cat << EOF > /etc/sysctl.d/101-bridge-nf-call-iptables.conf |
| 598 | net.bridge.bridge-nf-call-ip6tables=0 |
| 599 | net.bridge.bridge-nf-call-iptables=0 |
| 600 | net.bridge.bridge-nf-call-arptables=0 |
| 601 | EOF |
| 602 | |
| 603 | sysctl -p /etc/sysctl.d/101-bridge-nf-call-iptables.conf |
| 604 | } |
| 605 | |
Oleh Hryhorov | b58460e | 2020-02-05 15:53:48 +0200 | [diff] [blame] | 606 | function network_config { |
Vasyl Saienko | 9b68899 | 2020-02-13 13:50:53 +0200 | [diff] [blame] | 607 | PUBLIC_NODE_IP_ADDRESS=${PUBLIC_INTERFACE_IP:-$(ip addr show dev ${PUBLIC_INTERFACE} | grep -Po 'inet \K[\d.]+' | egrep -v "127.0.|172.17")} |
| 608 | PUBLIC_NODE_IP_NETMASK=${PUBLIC_INTERFACE_NETMASK:-$(ip addr show dev ${PUBLIC_INTERFACE} | grep -Po 'inet \K[\d.]+\/[\d]+' | egrep -v "127.0.|172.17" | cut -d'/' -f2)} |
| 609 | |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 610 | local public_interface=${1:-${PUBLIC_INTERFACE}} |
| 611 | local cloud_netplan_cfg="/etc/netplan/50-cloud-init.yaml" |
| 612 | local match_ip_line |
Vasyl Saienko | 9b68899 | 2020-02-13 13:50:53 +0200 | [diff] [blame] | 613 | |
Vasyl Saienko | 300bb0b | 2023-04-19 06:52:53 +0000 | [diff] [blame] | 614 | install_pkgs bridge-utils |
Mykyta Karpin | 5ed5fd8 | 2020-01-27 18:23:29 +0200 | [diff] [blame] | 615 | |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 616 | cat << EOF > /etc/systemd/network/10-veth-phy-br.netdev |
| 617 | [NetDev] |
| 618 | Name=veth-phy |
| 619 | Kind=veth |
| 620 | [Peer] |
| 621 | Name=veth-br |
| 622 | EOF |
Vasyl Saienko | 9b68899 | 2020-02-13 13:50:53 +0200 | [diff] [blame] | 623 | |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 624 | if [[ -n ${IRONIC_BAREMETAL_INTERFACE} ]]; then |
| 625 | |
Vasyl Saienko | 4c46819 | 2020-05-19 11:51:13 +0300 | [diff] [blame] | 626 | cat << EOF > /etc/systemd/network/11-veth-bm.netdev |
| 627 | [NetDev] |
| 628 | Name=veth-bm |
| 629 | Kind=veth |
| 630 | [Peer] |
| 631 | Name=veth-bm-br |
| 632 | EOF |
| 633 | |
Vasyl Saienko | 1233afd | 2020-05-21 14:55:21 +0300 | [diff] [blame] | 634 | cat << EOF > /etc/systemd/network/12-veth-vbmc.netdev |
| 635 | [NetDev] |
| 636 | Name=veth-vbmc |
| 637 | Kind=veth |
| 638 | [Peer] |
| 639 | Name=veth-vbmc-br |
| 640 | EOF |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 641 | fi |
Vasyl Saienko | 1233afd | 2020-05-21 14:55:21 +0300 | [diff] [blame] | 642 | |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 643 | sed -i 's/.*ethernets:.*/&\n veth-phy: {}/' ${cloud_netplan_cfg} |
| 644 | sed -i 's/.*ethernets:.*/&\n veth-br: {}/' ${cloud_netplan_cfg} |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 645 | if [[ -n ${IRONIC_BAREMETAL_INTERFACE} ]]; then |
Vasyl Saienko | 4c46819 | 2020-05-19 11:51:13 +0300 | [diff] [blame] | 646 | sed -i 's/.*ethernets:.*/&\n veth-bm: {}/' ${cloud_netplan_cfg} |
| 647 | sed -i 's/.*ethernets:.*/&\n veth-bm-br: {}/' ${cloud_netplan_cfg} |
Vasyl Saienko | 1233afd | 2020-05-21 14:55:21 +0300 | [diff] [blame] | 648 | sed -i 's/.*ethernets:.*/&\n veth-vbmc: {}/' ${cloud_netplan_cfg} |
| 649 | sed -i 's/.*ethernets:.*/&\n veth-vbmc-br: {}/' ${cloud_netplan_cfg} |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 650 | |
Michael Polenchuk | 486cadf | 2020-08-24 16:25:51 +0400 | [diff] [blame] | 651 | if [[ "${IRONIC_MT_ENABLED,,}" == true ]] ; then |
| 652 | sed -i "s/.*ethernets:.*/&\n ${IRONIC_BAREMETAL_VXLAN_INTERFACE}: {}/" ${cloud_netplan_cfg} |
| 653 | sed -i 's/.*ethernets:.*/&\n veth-pxe: {}/' ${cloud_netplan_cfg} |
| 654 | sed -i 's/.*ethernets:.*/&\n veth-pxe-br: {}/' ${cloud_netplan_cfg} |
| 655 | cat << EOF > /etc/systemd/network/13-veth-pxe.netdev |
| 656 | [NetDev] |
| 657 | Name=veth-pxe |
| 658 | Kind=veth |
| 659 | [Peer] |
| 660 | Name=veth-pxe-br |
| 661 | EOF |
| 662 | sed -i "s/- ${IRONIC_BAREMETAL_NETWORK_PREFIX}\([0-9]*\)/- ${IRONIC_BAREMETAL_TUNNEL_NETWORK_PREFIX}\1/" ${cloud_netplan_cfg} |
| 663 | cat << EOF >> ${cloud_netplan_cfg} |
| 664 | vlans: |
| 665 | pxe.1000: |
| 666 | id: 1000 |
| 667 | link: veth-pxe |
| 668 | addresses: |
| 669 | - ${IRONIC_BAREMETAL_INTERFACE_IP}/${IRONIC_BAREMETAL_NETWORK_NETMASK} |
| 670 | EOF |
| 671 | else |
| 672 | ironic_baremetal_address_match_ip_line=$(grep -nm1 "${IRONIC_BAREMETAL_INTERFACE_IP}/${IRONIC_BAREMETAL_NETWORK_NETMASK}" ${cloud_netplan_cfg} | cut -d: -f1) |
| 673 | sed -i "$((${ironic_baremetal_address_match_ip_line}-1)),$((${ironic_baremetal_address_match_ip_line}))d" ${cloud_netplan_cfg} |
| 674 | fi |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 675 | fi |
Vasyl Saienko | 4c46819 | 2020-05-19 11:51:13 +0300 | [diff] [blame] | 676 | |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 677 | public_address_match_ip_line=$(grep -nm1 "${PUBLIC_NODE_IP_ADDRESS}/${PUBLIC_NODE_IP_NETMASK}" ${cloud_netplan_cfg} | cut -d: -f1) |
Denis | 20740c2 | 2021-06-17 18:09:46 +0300 | [diff] [blame] | 678 | if [ -n "${public_address_match_ip_line}" ] ; then |
| 679 | sed -i "$((${public_address_match_ip_line}-1)),$((${public_address_match_ip_line}))d" ${cloud_netplan_cfg} |
| 680 | fi |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 681 | |
| 682 | cat << EOF >> ${cloud_netplan_cfg} |
| 683 | bridges: |
| 684 | br-public: |
| 685 | dhcp4: false |
| 686 | interfaces: |
| 687 | - ${PUBLIC_INTERFACE} |
| 688 | - veth-br |
| 689 | addresses: |
| 690 | - ${PUBLIC_NODE_IP_ADDRESS}/${PUBLIC_NODE_IP_NETMASK} |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 691 | EOF |
Vasyl Saienko | 5b6d70a | 2023-04-10 13:55:31 +0000 | [diff] [blame] | 692 | # Assign more ips for neutron dynamic routing PRODX-31417 |
| 693 | if [[ ${NODE_METADATA} == *"tempest"* ]]; then |
| 694 | for i in {71..76}; do |
| 695 | cat << EOF >> ${cloud_netplan_cfg} |
Vasyl Saienko | c763900 | 2023-04-11 07:40:29 +0000 | [diff] [blame] | 696 | - ${PUBLIC_NODE_IP_ADDRESS%.*}.${i}/${PUBLIC_NODE_IP_NETMASK} |
Vasyl Saienko | 5b6d70a | 2023-04-10 13:55:31 +0000 | [diff] [blame] | 697 | EOF |
| 698 | done |
| 699 | fi |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 700 | |
Vasyl Saienko | f79d094 | 2020-11-17 14:33:55 +0200 | [diff] [blame] | 701 | # Remove Tunnel interface from netplan |
| 702 | if [[ $TUNNEL_INTERFACE_NETPLAN_MANAGE == false ]]; then |
| 703 | sed -i "/ ${TUNNEL_INTERFACE}/,/ set-name: ${TUNNEL_INTERFACE}/d" ${cloud_netplan_cfg} |
| 704 | fi |
| 705 | |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 706 | if [[ -n ${IRONIC_BAREMETAL_INTERFACE} ]]; then |
| 707 | cat << EOF >> ${cloud_netplan_cfg} |
Vasyl Saienko | 4c46819 | 2020-05-19 11:51:13 +0300 | [diff] [blame] | 708 | br-baremetal: |
| 709 | dhcp4: false |
| 710 | interfaces: |
Vasyl Saienko | 4c46819 | 2020-05-19 11:51:13 +0300 | [diff] [blame] | 711 | - veth-bm-br |
Vasyl Saienko | 1233afd | 2020-05-21 14:55:21 +0300 | [diff] [blame] | 712 | - veth-vbmc-br |
Michael Polenchuk | 486cadf | 2020-08-24 16:25:51 +0400 | [diff] [blame] | 713 | EOF |
| 714 | if [[ "${IRONIC_MT_ENABLED,,}" != true ]] ; then |
| 715 | cat << EOF >> ${cloud_netplan_cfg} |
| 716 | - ${IRONIC_BAREMETAL_INTERFACE} |
Vasyl Saienko | 4c46819 | 2020-05-19 11:51:13 +0300 | [diff] [blame] | 717 | addresses: |
| 718 | - ${IRONIC_BAREMETAL_INTERFACE_IP}/${IRONIC_BAREMETAL_NETWORK_NETMASK} |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 719 | EOF |
Michael Polenchuk | 486cadf | 2020-08-24 16:25:51 +0400 | [diff] [blame] | 720 | else |
| 721 | cat << EOF >> ${cloud_netplan_cfg} |
| 722 | - ${IRONIC_BAREMETAL_VXLAN_INTERFACE} |
| 723 | - veth-pxe-br |
| 724 | EOF |
Vasyl Saienko | 3dd0c27 | 2020-11-16 17:20:07 +0200 | [diff] [blame] | 725 | |
Michael Polenchuk | 486cadf | 2020-08-24 16:25:51 +0400 | [diff] [blame] | 726 | cat << EOF > /etc/systemd/system/ironic-vxlan-tunnel.service |
| 727 | [Unit] |
| 728 | Description=Ironic VXLAN tunnel |
| 729 | After=network.target |
| 730 | |
| 731 | [Service] |
| 732 | Type=oneshot |
| 733 | RemainAfterExit=true |
| 734 | ExecStart=/sbin/ip link add ${IRONIC_BAREMETAL_VXLAN_INTERFACE} type vxlan id 10 group 239.1.1.10 dstport 0 dev ${IRONIC_BAREMETAL_INTERFACE} |
| 735 | ExecStart=/sbin/ip link set ${IRONIC_BAREMETAL_VXLAN_INTERFACE} up |
| 736 | |
| 737 | [Install] |
| 738 | WantedBy=multi-user.target |
| 739 | EOF |
| 740 | |
| 741 | systemctl enable ironic-vxlan-tunnel.service |
| 742 | systemctl start ironic-vxlan-tunnel.service |
| 743 | fi |
Vasyl Saienko | 6652298 | 2020-05-25 09:34:43 +0300 | [diff] [blame] | 744 | fi |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 745 | netplan --debug apply |
Vasyl Saienko | 9b68899 | 2020-02-13 13:50:53 +0200 | [diff] [blame] | 746 | |
| 747 | # NOTE(vsaienko): give some time to apply changes |
| 748 | sleep 15 |
Vasyl Saienko | 16c81c0 | 2020-11-17 17:10:55 +0200 | [diff] [blame] | 749 | |
| 750 | # Remove Tunnel interface from netplan |
| 751 | if [[ $TUNNEL_INTERFACE_NETPLAN_MANAGE == false ]]; then |
| 752 | ip addr flush ${TUNNEL_INTERFACE} |
| 753 | ip link set ${TUNNEL_INTERFACE} up |
| 754 | fi |
| 755 | |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Oleh Hryhorov | b58460e | 2020-02-05 15:53:48 +0200 | [diff] [blame] | 758 | $functions_override |
| 759 | |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 760 | function set_node_labels { |
Vasyl Saienko | 2ae2eec | 2020-02-20 10:11:32 +0200 | [diff] [blame] | 761 | function set_node_labels_retry { |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 762 | ${_KUBECTL_CMD} patch node $(hostname) -p "{\"metadata\": $(echo $NODE_METADATA | jq -c ".")}" |
Vasyl Saienko | 2ae2eec | 2020-02-20 10:11:32 +0200 | [diff] [blame] | 763 | } |
Vasyl Saienko | 0802458 | 2020-02-20 11:45:34 +0200 | [diff] [blame] | 764 | retry 10 "Labeling node failed" set_node_labels_retry |
Oleh Hryhorov | 404e957 | 2020-01-21 18:57:22 +0200 | [diff] [blame] | 765 | } |
Gerrit MCP | bbf9d5d | 2019-12-19 13:47:41 +0100 | [diff] [blame] | 766 | |
Vasyl Saienko | 1eb06d6 | 2020-11-16 10:16:22 +0200 | [diff] [blame] | 767 | HW_METADATA='{}' |
Vasyl Saienko | f9ee158 | 2020-03-02 16:53:41 +0200 | [diff] [blame] | 768 | function prepare_metadata_files { |
Dennis Dmitriev | ea89421 | 2020-03-12 21:36:43 +0200 | [diff] [blame] | 769 | /usr/sbin/prepare-metadata.py --metadata-file /usr/share/metadata/lab-metadata.yaml |
| 770 | } |
| 771 | |
| 772 | function collect_ceph_metadata { |
Oleh Hryhorov | f14fc92 | 2020-03-10 12:11:10 +0200 | [diff] [blame] | 773 | local ceph_osd_node |
Vasyl Saienko | 8d34ad0 | 2021-07-26 11:55:23 +0300 | [diff] [blame] | 774 | ceph_osd_node=$(${_KUBECTL_CMD} get nodes -l role=ceph-osd-node -o jsonpath={.items[?\(@.metadata.name==\"$(hostname)\"\)].metadata.name}) |
Oleh Hryhorov | f14fc92 | 2020-03-10 12:11:10 +0200 | [diff] [blame] | 775 | |
Oleh Hryhorov | f14fc92 | 2020-03-10 12:11:10 +0200 | [diff] [blame] | 776 | if [[ -f /usr/share/metadata/ceph.yaml && ${ceph_osd_node} ]]; then |
Vasyl Saienko | f9ee158 | 2020-03-02 16:53:41 +0200 | [diff] [blame] | 777 | HW_METADATA="{\"ceph\": {\"$(hostname)\": \"$(base64 -w 0 /usr/share/metadata/ceph.yaml)\"}}" |
Oleh Hryhorov | 39fbfe5 | 2020-03-12 15:26:53 +0200 | [diff] [blame] | 778 | ceph_store_drive=$(cat /usr/share/metadata/ceph.yaml | egrep '\- name\: vd?' | awk '{print $3}') |
| 779 | if [[ -b /dev/${ceph_store_drive} ]]; then |
| 780 | sgdisk --zap-all /dev/${ceph_store_drive} |
| 781 | fi |
Vasyl Saienko | f9ee158 | 2020-03-02 16:53:41 +0200 | [diff] [blame] | 782 | fi |
| 783 | } |
| 784 | |
Oleh Hryhorov | e7feab4 | 2020-11-11 18:00:29 +0200 | [diff] [blame] | 785 | function collect_interfaces_metadata { |
Vasyl Saienko | 3dd0c27 | 2020-11-16 17:20:07 +0200 | [diff] [blame] | 786 | |
Oleh Hryhorov | e7feab4 | 2020-11-11 18:00:29 +0200 | [diff] [blame] | 787 | local if_metadata_file="/usr/share/metadata/interfaces.yaml" |
Denis | d2635bf | 2021-06-15 13:35:36 +0300 | [diff] [blame] | 788 | if [ -z "${TUNNEL_INTERFACE}" ] ; then |
| 789 | echo "Tunnel interface is empty" |
| 790 | else |
| 791 | pci_id=$(ethtool -i ${TUNNEL_INTERFACE} |grep bus-info | awk '{print $2}') |
| 792 | mac=$(cat $(find /sys/bus/pci/devices/${pci_id}/ -name net)/${TUNNEL_INTERFACE}/address) |
| 793 | ip=${TUNNEL_INTERFACE_IP}/${TUNNEL_INTERFACE_NETWORK_NETMASK} |
Oleh Hryhorov | e7feab4 | 2020-11-11 18:00:29 +0200 | [diff] [blame] | 794 | |
Denis | d2635bf | 2021-06-15 13:35:36 +0300 | [diff] [blame] | 795 | cat << EOF > ${if_metadata_file} |
Vasyl Saienko | 592730c | 2020-11-17 11:36:46 +0200 | [diff] [blame] | 796 | ${TUNNEL_INTERFACE}: |
Vasyl Saienko | 1152e98 | 2020-11-16 16:23:32 +0200 | [diff] [blame] | 797 | pci_id: "${pci_id}" |
| 798 | ip_addr: "${ip}" |
| 799 | mac: "${mac}" |
Oleh Hryhorov | e7feab4 | 2020-11-11 18:00:29 +0200 | [diff] [blame] | 800 | EOF |
| 801 | |
Denis | d2635bf | 2021-06-15 13:35:36 +0300 | [diff] [blame] | 802 | fi |
Oleh Hryhorov | e7feab4 | 2020-11-11 18:00:29 +0200 | [diff] [blame] | 803 | HW_METADATA=$(echo ${HW_METADATA} | jq -cr ". += {\"interfaces\": {\"$(hostname)\": \"$(base64 -w 0 ${if_metadata_file})\"}}") |
| 804 | |
| 805 | } |
| 806 | |
Oleh Hryhorov | ab3793f | 2020-06-04 18:37:22 +0300 | [diff] [blame] | 807 | function nested_virt_config { |
| 808 | |
Vasyl Saienko | e61a98c | 2021-10-19 21:42:19 +0300 | [diff] [blame] | 809 | if grep --color vmx /proc/cpuinfo; then |
| 810 | cat << EOF > /etc/modprobe.d/qemu-system-x86.conf |
Oleh Hryhorov | ab3793f | 2020-06-04 18:37:22 +0300 | [diff] [blame] | 811 | options kvm_intel nested=1 |
| 812 | options kvm_intel enable_apicv=1 |
| 813 | options kvm_intel ept=1 |
| 814 | EOF |
| 815 | |
| 816 | modprobe -r kvm_intel || true |
| 817 | modprobe kvm_intel nested=1 |
Vasyl Saienko | e61a98c | 2021-10-19 21:42:19 +0300 | [diff] [blame] | 818 | else |
| 819 | echo "Nested virtualization is not supported" |
| 820 | fi |
Oleh Hryhorov | ab3793f | 2020-06-04 18:37:22 +0300 | [diff] [blame] | 821 | |
| 822 | } |
Vasyl Saienko | f9ee158 | 2020-03-02 16:53:41 +0200 | [diff] [blame] | 823 | |
Mykyta Karpin | 6a153c5 | 2020-11-03 15:21:38 +0200 | [diff] [blame] | 824 | function configure_huge_pages { |
| 825 | local nr_2Mb |
| 826 | local nr_1G |
| 827 | local apply_grub=false |
| 828 | |
| 829 | if [[ ! $(cat /etc/default/grub | grep -E ^GRUB_CMDLINE_LINUX=".*hugepagesz=2M.*") ]] && [[ "${HUGE_PAGES_2Mb_SIZE}" -gt 0 ]]; then |
| 830 | nr_2Mb=$(( "${HUGE_PAGES_2Mb_SIZE}" / 2 )) |
| 831 | echo "Configure GRUB kernel cmd to allocate ${nr_2Mb} 2Mb huge pages" |
| 832 | echo "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX hugepagesz=2M hugepages=$nr_2Mb\"" >> /etc/default/grub |
| 833 | apply_grub=true |
| 834 | fi |
| 835 | |
| 836 | if [[ ! $(cat /etc/default/grub | grep -E ^GRUB_CMDLINE_LINUX=".*hugepagesz=1G.*") ]] && [[ "${HUGE_PAGES_1G_SIZE}" -gt 0 ]]; then |
| 837 | echo "Configure GRUB kernel cmd to allocate ${HUGE_PAGES_1G_SIZE} 1G huge pages" |
| 838 | echo "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX hugepagesz=1G hugepages=${HUGE_PAGES_1G_SIZE}\"" >> /etc/default/grub |
| 839 | apply_grub=true |
| 840 | fi |
| 841 | |
| 842 | if [[ "${apply_grub}" == true ]]; then |
| 843 | update-grub |
| 844 | cloud-init clean -r |
| 845 | else |
| 846 | echo "GRUB already configured with huge pages" |
| 847 | fi |
| 848 | } |
| 849 | |
Oleh Hryhorov | 43bbc8c | 2020-12-03 15:30:09 +0200 | [diff] [blame] | 850 | function disable_master_taint { |
| 851 | |
Oleh Hryhorov | cd1a3bd | 2020-12-04 13:21:06 +0200 | [diff] [blame] | 852 | function disable_master_taint_retry { |
| 853 | # Enable "Allow all authenticated users, including service accounts to schedule on all nodes, including UCP managers." |
| 854 | curl --retry 6 --retry-delay 5 -k -H "Authorization: Bearer $AUTHTOKEN" -k -X PUT https://${UCP_MASTER_HOST}/collectionGrants/authenticated/swarm/scheduler |
| 855 | } |
| 856 | |
| 857 | retry 10 "Can't enable permission to schedule all pods on UCP master." disable_master_taint_retry |
Oleh Hryhorov | 43bbc8c | 2020-12-03 15:30:09 +0200 | [diff] [blame] | 858 | |
| 859 | } |
| 860 | |
Vasyl Saienko | 94843cb | 2021-02-26 16:43:34 +0200 | [diff] [blame] | 861 | function disable_ipv6 { |
| 862 | cat << EOF > /etc/sysctl.d/11-ipv6-disable.conf |
| 863 | net.ipv6.conf.all.disable_ipv6 = 1 |
| 864 | net.ipv6.conf.default.disable_ipv6 = 1 |
| 865 | net.ipv6.conf.lo.disable_ipv6 = 1 |
| 866 | EOF |
| 867 | sysctl -p /etc/sysctl.d/11-ipv6-disable.conf |
| 868 | } |
| 869 | |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 870 | function setup_evpn { |
| 871 | |
| 872 | cat << EOF > /etc/netplan/60-evpn.yaml |
| 873 | network: |
| 874 | version: 2 |
| 875 | ethernets: |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 876 | EOF |
| 877 | for vni in $(seq ${FRR_EVPN_TUNNELS_RANGE}); do |
| 878 | cat << EOF >> /etc/netplan/60-evpn.yaml |
| 879 | vxlan$vni: {} |
| 880 | EOF |
| 881 | done |
| 882 | cat << EOF >> /etc/netplan/60-evpn.yaml |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 883 | bridges: |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 884 | EOF |
| 885 | for vni in $(seq ${FRR_EVPN_TUNNELS_RANGE}); do |
| 886 | cat << EOF >> /etc/netplan/60-evpn.yaml |
| 887 | br$vni: |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 888 | dhcp4: false |
Vasyl Saienko | f18b478 | 2021-03-03 14:15:40 +0200 | [diff] [blame] | 889 | link-local: [] |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 890 | parameters: |
| 891 | stp: false |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 892 | interfaces: |
| 893 | - vxlan$vni |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 894 | addresses: |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 895 | - 192.168.$vni.254/24 |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 896 | EOF |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 897 | done |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 898 | |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 899 | for vni in $(seq ${FRR_EVPN_TUNNELS_RANGE}); do |
| 900 | cat << EOF > /etc/systemd/system/evpn-vxlan-tunnel-${vni}.service |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 901 | [Unit] |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 902 | Description=EVPN tunnel ${vni} |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 903 | After=network.target |
| 904 | |
| 905 | [Service] |
| 906 | Type=oneshot |
| 907 | RemainAfterExit=true |
Vasyl Saienko | b3b8c4e | 2021-02-26 10:54:27 +0200 | [diff] [blame] | 908 | ExecStart=/sbin/ip link add vxlan${vni} type vxlan id ${vni} local ${TUNNEL_INTERFACE_IP} nolearning dstport ${FRR_EVPN_VXLAN_DST_PORT} |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 909 | ExecStart=/sbin/ip link set vxlan${vni} up |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 910 | |
| 911 | [Install] |
| 912 | WantedBy=multi-user.target |
| 913 | EOF |
Vasyl Saienko | 5f95378 | 2021-02-25 10:30:32 +0200 | [diff] [blame] | 914 | systemctl enable evpn-vxlan-tunnel-${vni}.service |
| 915 | systemctl start evpn-vxlan-tunnel-${vni}.service |
| 916 | done |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 917 | |
| 918 | netplan --debug apply |
| 919 | # NOTE(vsaienko): give some time to apply changes |
| 920 | sleep 15 |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 921 | } |
| 922 | |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 923 | function install_frr { |
| 924 | function _install_frr_packages { |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 925 | FRRVER="frr-stable" |
Oleh Hryhorov | 6243c9f | 2023-09-21 09:53:09 +0000 | [diff] [blame] | 926 | curl -s https://mirror.mirantis.com/.snapshots/frr-stable-latest/keys.asc | sudo apt-key add - |
Oleh Hryhorov | 2ae1db8 | 2023-09-21 07:39:50 +0000 | [diff] [blame] | 927 | add-apt-repository "deb [arch=amd64] https://mirror.mirantis.com/.snapshots/frr-stable-latest/ ${OS_CODENAME} ${FRRVER}" |
Vasyl Saienko | 300bb0b | 2023-04-19 06:52:53 +0000 | [diff] [blame] | 928 | install_pkgs frr frr-pythontools |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 929 | } |
| 930 | retry 3 "Can't install frr packages" _install_frr_packages |
| 931 | |
| 932 | sed -i 's/^bgpd=no/bgpd=yes/g' /etc/frr/daemons |
| 933 | |
| 934 | cat << EOF > /etc/frr/frr.conf |
| 935 | log syslog informational |
| 936 | no ipv6 forwarding |
| 937 | service integrated-vtysh-config |
| 938 | ! |
| 939 | router bgp ${FRR_BGP_AS_NUMBER} |
| 940 | bgp router-id ${FRR_ROUTER_ID} |
| 941 | no bgp default ipv4-unicast |
| 942 | bgp cluster-id ${FRR_ROUTER_ID} |
| 943 | coalesce-time 1000 |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 944 | neighbor rr peer-group |
Vasyl Saienko | b3b8c4e | 2021-02-26 10:54:27 +0200 | [diff] [blame] | 945 | neighbor rr capability extended-nexthop |
| 946 | neighbor rr remote-as ${FRR_BGP_AS_NUMBER} |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 947 | neighbor rr update-source ${FRR_BGP_SOURCE_ADDRESS} |
| 948 | EOF |
| 949 | |
| 950 | for neighbor_ip in $(echo $FRR_BGP_NEIGHBORS | tr "," "\n"); do |
| 951 | cat << EOF >> /etc/frr/frr.conf |
| 952 | neighbor $neighbor_ip peer-group rr |
| 953 | EOF |
| 954 | |
| 955 | done |
| 956 | cat << EOF >> /etc/frr/frr.conf |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 957 | ! |
| 958 | address-family ipv4 unicast |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 959 | neighbor rr activate |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 960 | exit-address-family |
| 961 | ! |
| 962 | address-family ipv4 vpn |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 963 | neighbor rr activate |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 964 | exit-address-family |
| 965 | ! |
| 966 | address-family l2vpn evpn |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 967 | neighbor rr activate |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 968 | advertise-all-vni |
| 969 | advertise-default-gw |
| 970 | exit-address-family |
| 971 | ! |
| 972 | line vty |
| 973 | ! |
| 974 | EOF |
| 975 | |
| 976 | systemctl restart frr |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 977 | |
Vasyl Saienko | 94843cb | 2021-02-26 16:43:34 +0200 | [diff] [blame] | 978 | disable_ipv6 |
Vasyl Saienko | 846c634 | 2021-02-24 17:01:36 +0200 | [diff] [blame] | 979 | setup_evpn |
Vasyl Saienko | 25bb75b | 2021-02-15 12:22:33 +0200 | [diff] [blame] | 980 | } |
| 981 | |
Mykyta Karpin | bac78b4 | 2021-12-07 11:25:03 +0200 | [diff] [blame] | 982 | function cron_disable_calico_offloading { |
Denis Biletskiy | 49b91ea | 2022-06-09 11:41:39 +0200 | [diff] [blame] | 983 | # The workaround is to disable offloading on vxlan interface |
| 984 | if [ -f /etc/cron.d/disable_calico_offloading ]; then |
| 985 | echo "Cronjob for disable callico offloading already exists" |
| 986 | else |
| 987 | script_path="/usr/sbin/calico_disable_offloading.sh" |
| 988 | cat << 'EOF' >> $script_path |
| 989 | #!/usr/bin/env bash |
| 990 | if /sbin/ethtool --show-offload vxlan.calico | grep -E '^.x-checksumming:' | grep -q ': on'; then |
| 991 | /sbin/ethtool --offload vxlan.calico rx off tx off > /dev/null |
| 992 | fi |
Mykyta Karpin | bac78b4 | 2021-12-07 11:25:03 +0200 | [diff] [blame] | 993 | EOF |
Denis Biletskiy | 49b91ea | 2022-06-09 11:41:39 +0200 | [diff] [blame] | 994 | chmod +x $script_path |
| 995 | cat << EOF >> /etc/cron.d/disable_calico_offloading |
| 996 | * * * * * root $script_path 2>&1 | /usr/bin/logger -t calico_disable_offloading |
| 997 | EOF |
| 998 | fi |
Mykyta Karpin | bac78b4 | 2021-12-07 11:25:03 +0200 | [diff] [blame] | 999 | } |
| 1000 | |
Vasyl Saienko | 114333f | 2022-05-24 09:34:51 +0000 | [diff] [blame] | 1001 | function increase_iscsi_timeout { |
| 1002 | cat <<EOF > /etc/udev/rules.d/50-iscsi-timeout.rules |
| 1003 | ACTION=="add", SUBSYSTEM=="scsi" , SYSFS{type}=="0|7|14", |
| 1004 | RUN+="/bin/sh -c 'echo 120 > /sys/block/%k/device/timeout'" |
| 1005 | EOF |
| 1006 | udevadm control --reload-rules && udevadm trigger |
| 1007 | } |