Skip to content

Commit

Permalink
test/e2e: add tests using multiple k8s clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Ryotaro Banno <ryotaro.banno@gmail.com>
  • Loading branch information
ushitora-anqou committed Jul 11, 2024
1 parent 4d07d80 commit 0fe8971
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 22 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/e2e-multiple-k8s-clusters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: "e2e-multiple-k8s-clusters"
on:
pull_request:
paths-ignore:
- "**/*.md"
- "CODEOWNERS"
push:
paths-ignore:
- "**/*.md"
- "CODEOWNERS"
branches:
- "main"

jobs:
build:
runs-on: "ubuntu-22.04"
#runs-on: mantle_large_runner_16core
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- run: sudo apt-get update
- run: sudo apt-get purge -y apport apport-symptoms fwupd nano netplan.io popularity-contest unattended-upgrades update-manager-core snapd
- run: sudo docker rmi $(docker image ls -aq) >/dev/null 2>&1 || true
- run: sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /usr/local/share/powershell /usr/share/swift /usr/local/.ghcup /usr/lib/jvm || true
- run: sudo apt-get purge -y $(dpkg-query -W | grep nginx | awk '{print $1}')
- run: sudo apt-get purge -y aria2 ansible azure-cli shellcheck rpm xorriso zsync firefox gfortran-9 google-chrome-stable google-cloud-sdk
- run: sudo apt-get purge -y imagemagick libmagickcore-dev libmagickwand-dev libmagic-dev ant ant-optional mercurial apt-transport-https
- run: sudo apt-get purge -y mono-complete unixodbc-dev yarn chrpath libxft-dev libfreetype6-dev libfontconfig1 libfontconfig1-dev
- run: sudo apt-get purge -y snmp pollinate libpq-dev postgresql-client powershell ruby-full sphinxsearch subversion azure-cli
- run: sudo apt-get purge -y $(dpkg-query -W | grep dotnet | awk '{print $1}')
- run: sudo apt-get autoremove -y >/dev/null 2>&1
- run: sudo apt-get autoclean -y >/dev/null 2>&1
- name: "KVM setup"
run: |-
VIRTUALIZATION_SUPPORT=$(grep -E -q 'vmx|svm' /proc/cpuinfo && echo yes || echo no)
echo ${VIRTUALIZATION_SUPPORT}
if [ "${VIRTUALIZATION_SUPPORT}" != "yes" ]; then
echo "CPU does not support the virtualization feature."
exit 1
fi
sudo apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils
kvm-ok
sudo adduser `id -un` libvirt
sudo adduser `id -un` kvm
virsh list --all
sudo ls -la /var/run/libvirt/libvirt-sock
sudo chmod 777 /var/run/libvirt/libvirt-sock
sudo ls -la /var/run/libvirt/libvirt-sock
ls -l /dev/kvm
sudo rmmod kvm_amd
sudo rmmod kvm
sudo modprobe -a kvm
sudo modprobe -a kvm_amd
- name: cache go dependencies
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: go-${{ hashFiles('go.sum', 'Makefile', 'versions.mk') }}
restore-keys: |
go-
- run: make -C test/e2e setup
- run: make -C test/e2e test-multiple-k8s-clusters
57 changes: 35 additions & 22 deletions test/e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ POLLING_INTERVAL := 1
TIMEOUT_SECS := 180
LOOP_DEV := /dev/loop0
LOOP_DEV2 := /dev/loop1
MINIKUBE_PROFILE_PRIMARY=profile1
MINIKUBE_PROFILE_SECONDARY=profile2

export MINIKUBE_HOME

Expand All @@ -34,15 +36,25 @@ setup:

.PHONY: test
test:
$(MAKE) launch-minikube
$(MAKE) image-build
$(MAKE) launch-rook-ceph
$(MAKE) setup-components
$(MAKE) launch-cluster MINIKUBE_PROFILE=$(MINIKUBE_PROFILE_PRIMARY)
$(MINIKUBE) profile $(MINIKUBE_PROFILE_PRIMARY)
$(MAKE) do_test

.PHONY: test-multiple-k8s-clusters
test-multiple-k8s-clusters:
$(MAKE) launch-cluster MINIKUBE_PROFILE=$(MINIKUBE_PROFILE_PRIMARY)
$(MAKE) launch-cluster MINIKUBE_PROFILE=$(MINIKUBE_PROFILE_SECONDARY)
$(MINIKUBE) profile $(MINIKUBE_PROFILE_PRIMARY)
env \
MINIKUBE=$(MINIKUBE) \
MINIKUBE_HOME=$(MINIKUBE_HOME) \
MINIKUBE_PROFILE_PRIMARY=$(MINIKUBE_PROFILE_PRIMARY) \
MINIKUBE_PROFILE_SECONDARY=$(MINIKUBE_PROFILE_SECONDARY) \
./test-multiple-k8s-clusters.sh

