Skip to content

Commit

Permalink
Merge pull request #139 from wave-k8s/e2e-test
Browse files Browse the repository at this point in the history
Add end2end test github workflow
  • Loading branch information
toelke authored Feb 12, 2024
2 parents 8a71af6 + 1b60d04 commit 08003f0
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 3 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: end2end Test
on:
- pull_request
jobs:
e2etest:
strategy:
fail-fast: false
matrix:
version:
- v1.21
- v1.29
runs-on: ubuntu-latest
name: test on minikube
steps:
- uses: actions/checkout@v4
- name: Start minikube
uses: medyagh/setup-minikube@master
with:
kubernetes-version: ${{ matrix.version }}
- name: Build and run wave
run: hack/run-test-in-minikube.sh
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
${{ runner.os }}-build-depcache-
- name: Setup test tooling
run: |
go get github.com/onsi/ginkgo/ginkgo && go get github.com/onsi/gomega/...
GO111MODULE=on go get github.com/onsi/ginkgo/ginkgo@v1.14.2
if ! [[ -x $(go env GOPATH)/bin/golangci-lint ]]; then echo "golangci-lint not found; fetching"; curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0; fi
if ! [[ -d ${{ github.workspace }}/kubebuilder_2.3.1_linux_amd64 ]]; then echo "kubebuilder not found; fetching"; curl -sSfL https://github.com/kubernetes-sigs/kubebuilder/releases/download/v2.3.1/kubebuilder_2.3.1_linux_amd64.tar.gz | tar zxvf -; fi
if ! [[ -x $(go env GOPATH)/bin/dep ]]; then echo "deplint not found; fetching"; curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh; fi
Expand Down
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions hack/run-test-in-minikube.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env bash

set -eu
set -o pipefail

helm --help > /dev/null 2>&1 || {
echo "helm is not installed"
exit 1
}

kubectl --help > /dev/null 2>&1 || {
echo "kubectl is not installed"
exit 1
}

MINIKUBE_ALREADY_RUNNING=0
kubectl get node minikube >/dev/null 2>&1 && MINIKUBE_ALREADY_RUNNING=1

minikube --help > /dev/null 2>&1 || {
echo "minikube is not installed"
exit 1
}

KUBERNETES_VERSION=${1:-v1.21}

[ $MINIKUBE_ALREADY_RUNNING -eq 0 ] && {
echo Starting minikube...
minikube start --kubernetes-version "$KUBERNETES_VERSION"
trap "minikube delete" EXIT
}

eval $(minikube -p minikube docker-env)
docker build -f ./Dockerfile -t wave-local:local .

echo Installing wave...
helm install wave charts/wave --set image.name=wave-local --set image.tag=local

while [ "$(kubectl get pods -A | grep -cEv 'Running|Completed')" -gt 1 ]; do echo Waiting for \"cluster\" to start; sleep 10; done

echo Creating test resources...
kubectl create -f - <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
name: test
data:
test: init
EOF

kubectl create -f - <<'EOF'
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["patch", "create", "get"]
EOF

kubectl create -f - <<'EOF'
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: test
subjects:
- kind: ServiceAccount
name: default
roleRef:
kind: Role
name: test
apiGroup: rbac.authorization.k8s.io
EOF

kubectl create -f - <<'EOF'
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
annotations:
wave.pusher.com/update-on-config-change: "true"
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
containers:
- name: test
image: nixery.dev/shell/kubectl
command:
- /bin/sh
- -ec
- |
sleep 60
if [ $(cat /etc/config/test) = "updated" ]; then
kubectl create configmap test-completed
elif [ $(cat /etc/config/test) = "init" ]; then
kubectl patch configmap test --type merge -p '{"data":{"test":"updated"}}'
fi
sleep infinity
volumeMounts:
- name: config
mountPath: /etc/config
volumes:
- name: config
configMap:
name: test
EOF

ctr=0
while ! kubectl get cm test-completed; do
echo Waiting for test to complete
sleep 10
ctr=$((ctr+1))
if [ "$ctr" -gt 60 ]; then
echo "Test failed"
exit 1
fi
done

echo Test passed
exit 0

0 comments on commit 08003f0

Please sign in to comment.