Skip to content

Commit d44e144

Browse files
committed
wip
1 parent 6997e94 commit d44e144

File tree

4 files changed

+108
-67
lines changed

4 files changed

+108
-67
lines changed

test/e2e/pipeline/infra/kubeadm/clean.sh

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
# POD_CIDR_OVERLAPPING -> the pod CIDR of the clusters is overlapping
1717
# CLUSTER_TEMPLATE_FILE -> the file where the cluster template is stored
1818

19-
set -e # Fail in case of error
20-
set -o nounset # Fail if undefined variables are used
21-
set -o pipefail # Fail if one of the piped commands fails
19+
set -e # Fail in case of error
20+
set -o nounset # Fail if undefined variables are used
21+
set -o pipefail # Fail if one of the piped commands fails
2222

2323
error() {
24-
local sourcefile=$1
25-
local lineno=$2
26-
echo "An error occurred at $sourcefile:$lineno."
24+
local sourcefile=$1
25+
local lineno=$2
26+
echo "An error occurred at $sourcefile:$lineno."
2727
}
2828
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
2929

@@ -34,9 +34,11 @@ WORKDIR=$(dirname "$FILEPATH")
3434
# shellcheck source=../../utils.sh
3535
source "$WORKDIR/../../utils.sh"
3636

37+
# Setup PATH to include BINDIR
38+
setup_path
39+
3740
# Cleaning all remaining clusters
38-
for i in $(seq 1 "${CLUSTER_NUMBER}")
39-
do
41+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
4042
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
4143
${KUBECTL} delete clusters.cluster.x-k8s.io --namespace=liqo-ci "${CAPI_CLUSTER_NAME}" --ignore-not-found
4244
done

test/e2e/pipeline/infra/kubeadm/pre-requirements.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
# POD_CIDR_OVERLAPPING -> the pod CIDR of the clusters is overlapping
1919
# CLUSTER_TEMPLATE_FILE -> the file where the cluster template is stored
2020

21-
set -e # Fail in case of error
22-
set -o nounset # Fail if undefined variables are used
23-
set -o pipefail # Fail if one of the piped commands fails
21+
set -e # Fail in case of error
22+
set -o nounset # Fail if undefined variables are used
23+
set -o pipefail # Fail if one of the piped commands fails
2424

2525
error() {
2626
local sourcefile=$1
@@ -42,4 +42,8 @@ install_kubectl "${OS}" "${ARCH}" "${K8S_VERSION}"
4242

4343
install_helm "${OS}" "${ARCH}"
4444

45+
install_krew "${OS}" "${ARCH}"
46+
47+
install_oidc
48+
4549
install_clusterctl "${OS}" "${ARCH}"

test/e2e/pipeline/infra/kubeadm/setup.sh

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
# CLUSTER_TEMPLATE_FILE -> the file where the cluster template is stored
2020
# CNI -> the CNI plugin used
2121

22-
set -e # Fail in case of error
23-
set -o nounset # Fail if undefined variables are used
24-
set -o pipefail # Fail if one of the piped commands fails
22+
set -e # Fail in case of error
23+
set -o nounset # Fail if undefined variables are used
24+
set -o pipefail # Fail if one of the piped commands fails
2525

2626
error() {
27-
local sourcefile=$1
28-
local lineno=$2
29-
echo "An error occurred at $sourcefile:$lineno."
27+
local sourcefile=$1
28+
local lineno=$2
29+
echo "An error occurred at $sourcefile:$lineno."
3030
}
3131
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
3232

@@ -38,9 +38,12 @@ WORKDIR=$(dirname "$FILEPATH")
3838
source "$WORKDIR/../../utils.sh"
3939

4040
# shellcheck disable=SC1091
41-
# shellcheck source=../cni.sh
41+
# shellcheck source=../cni.sh
4242
source "$WORKDIR/../cni.sh"
4343

44+
# Setup PATH to include BINDIR
45+
setup_path
46+
4447
export K8S_VERSION=${K8S_VERSION:-"1.29.7"}
4548
K8S_VERSION=$(echo -n "$K8S_VERSION" | sed 's/v//g') # remove the leading v
4649

@@ -56,14 +59,13 @@ export POD_CIDR_OVERLAPPING=${POD_CIDR_OVERLAPPING:-"false"}
5659

5760
TARGET_NAMESPACE="liqo-ci"
5861

59-
for i in $(seq 1 "${CLUSTER_NUMBER}");
60-
do
62+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
6163
CAPI_CLUSTER_NAME=$(forge_clustername "${i}")
62-
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
63-
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
64-
export POD_CIDR="10.$((i * 10)).0.0/16"
65-
fi
66-
echo "Creating cluster ${CAPI_CLUSTER_NAME}"
64+
if [[ ${POD_CIDR_OVERLAPPING} != "true" ]]; then
65+
# this should avoid the ipam to reserve a pod CIDR of another cluster as local external CIDR causing remapping
66+
export POD_CIDR="10.$((i * 10)).0.0/16"
67+
fi
68+
echo "Creating cluster ${CAPI_CLUSTER_NAME}"
6769
POD_CIDR_ESC_1=$(echo $POD_CIDR | cut -d'/' -f1)
6870
POD_CIDR_ESC_2=$(echo $POD_CIDR | cut -d'/' -f2)
6971
POD_CIDR_ESC="${POD_CIDR_ESC_1}\/${POD_CIDR_ESC_2}"
@@ -75,19 +77,18 @@ do
7577
--infrastructure kubevirt | sed "s/10.243.0.0\/16/$POD_CIDR_ESC/g" | ${KUBECTL} apply -f -
7678
done
7779

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

8889
echo "Getting kubeconfig for cluster ${CAPI_CLUSTER_NAME}"
8990
mkdir -p "${TMPDIR}/kubeconfigs"
90-
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}" > "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
91+
clusterctl get kubeconfig -n "$TARGET_NAMESPACE" "${CAPI_CLUSTER_NAME}" >"${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
9192