.PHONY: clean
clean:
$(MAKE) delete-minikube
$(MINIKUBE) delete --all || true

$(BINDIR):
mkdir -p $@
Expand All @@ -63,24 +75,25 @@ $(HELM): | $(BINDIR)
$(CURL) https://get.helm.sh/helm-v$(HELM_VERSION)-linux-amd64.tar.gz \
| tar xvz -C $(BINDIR) --strip-components 1 linux-amd64/helm

.PHONY: launch-minikube
launch-minikube:
.PHONY: launch-cluster
launch-cluster: MINIKUBE_PROFILE=
launch-cluster:
# TODO: Is there any better way to verify whether k8s cluster is available or not?
kubectl get pod >/dev/null 2>&1; \
RET=$$? ; \
if [ $$RET -eq 0 ] ; then exit; fi ; \
$(MINIKUBE) start \
--kubernetes-version="v$(KUBERNETES_VERSION)" \
--driver=kvm2 \
--memory 6g \
--cpus=2 \
--extra-config=kubeadm.node-name=$(NODE_NAME) \
--extra-config=kubelet.hostname-override=$(NODE_NAME)

.PHONY: delete-minikube
delete-minikube:
$(MINIKUBE) stop || true
$(MINIKUBE) delete || true
if $(MINIKUBE) profile $(MINIKUBE_PROFILE) |& grep "not found" > /dev/null; then \
$(MINIKUBE) start \
--kubernetes-version="v$(KUBERNETES_VERSION)" \
--driver=kvm2 \
--memory 6g \
--cpus=2 \
--extra-config=kubeadm.node-name=$(NODE_NAME) \
--extra-config=kubelet.hostname-override=$(NODE_NAME) \
--network mantle-test \
-p $(MINIKUBE_PROFILE) ; \
fi
$(MINIKUBE) profile $(MINIKUBE_PROFILE)
$(MAKE) image-build
$(MAKE) launch-rook-ceph
$(MAKE) setup-components

.PHONY: create-loop-dev
create-loop-dev:
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# End-to-End Tests for Mantle

## Requirements

To set up the test environment, you'll need Minikube with the KVM2 driver enabled, so make sure to enable KVM2 beforehand. Don't worry about installing Minikube yourself; it will be installed automatically.

## Usage

First, install the necessary software by running:
```
cd test/e2e
make setup
```

Next, you can start the tests:

- To run the tests using a single Kubernetes cluster:
```
make test
```
- To run the tests using multiple Kubernetes clusters:
```
make test-multiple-k8s-clusters
```

These Makefile targets are designed to be idempotent, so if you need to re-run the tests after making changes to the code, simply run the appropriate target again.

Finally, to clean up your environment, run:
```
make clean
```
53 changes: 53 additions & 0 deletions test/e2e/test-multiple-k8s-clusters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/bash -xeu

set -o pipefail

# Exits with an "unbound variable" error if one of the following environment
# variables is undefined, thanks to "-u" option to bash.
echo "${MINIKUBE}"
echo "${MINIKUBE_HOME}"
echo "${MINIKUBE_PROFILE_PRIMARY}"
echo "${MINIKUBE_PROFILE_SECONDARY}"

cat <<EOS | ${MINIKUBE} -p ${MINIKUBE_PROFILE_PRIMARY} kubectl -- apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.27.0
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: NodePort
ports:
- port: 8080
targetPort: 80
protocol: TCP
name: http
selector:
app: nginx
EOS
${MINIKUBE} -p ${MINIKUBE_PROFILE_SECONDARY} kubectl -- wait --for=jsonpath='{.status.readyReplicas}'=1 deploy/nginx

${MINIKUBE} service list -p ${MINIKUBE_PROFILE_PRIMARY}
URL=$(${MINIKUBE} service list -p ${MINIKUBE_PROFILE_PRIMARY} -o json | jq -r '.[].URLs | select(. | length > 0)[]' | head -1)

# Exits with an errornous exit code if curl fails, thanks to "-e" option to bash.
${MINIKUBE} -p ${MINIKUBE_PROFILE_SECONDARY} kubectl -- exec -it -n rook-ceph deploy/rook-ceph-tools -- curl -vvv ${URL} > /dev/null

0 comments on commit 0fe8971

Please sign in to comment.