Skip to content

Commit

Permalink
Test: refactor cluster name
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 authored and adamjensenbot committed Sep 27, 2024
1 parent f77bc08 commit 1df7e6e
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 71 deletions.
13 changes: 4 additions & 9 deletions test/e2e/pipeline/infra/aks/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,18 @@ error() {
}
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR

CLUSTER_NAME=cluster
RUNNER_NAME=${RUNNER_NAME:-"test"}
CLUSTER_NAME="${RUNNER_NAME}-${CLUSTER_NAME}"

PIDS=()

# Cleaning all remaining clusters
for i in $(seq 1 "${CLUSTER_NUMBER}")
do
AKS_RESOURCE_GROUP="liqo${i}"
RUNNER_NAME=${RUNNER_NAME:-"test"}
AKS_CLUSTER_NAME="${RUNNER_NAME}-cluster${i}"
CLUSTER_NAME=$(forge_clustername "${i}")

# if the cluster exists, delete it
if az aks show --resource-group "${AKS_RESOURCE_GROUP}" --name "${AKS_CLUSTER_NAME}" &> /dev/null; then
echo "Deleting cluster ${CLUSTER_NAME}${i}"
az aks delete --resource-group "${AKS_RESOURCE_GROUP}" --name "${AKS_CLUSTER_NAME}" --yes &
if az aks show --resource-group "${AKS_RESOURCE_GROUP}" --name "${CLUSTER_NAME}" &> /dev/null; then
echo "Deleting cluster ${CLUSTER_NAME}"
az aks delete --resource-group "${AKS_RESOURCE_GROUP}" --name "${CLUSTER_NAME}" --yes &
PIDS+=($!)
else
echo "Cluster ${CLUSTER_NAME}${i} does not exist"
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/pipeline/infra/aks/pre-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

setup_arch_and_os
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/pipeline/infra/aks/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

NUM_NODES="2"
Expand Down Expand Up @@ -93,8 +95,7 @@ PIDS=()
for i in $(seq 1 "${CLUSTER_NUMBER}");
do
AKS_RESOURCE_GROUP="liqo${i}"
RUNNER_NAME=${RUNNER_NAME:-"test"}
AKS_CLUSTER_NAME="${RUNNER_NAME}-cluster${i}"
AKS_CLUSTER_NAME=$(forge_clustername "${i}")
REGION=${REGIONS[$i-1]}
KUBECONFIG="${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"

Expand Down
12 changes: 8 additions & 4 deletions test/e2e/pipeline/infra/cluster-api/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ error() {
}
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR

CLUSTER_NAME=cluster
RUNNER_NAME=${RUNNER_NAME:-"test"}
CAPI_CLUSTER_NAME="${RUNNER_NAME}-${CLUSTER_NAME}"
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

# Cleaning all remaining clusters
for i in $(seq 1 "${CLUSTER_NUMBER}")
do
${KUBECTL} delete clusters.cluster.x-k8s.io --namespace=liqo-ci "${CAPI_CLUSTER_NAME}${i}" --ignore-not-found
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
${KUBECTL} delete clusters.cluster.x-k8s.io --namespace=liqo-ci "${CAPI_CLUSTER_NAME}" --ignore-not-found
done
2 changes: 2 additions & 0 deletions test/e2e/pipeline/infra/cluster-api/cni.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=./pre-requirements.sh
source "$WORKDIR/pre-requirements.sh"

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

Expand Down
1 change: 1 addition & 0 deletions test/e2e/pipeline/infra/cluster-api/pre-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

Expand Down
25 changes: 12 additions & 13 deletions test/e2e/pipeline/infra/cluster-api/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

# shellcheck disable=SC1091
# shellcheck source=./cni.sh
source "$WORKDIR/cni.sh"

CLUSTER_NAME=cluster

export K8S_VERSION=${K8S_VERSION:-"1.29.7"}
K8S_VERSION=$(echo -n "$K8S_VERSION" | sed 's/v//g') # remove the leading v

Expand All @@ -56,20 +56,18 @@ export POD_CIDR_OVERLAPPING=${POD_CIDR_OVERLAPPING:-"false"}

TARGET_NAMESPACE="liqo-ci"

RUNNER_NAME=${RUNNER_NAME:-"test"}
CAPI_CLUSTER_NAME="${RUNNER_NAME}-${CLUSTER_NAME}"

