diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml new file mode 100644 index 00000000..68bed90f --- /dev/null +++ b/.github/workflows/e2e-test.yaml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 09451044..8309557e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 diff --git a/Gopkg.lock b/Gopkg.lock index ff3437c3..6da3c8f9 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -292,7 +292,7 @@ version = "v1.1.5" [[projects]] - branch = "controller-platform" + branch = "v1.0.4" digest = "1:b3d1d9f131d1e368af28b268782da9885bd963b2f13d15496ca4b7531b0259bd" name = "github.com/kubernetes-sigs/kubebuilder" packages = [ @@ -314,7 +314,7 @@ "pkg/test", ] pruneopts = "T" - revision = "29bccabffb065deea1c4cb3273313b615996588a" + revision = "f954dc7cff7e6c94d54139f936bb9d42314ad63e" [[projects]] digest = "1:50656f57259a3c6087d0e8c572d5845e3dee42c77209dd5409b6ab8595f0295e" diff --git a/hack/run-test-in-minikube.sh b/hack/run-test-in-minikube.sh new file mode 100755 index 00000000..940ef97f --- /dev/null +++ b/hack/run-test-in-minikube.sh @@ -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