|
| 1 | +#!/bin/bash |
| 2 | +#shellcheck disable=SC1091 |
| 3 | + |
| 4 | +# This scripts expects the following variables to be set: |
| 5 | +# CLUSTER_NUMBER -> the number of liqo clusters |
| 6 | +# K8S_VERSION -> the Kubernetes version |
| 7 | +# CNI -> the CNI plugin used |
| 8 | +# TMPDIR -> the directory where the test-related files are stored |
| 9 | +# BINDIR -> the directory where the test-related binaries are stored |
| 10 | +# TEMPLATE_DIR -> the directory where to read the cluster templates |
| 11 | +# NAMESPACE -> the namespace where liqo is running |
| 12 | +# KUBECONFIGDIR -> the directory where the kubeconfigs are stored |
| 13 | +# LIQO_VERSION -> the liqo version to test |
| 14 | +# INFRA -> the Kubernetes provider for the infrastructure |
| 15 | +# LIQOCTL -> the path where liqoctl is stored |
| 16 | +# KUBECTL -> the path where kubectl is stored |
| 17 | +# HELM -> the path where helm is stored |
| 18 | +# EKSCTL -> the path where eksctl is stored |
| 19 | +# AWS_CLI -> the path where aws-cli is stored |
| 20 | +# POD_CIDR_OVERLAPPING -> the pod CIDR of the clusters is overlapping |
| 21 | +# CLUSTER_TEMPLATE_FILE -> the file where the cluster template is stored |
| 22 | +# CNI -> the CNI plugin used |
| 23 | + |
| 24 | +set -e # Fail in case of error |
| 25 | +set -o nounset # Fail if undefined variables are used |
| 26 | +set -o pipefail # Fail if one of the piped commands fails |
| 27 | + |
| 28 | +error() { |
| 29 | + local sourcefile=$1 |
| 30 | + local lineno=$2 |
| 31 | + echo "An error occurred at $sourcefile:$lineno." |
| 32 | +} |
| 33 | +trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR |
| 34 | + |
| 35 | +FILEPATH=$(realpath "$0") |
| 36 | +WORKDIR=$(dirname "$FILEPATH") |
| 37 | + |
| 38 | +# shellcheck source=../../utils.sh |
| 39 | +source "$WORKDIR/../../utils.sh" |
| 40 | + |
| 41 | +CLUSTER_NAME=cluster |
| 42 | + |
| 43 | +export POD_CIDR=10.200.0.0/16 |
| 44 | +export POD_CIDR_OVERLAPPING=${POD_CIDR_OVERLAPPING:-"false"} |
| 45 | + |
| 46 | +RUNNER_NAME=${RUNNER_NAME:-"test"} |
| 47 | +CLUSTER_NAME="${RUNNER_NAME}-${CLUSTER_NAME}" |
| 48 | + |
| 49 | +PIDS=() |
| 50 | + |
| 51 | +for i in $(seq 1 "${CLUSTER_NUMBER}"); |
| 52 | +do |
| 53 | + if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then |
| 54 | + export POD_CIDR="10.$((i * 10)).0.0/16" |
| 55 | + fi |
| 56 | + echo "Creating cluster ${CLUSTER_NAME}${i}" |
| 57 | + "${EKSCTL}" create cluster \ |
| 58 | + --name "${CLUSTER_NAME}${i}" \ |
| 59 | + --region "eu-central-1" \ |
| 60 | + --instance-types c4.large,c5.large \ |
| 61 | + --nodes 2 \ |
| 62 | + --managed \ |
| 63 | + --alb-ingress-access \ |
| 64 | + --node-ami-family "AmazonLinux2" \ |
| 65 | + --vpc-cidr "$POD_CIDR" \ |
| 66 | + --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}" & |
| 67 | + PIDS+=($!) |
| 68 | +done |
| 69 | + |
| 70 | +for PID in "${PIDS[@]}"; do |
| 71 | + wait "${PID}" |
| 72 | +done |
| 73 | + |
| 74 | +for i in $(seq 1 "${CLUSTER_NUMBER}"); |
| 75 | +do |
| 76 | + CURRENT_CONTEXT=$("${KUBECTL}" config current-context --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}") |
| 77 | + "${KUBECTL}" config set contexts."${CURRENT_CONTEXT}".namespace default --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}" |
| 78 | + |
| 79 | + # install local-path storage class |
| 80 | + install_local_path_storage "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}" |
| 81 | + |
| 82 | + # Install metrics-server |
| 83 | + install_metrics_server "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}" |
| 84 | + |
| 85 | + # Install kyverno for network tests |
| 86 | + install_kyverno "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}" |
| 87 | + |
| 88 | + # Install AWS Load Balancer Controller |
| 89 | + "${HELM}" repo add eks https://aws.github.io/eks-charts |
| 90 | + "${HELM}" repo update |
| 91 | + "${HELM}" install aws-load-balancer-controller eks/aws-load-balancer-controller \ |
| 92 | + -n kube-system \ |
| 93 | + --set clusterName="${CLUSTER_NAME}${i}" \ |
| 94 | + --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}" |
| 95 | +done |
0 commit comments