for i in $(seq 1 "${CLUSTER_NUMBER}");
do
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
export POD_CIDR="10.$((i * 10)).0.0/16"
fi
echo "Creating cluster ${CLUSTER_NAME}${i}"
echo "Creating cluster ${CAPI_CLUSTER_NAME}"
POD_CIDR_ESC_1=$(echo $POD_CIDR | cut -d'/' -f1)
POD_CIDR_ESC_2=$(echo $POD_CIDR | cut -d'/' -f2)
POD_CIDR_ESC="${POD_CIDR_ESC_1}\/${POD_CIDR_ESC_2}"
clusterctl generate cluster "${CAPI_CLUSTER_NAME}${i}" \
clusterctl generate cluster "${CAPI_CLUSTER_NAME}" \
--kubernetes-version "$K8S_VERSION" \
--control-plane-machine-count 1 \
--worker-machine-count 2 \
Expand All @@ -79,21 +77,22 @@ done

for i in $(seq 1 "${CLUSTER_NUMBER}");
do
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
export POD_CIDR="10.$((i * 10)).0.0/16"
fi
echo "Waiting for cluster ${CLUSTER_NAME}${i} to be ready"
"${KUBECTL}" wait --for condition=Ready=true -n "$TARGET_NAMESPACE" "clusters.cluster.x-k8s.io/${CAPI_CLUSTER_NAME}${i}" --timeout=-1s
echo "Waiting for cluster ${CAPI_CLUSTER_NAME} to be ready"
"${KUBECTL}" wait --for condition=Ready=true -n "$TARGET_NAMESPACE" "clusters.cluster.x-k8s.io/${CAPI_CLUSTER_NAME}" --timeout=-1s

echo "Getting kubeconfig for cluster ${CLUSTER_NAME}${i}"
echo "Getting kubeconfig for cluster ${CAPI_CLUSTER_NAME}"
mkdir -p "${TMPDIR}/kubeconfigs"
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}${i}" > "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}" > "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"

CURRENT_CONTEXT=$("${KUBECTL}" config current-context --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}")
"${KUBECTL}" config set contexts."${CURRENT_CONTEXT}".namespace default --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"

echo "Installing ${CNI} for cluster ${CLUSTER_NAME}${i}"
echo "Installing ${CNI} for cluster ${CAPI_CLUSTER_NAME}"
"install_${CNI}" "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"

# install local-path storage class
Expand All @@ -105,6 +104,6 @@ done

for i in $(seq 1 "${CLUSTER_NUMBER}");
do
echo "Waiting for cluster ${CLUSTER_NAME}${i} CNI to be ready"
echo "Waiting for cluster ${CAPI_CLUSTER_NAME} CNI to be ready"
"wait_${CNI}" "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
done
18 changes: 11 additions & 7 deletions test/e2e/pipeline/infra/eks/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,27 @@ error() {
}
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR

CLUSTER_NAME=cluster
RUNNER_NAME=${RUNNER_NAME:-"test"}
CLUSTER_NAME="${RUNNER_NAME}-${CLUSTER_NAME}"
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

PIDS=()

# Cleaning all remaining clusters
for i in $(seq 1 "${CLUSTER_NUMBER}")
do
CLUSTER_NAME=$(forge_clustername "${i}")
# if the cluster exists, delete it
if "${EKSCTL}" get cluster --name "${CLUSTER_NAME}${i}" --region "eu-central-1" &> /dev/null; then
echo "Deleting cluster ${CLUSTER_NAME}${i}"
if "${EKSCTL}" get cluster --name "${CLUSTER_NAME}" --region "eu-central-1" &> /dev/null; then
echo "Deleting cluster ${CLUSTER_NAME}"
else
echo "Cluster ${CLUSTER_NAME}${i} does not exist"
echo "Cluster ${CLUSTER_NAME} does not exist"
continue
fi
"${EKSCTL}" delete cluster --name "${CLUSTER_NAME}${i}" --region "eu-central-1" --wait --force &
"${EKSCTL}" delete cluster --name "${CLUSTER_NAME}" --region "eu-central-1" --wait --force &
PIDS+=($!)
done

Expand Down
1 change: 1 addition & 0 deletions test/e2e/pipeline/infra/eks/pre-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

Expand Down
12 changes: 6 additions & 6 deletions test/e2e/pipeline/infra/eks/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

Expand All @@ -43,19 +44,17 @@ CLUSTER_NAME=cluster
export POD_CIDR=10.200.0.0/16
export POD_CIDR_OVERLAPPING=${POD_CIDR_OVERLAPPING:-"false"}

RUNNER_NAME=${RUNNER_NAME:-"test"}
CLUSTER_NAME="${RUNNER_NAME}-${CLUSTER_NAME}"

PIDS=()

