Skip to content

Commit

Permalink
github: Replace minikube with kind in CI
Browse files Browse the repository at this point in the history
This change replaces the use of minikube in the Build Container and
test / build discover and deploy workflow with the use of kind. We
estimate 60% decrease in run time on a cold run for the "Start Cluster"
step of 1 minute (from ~1m50s to ~45s). Even with a cached image for the
minikube run, we estimate a 25% decrease in run time (from ~1m to ~45s).
This should speed up CI workflows for future changes.

Fixes: #1746

Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
  • Loading branch information
skoeva committed Jun 26, 2024
1 parent b9e15b7 commit 9c0550f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
50 changes: 33 additions & 17 deletions .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ jobs:
with:
node-version: 20.x
- name: Start cluster
uses: medyagh/setup-minikube@latest
uses: helm/kind-action@v1
with:
cluster_name: test
# now you can run kubectl to see the pods in the cluster
- name: Try the cluster!
run: kubectl get pods -A
Expand All @@ -45,7 +47,6 @@ jobs:
if: steps.cache-image-restore.outputs.cache-hit == 'true'
run: |
export SHELL=/bin/bash
eval $(minikube -p minikube docker-env)
docker load -i ~/image-cache/headlamp-plugins-test.tar
docker load -i ~/image-cache/headlamp.tar
- name: Make a .plugins folder for testing later
Expand All @@ -70,16 +71,19 @@ jobs:
if: steps.cache-image-restore.outputs.cache-hit != 'true'
run: |
export SHELL=/bin/bash
eval $(minikube -p minikube docker-env)
DOCKER_IMAGE_VERSION=latest make image
DOCKER_IMAGE_VERSION=latest DOCKER_PLUGINS_IMAGE_NAME=headlamp-plugins-test make build-plugins-container
echo -n "verifying images:"
docker images
- name: Import images to kind
run: |
export SHELL=/bin/bash
kind load docker-image ghcr.io/headlamp-k8s/headlamp-plugins-test:latest --name test
kind load docker-image ghcr.io/headlamp-k8s/headlamp:latest --name test
- name: Test .plugins folder
if: steps.cache-image-restore.outputs.cache-hit != 'true'
run: |
export SHELL=/bin/bash
eval $(minikube -p minikube docker-env)
echo "----------------------------"
echo "Test .plugins folder is copied to the right place in the image by 'make image'"
echo "--- Files in the image /headlamp/ folder: ---"
Expand All @@ -105,28 +109,41 @@ jobs:
exit 1
fi
- name: Deploy to cluster
run:
kubectl apply -f e2e-tests/kubernetes-headlamp-ci.yaml
run: kubectl apply -f e2e-tests/kubernetes-headlamp-ci.yaml
- name: Run e2e tests
run: |
echo "------------------sleeping 3...------------------"
echo "------------------------------------sleeping 3...------------------------------------"
sleep 6
minikube service list
minikube service headlamp -n kube-system --url
kubectl get services --all-namespaces
kubectl get deployments -n kube-system
minikube logs | tail -10
echo "------------------waiting for headlamp deployment to be available...------------------"
echo "------------------Waiting for headlamp deployment to be available...------------------"
kubectl wait deployment -n kube-system headlamp --for condition=Available=True --timeout=30s
minikube service headlamp -n kube-system --url
echo "------------------opening the service------------------"
export SERVICE_URL=$(minikube service headlamp -n kube-system --url | tail -1)
echo "----------------------------------Opening the service----------------------------------"
IP_ADDRESS=$(kubectl get nodes -o=jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}')
SERVICE_PORT=$(kubectl get services headlamp -n kube-system -o=jsonpath='{.spec.ports[0].nodePort}')
export SERVICE_URL="http://${IP_ADDRESS}:${SERVICE_PORT}"
echo $SERVICE_URL
curl -L $SERVICE_URL | grep -q "Headlamp: Kubernetes Web UI"
echo "------------------Getting HEADLAMP_TOKEN------------------"
echo "--------------------------------Getting HEADLAMP_TOKEN--------------------------------"
kubectl create serviceaccount headlamp-admin --namespace kube-system
kubectl create clusterrolebinding headlamp-admin --serviceaccount=kube-system:headlamp-admin --clusterrole=cluster-admin
export HEADLAMP_TOKEN=$(kubectl create token headlamp-admin --duration 24h -n kube-system)
echo "------------------Running playwright e2e tests------------------"
echo "---------------------------------Certificate handling---------------------------------"
export KUBECONFIG=$HOME/.kube/config
ca_data=$(yq e '.clusters[0].cluster."certificate-authority-data"' $KUBECONFIG | base64 --decode)
echo "$ca_data" > ca.crt
kubectl config set-cluster kind-test --certificate-authority=$(pwd)/ca.crt --server=https://${IP_ADDRESS}:${SERVICE_PORT}
kubectl config unset clusters.kind-test.certificate-authority-data
cc_data=$(yq e '.users[0].user."client-certificate-data"' $KUBECONFIG | base64 --decode)
echo "$cc_data" > client.crt
ck_data=$(yq e '.users[0].user."client-key-data"' $KUBECONFIG | base64 --decode)
echo "$ck_data" > client.key
kubectl config set-credentials admin@kind-test --client-certificate=$(pwd)/client.crt --client-key=$(pwd)/client.key
kubectl config unset users.admin@kind-test.client-certificate-data
kubectl config unset users.admin@kind-test.client-key-data
echo "Modified kubeconfig:"
cat $KUBECONFIG
echo "-----------------------------Running playwright e2e tests-----------------------------"
cd e2e-tests
npm ci
npx playwright install --with-deps
Expand All @@ -142,7 +159,6 @@ jobs:
if: steps.cache-image-restore.outputs.cache-hit != 'true'
run: |
export SHELL=/bin/bash
eval $(minikube -p minikube docker-env)
mkdir -p ~/image-cache
docker save -o ~/image-cache/headlamp-plugins-test.tar ghcr.io/headlamp-k8s/headlamp-plugins-test
docker save -o ~/image-cache/headlamp.tar ghcr.io/headlamp-k8s/headlamp
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/kubernetes-headlamp-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
namespace: kube-system
spec:
accessModes:
- ReadWriteMany
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Expand Down

0 comments on commit 9c0550f

Please sign in to comment.