9293
CURRENT_CONTEXT=$("${KUBECTL}" config current-context --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}")
9394
"${KUBECTL}" config set contexts."${CURRENT_CONTEXT}".namespace default --kubeconfig "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
@@ -102,8 +103,7 @@ do
102103
install_metrics_server "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
103104
done
104105

105-
for i in $(seq 1 "${CLUSTER_NUMBER}");
106-
do
106+
for i in $(seq 1 "${CLUSTER_NUMBER}"); do
107107
echo "Waiting for cluster ${CAPI_CLUSTER_NAME} CNI to be ready"
108108
"wait_${CNI}" "${TMPDIR}/kubeconfigs/liqo_kubeconf_${i}"
109109
done

test/e2e/pipeline/utils.sh

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
#!/usr/bin/env bash
22
#shellcheck disable=SC1091
33

4+
# Setup PATH to include BINDIR for kubectl and other tools
5+
# This ensures credential plugins can find kubectl
6+
setup_path() {
7+
if [ -n "${BINDIR:-}" ]; then
8+
export PATH="${BINDIR}:${PATH}"
9+
fi
10+
}
11+
412
# Define the retry function
513
waitandretry() {
614
local waittime="$1"
@@ -36,29 +44,34 @@ waitandretry() {
3644
fi
3745
}
3846

39-
function setup_arch_and_os(){
47+
function setup_arch_and_os() {
4048
ARCH=$(uname -m)
4149
case $ARCH in
42-
armv5*) ARCH="armv5";;
43-
armv6*) ARCH="armv6";;
44-
armv7*) ARCH="arm";;
45-
aarch64) ARCH="arm64";;
46-
x86) ARCH="386";;
47-
x86_64) ARCH="amd64";;
48-
i686) ARCH="386";;
49-
i386) ARCH="386";;
50-
*) echo "Error architecture '${ARCH}' unknown"; exit 1 ;;
50+
armv5*) ARCH="armv5" ;;
51+
armv6*) ARCH="armv6" ;;
52+
armv7*) ARCH="arm" ;;
53+
aarch64) ARCH="arm64" ;;
54+
x86) ARCH="386" ;;
55+
x86_64) ARCH="amd64" ;;
56+
i686) ARCH="386" ;;
57+
i386) ARCH="386" ;;
58+
*)
59+
echo "Error architecture '${ARCH}' unknown"
60+
exit 1
61+
;;
5162
esac
5263

53-
OS=$(uname |tr '[:upper:]' '[:lower:]')
64+
OS=$(uname | tr '[:upper:]' '[:lower:]')
5465
case "$OS" in
5566
# Minimalist GNU for Windows
56-
"mingw"*) OS='windows'; return ;;
67+
"mingw"*)
68+
OS='windows'
69+
return
70+
;;
5771
esac
5872
}
5973

