#!/bin/sh set -xeuo pipefail function print_help() { cat < [] EOF } if [ "$#" -lt 5 ]; then print_help exit 1 fi function at_err() { if [ -s tmp/hosts ]; then cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh-keygen -R {} fi } trap at_err ERR branch="$1" k8s_version="$2" flannel_tag="$3" flannel_cni_tag="$4" registry="$5" task_number="${6:-}" ssh_options="-o IdentitiesOnly=yes -o StrictHostKeyChecking=no" # Create VMs python3 ./main.py "$branch" # Send run/hosts to every vm cat tmp/hosts | awk '{print $1}' | xargs -I {} rsync -e "ssh $ssh_options" tmp/hosts root@{}:/etc/hosts # Restart network on every vm cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh $ssh_options root@{} "systemctl restart network" # Add insecure registry entry cat tmp/hosts | awk '{print $1}' | xargs -I {} ssh $ssh_options root@{} "mkdir -p /etc/containers/registries.conf.d" if [ -f '001-insecure-registries.conf' ]; then cat tmp/hosts | awk '{print $1}' | xargs -I {} scp $ssh_options 001-insecure-registries.conf root@{}:/etc/containers/registries.conf.d/001-insecure-registries.conf fi ansible-playbook ansible/playbook.yaml -i tmp/generated_inventory.yaml \ -e branch="$branch" \ -e k8s_version="$k8s_version" \ -e flannel_tag="$flannel_tag" \ -e flannel_cni_tag="$flannel_cni_tag" \ -e registry="$registry" \ -e task_number="$task_number" head -n 1 tmp/hosts | awk '{print $1}' | xargs -I {} rsync --mkpath root@{}:/etc/kubernetes/admin.conf ~/.kube/config kubectl apply -f - <