for i in $(seq 1 "${CLUSTER_NUMBER}");
do
CLUSTER_NAME=$(forge_clustername "${i}")
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
export POD_CIDR="10.$((i * 10)).0.0/16"
fi
echo "Creating cluster ${CLUSTER_NAME}${i}"
echo "Creating cluster ${CLUSTER_NAME}"
"${EKSCTL}" create cluster \
--name "${CLUSTER_NAME}${i}" \
--name "${CLUSTER_NAME}" \
--region "eu-central-1" \
--instance-types c4.large,c5.large \
--nodes 2 \
Expand All @@ -73,6 +72,7 @@ done

for i in $(seq 1 "${CLUSTER_NUMBER}");
do
CLUSTER_NAME=$(forge_clustername "${i}")
CURRENT_CONTEXT=$("${KUBECTL}" config current-context --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}")
"${KUBECTL}" config set contexts."${CURRENT_CONTEXT}".namespace default --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"

Expand All @@ -87,6 +87,6 @@ do
"${HELM}" repo update
"${HELM}" install aws-load-balancer-controller eks/aws-load-balancer-controller \
-n kube-system \
--set clusterName="${CLUSTER_NAME}${i}" \
--set clusterName="${CLUSTER_NAME}" \
--kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
done
9 changes: 5 additions & 4 deletions test/e2e/pipeline/infra/gke/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

# shellcheck disable=SC1091
# shellcheck source=./const.sh
source "$WORKDIR/const.sh"

RUNNER_NAME=${RUNNER_NAME:-"test"}
CLUSTER_NAME=${RUNNER_NAME}-cluster

PIDS=()
for i in $(seq 1 "${CLUSTER_NUMBER}");
do
GKE_CLUSTER_ID="${CLUSTER_NAME}${i}"
GKE_CLUSTER_ID=$(forge_clustername "${i}")
GKE_CLUSTER_ZONE=${GKE_ZONES[$i-1]}

echo "Deleting cluster ${GKE_CLUSTER_ID}"
Expand Down
1 change: 1 addition & 0 deletions test/e2e/pipeline/infra/gke/pre-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

Expand Down
9 changes: 4 additions & 5 deletions test/e2e/pipeline/infra/gke/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,18 @@ function gke_generate_kubeconfig() {
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

# shellcheck disable=SC1091
# shellcheck source=./const.sh
source "$WORKDIR/const.sh"

RUNNER_NAME=${RUNNER_NAME:-"test"}
CLUSTER_NAME=${RUNNER_NAME}-cluster

PIDS=()
for i in $(seq 1 "${CLUSTER_NUMBER}");
do
GKE_CLUSTER_ID="${CLUSTER_NAME}${i}"
GKE_CLUSTER_ID=$(forge_clustername "${i}")
GKE_CLUSTER_REGION=${GKE_REGIONS[$i-1]}
GKE_CLUSTER_ZONE=${GKE_ZONES[$i-1]}

Expand All @@ -101,7 +100,7 @@ done

for i in $(seq 1 "${CLUSTER_NUMBER}");
do
GKE_CLUSTER_ID="${CLUSTER_NAME}${i}"
GKE_CLUSTER_ID=$(forge_clustername "${i}")
GKE_CLUSTER_ZONE=${GKE_ZONES[$i-1]}

gke_generate_kubeconfig "${GKE_CLUSTER_ID}" "${GKE_CLUSTER_ZONE}" "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
Expand Down
10 changes: 7 additions & 3 deletions test/e2e/pipeline/infra/k3s/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ error() {
}
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR

CLUSTER_NAME=cluster
RUNNER_NAME=${RUNNER_NAME:-"test"}
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

TARGET_NAMESPACE="liqo-ci"

for i in $(seq 1 "${CLUSTER_NUMBER}");
do
K3S_CLUSTER_NAME="${RUNNER_NAME}-${CLUSTER_NAME}${i}"
K3S_CLUSTER_NAME=$(forge_clustername "${i}")
echo "Deleting cluster ${K3S_CLUSTER_NAME}"
"${KUBECTL}" delete -n "${TARGET_NAMESPACE}" vms "${K3S_CLUSTER_NAME}-control-plane" --ignore-not-found
"${KUBECTL}" delete -n "${TARGET_NAMESPACE}" vms "${K3S_CLUSTER_NAME}-worker-1" --ignore-not-found
Expand Down
1 change: 1 addition & 0 deletions test/e2e/pipeline/infra/k3s/pre-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
FILEPATH=$(realpath "$0")
WORKDIR=$(dirname "$FILEPATH")

# shellcheck disable=SC1091
# shellcheck source=../../utils.sh
source "$WORKDIR/../../utils.sh"

Expand Down
Loading

0 comments on commit 1df7e6e

Please sign in to comment.