60-
61-
function check_supported_arch_and_os(){
74+
function check_supported_arch_and_os() {
6275
local supported=$1
6376
local os=$2
6477
local arch=$3
@@ -89,8 +102,7 @@ function install_kubectl() {
89102
version=$(curl -L -s https://dl.k8s.io/release/stable.txt)
90103
fi
91104

92-
if ! command -v "${KUBECTL}" &> /dev/null
93-
then
105+
if ! command -v "${KUBECTL}" &>/dev/null; then
94106
echo "WARNING: kubectl could not be found. Downloading and installing it locally..."
95107
echo "Downloading https://dl.k8s.io/release/${version}/bin/${os}/${arch}/kubectl"
96108
if ! curl --fail -Lo "${KUBECTL}" "https://dl.k8s.io/release/${version}/bin/${os}/${arch}/kubectl"; then
@@ -100,6 +112,10 @@ function install_kubectl() {
100112
fi
101113

102114
chmod +x "${KUBECTL}"
115+
116+
# Setup PATH to include BINDIR
117+
setup_path
118+
103119
echo "kubectl version:"
104120
"${KUBECTL}" version --client
105121
}
@@ -114,8 +130,7 @@ function install_helm() {
114130

115131
HELM_VERSION="v3.15.3"
116132

117-
if ! command -v "${HELM}" &> /dev/null
118-
then
133+
if ! command -v "${HELM}" &>/dev/null; then
119134
echo "WARNING: helm could not be found. Downloading and installing it locally..."
120135
if ! curl --fail -Lo "./helm-${HELM_VERSION}-${os}-${arch}.tar.gz" "https://get.helm.sh/helm-${HELM_VERSION}-${os}-${arch}.tar.gz"; then
121136
echo "Error: Unable to download helm for '${os}-${arch}'"
@@ -159,27 +174,24 @@ function install_gcloud() {
159174
cd -
160175

161176
#Login to gcloud
162-
echo "${GCLOUD_KEY}" | base64 -d > "${BINDIR}/gke_key_file.json"
177+
echo "${GCLOUD_KEY}" | base64 -d >"${BINDIR}/gke_key_file.json"
163178
"${GCLOUD}" auth activate-service-account --key-file="${BINDIR}/gke_key_file.json"
164179
"${GCLOUD}" components install gke-gcloud-auth-plugin
165180
}
166181

167182
function install_az() {
168183
local os=$1
169184

170-
if ! command -v az &> /dev/null
171-
then
172-
echo "Azure CLI could not be found. Downloading and installing..."
173-
if [[ "${os}" == "linux" ]]
174-
then
175-
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
176-
elif [[ "${os}" == "darwin" ]]
177-
then
178-
brew update && brew install azure-cli
179-
else
180-
echo "Error: Azure CLI is not supported on ${os}"
181-
exit 1
182-
fi
185+
if ! command -v az &>/dev/null; then
186+
echo "Azure CLI could not be found. Downloading and installing..."
187+
if [[ "${os}" == "linux" ]]; then
188+
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
189+
elif [[ "${os}" == "darwin" ]]; then
190+
brew update && brew install azure-cli
191+
else
192+
echo "Error: Azure CLI is not supported on ${os}"
193+
exit 1
194+
fi
183195
fi
184196

185197
echo "Azure CLI version:"
@@ -206,8 +218,7 @@ function wait_kyverno() {
206218
local kubeconfig=$1
207219

208220
# Wait for the kyverno deployments to be ready
209-
if ! waitandretry 5s 2 "${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig}"
210-
then
221+
if ! waitandretry 5s 2 "${KUBECTL} rollout status deployment -n kyverno --kubeconfig ${kubeconfig}"; then
211222
echo "Failed to wait for kyverno deployments to be ready"
212223
exit 1
213224
fi
@@ -221,3 +232,27 @@ function install_clusterctl() {
221232
sudo install -o root -g root -m 0755 clusterctl /usr/local/bin/clusterctl
222233
clusterctl version
223234
}
235+
236+
function install_krew() {
237+
local os=$1
238+
local arch=$2
239+
240+
(
241+
set -x
242+
cd "$(mktemp -d)" &&
243+
KREW="krew-${os}_${arch}" &&
244+
curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/latest/download/${KREW}.tar.gz" &&
245+
tar zxvf "${KREW}.tar.gz" &&
246+
./"${KREW}" install krew
247+
)
248+
249+
# Add krew to PATH in .bashrc if not already present
250+
echo 'export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"' >>~/.bashrc
251+
252+
# Export for current session
253+
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"
254+
}
255+
256+
function install_oidc() {
257+
"${KUBECTL}" krew install oidc-login
258+
}

0 commit comments

Comments
 (0)