|
| 1 | +name: e2e |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - master |
| 8 | + |
| 9 | +jobs: |
| 10 | + kind: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: Checkout |
| 14 | + uses: actions/checkout@v2 |
| 15 | + - name: Setup QEMU |
| 16 | + uses: docker/setup-qemu-action@v1 |
| 17 | + with: |
| 18 | + platforms: all |
| 19 | + - name: Setup Docker Buildx |
| 20 | + id: buildx |
| 21 | + uses: docker/setup-buildx-action@v1 |
| 22 | + - name: Restore Go cache |
| 23 | + uses: actions/cache@v1 |
| 24 | + with: |
| 25 | + path: ~/go/pkg/mod |
| 26 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 27 | + restore-keys: | |
| 28 | + ${{ runner.os }}-go- |
| 29 | + - name: Cache Docker layers |
| 30 | + uses: actions/cache@v2 |
| 31 | + id: cache |
| 32 | + with: |
| 33 | + path: /tmp/.buildx-cache |
| 34 | + key: ${{ runner.os }}-buildx-ghcache-${{ github.sha }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-buildx-ghcache- |
| 37 | + - name: Setup Go |
| 38 | + uses: actions/setup-go@v2 |
| 39 | + with: |
| 40 | + go-version: 1.16.x |
| 41 | + - name: Setup Kubernetes |
| 42 | + uses: engineerd/setup-kind@v0.5.0 |
| 43 | + with: |
| 44 | + version: v0.11.1 |
| 45 | + image: kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6 |
| 46 | + - name: Setup Kustomize |
| 47 | + uses: fluxcd/pkg/actions/kustomize@main |
| 48 | + - name: Setup envtest |
| 49 | + uses: fluxcd/pkg/actions/envtest@main |
| 50 | + with: |
| 51 | + version: "1.21.2" |
| 52 | + - name: Setup Helm |
| 53 | + uses: fluxcd/pkg/actions/helm@main |
| 54 | + - name: Run controller tests |
| 55 | + run: make test |
| 56 | + - name: Check if working tree is dirty |
| 57 | + run: | |
| 58 | + if [[ $(git diff --stat) != '' ]]; then |
| 59 | + git --no-pager diff |
| 60 | + echo 'run make test and commit changes' |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | + - name: Build container image |
| 64 | + run: | |
| 65 | + make docker-build IMG=test/k8sdb-controller:latest BUILD_PLATFORMS=linux/amd64 \ |
| 66 | + BUILD_ARGS="--cache-from=type=local,src=/tmp/.buildx-cache \ |
| 67 | + --cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max" |
| 68 | + - name: Move cache |
| 69 | + run: | |
| 70 | + rm -rf /tmp/.buildx-cache |
| 71 | + mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
| 72 | + - name: Load test image |
| 73 | + run: kind load docker-image test/k8sdb-controller:latest |
| 74 | + - name: Deploy controller |
| 75 | + run: make deploy IMG=test/k8sdb-controller:latest |
| 76 | + - name: Setup MongoDB |
| 77 | + env: |
| 78 | + MONGODB_VER: ${{ '10.29.2' }} |
| 79 | + run: | |
| 80 | + kubectl create ns mongodb |
| 81 | + helm repo add bitnami https://charts.bitnami.com/bitnami |
| 82 | + helm upgrade --wait -i mongodb bitnami/mongodb \ |
| 83 | + --version $MONGODB_VER \ |
| 84 | + --namespace mongodb \ |
| 85 | + --set auth.rootPassword=password \ |
| 86 | + --set persistence.enabled=false |
| 87 | + kubectl -n k8sdb-system apply -f ./config/testdata/mongodb/root-secret.yaml |
| 88 | + - name: Run MongoDB tests |
| 89 | + run: | |
| 90 | + kubectl -n k8sdb-system apply -f ./config/testdata/mongodbdatabase |
| 91 | + kubectl -n k8sdb-system apply -f ./config/testdata/mongodbuser |
| 92 | + kubectl -n k8sdb-system wait mongodbdatabase/admin --for=condition=DatabaseReady --timeout=1m |
| 93 | + kubectl -n k8sdb-system wait mongodbuser/foo --for=condition=UserReady --timeout=1m |
| 94 | + kubectl -n mongodb exec -ti deployment/mongodb mongodb -- mongo mongodb://localhost:27017/foo --authenticationDatabase=admin -u foo -p password --eval 'db.bar.insert({"foo":"bar"})' |
| 95 | + kubectl -n k8sdb-system delete -f ./config/testdata/mongodbuser |
| 96 | + ! kubectl -n mongodb exec -ti deployment/mongodb mongodb -- mongo mongodb://localhost:27017/foo --authenticationDatabase=admin -u foo -p password --eval 'db.bar.insert({"foo":"bar"})' |
| 97 | + - name: Setup PostgreSQL |
| 98 | + env: |
| 99 | + POSTGRESQL_VER: ${{ '10.13.8' }} |
| 100 | + run: | |
| 101 | + kubectl create ns postgresql |
| 102 | + helm repo add bitnami https://charts.bitnami.com/bitnami |
| 103 | + helm upgrade --wait -i postgresql bitnami/postgresql \ |
| 104 | + --version $POSTGRESQL_VER \ |
| 105 | + --namespace postgresql \ |
| 106 | + --set postgresqlPassword=password \ |
| 107 | + --set persistence.enabled=false |
| 108 | + kubectl -n k8sdb-system apply -f ./config/testdata/postgresql/root-secret.yaml |
| 109 | + - name: Run PostgreSQL tests |
| 110 | + run: | |
| 111 | + kubectl -n k8sdb-system apply -f ./config/testdata/postgresqldatabase |
| 112 | + kubectl -n k8sdb-system apply -f ./config/testdata/postgresqluser |
| 113 | + kubectl -n k8sdb-system wait postgresqldatabase/foo --for=condition=DatabaseReady --timeout=1m |
| 114 | + kubectl -n k8sdb-system wait postgresqluser/foo --for=condition=UserReady --timeout=1m |
| 115 | + kubectl -n postgresql exec -ti sts/postgresql-postgresql postgresql -- bash -c "PGPASSWORD=password psql -h localhost -U foo foo -c '\l'" |
| 116 | + kubectl -n k8sdb-system delete -f ./config/testdata/postgresqluser |
| 117 | + ! kubectl -n postgresql exec -ti sts/postgresql-postgresql postgresql -- bash -c "PGPASSWORD=password psql -h localhost -U foo foo -c '\l'" |
| 118 | + - name: Logs |
| 119 | + run: | |
| 120 | + kubectl -n k8sdb-system logs deploy/k8sdb-controller |
| 121 | + - name: Debug failure |
| 122 | + if: failure() |
| 123 | + run: | |
| 124 | + kubectl -n kube-system describe pods |
| 125 | + kubectl -n k8sdb-system describe pods |
| 126 | + kubectl -n k8sdb-system get mongodbdatabase -oyaml |
| 127 | + kubectl -n k8sdb-system get mongodbuser -oyaml |
| 128 | + kubectl -n k8sdb-system get postgresqldatabase -oyaml |
| 129 | + kubectl -n k8sdb-system get postgresqluser -oyaml |
| 130 | + kubectl -n k8sdb-system get all |
| 131 | + kubectl -n k8sdb-system logs deploy/k8sdb-controller |
| 132 | + kubectl -n mongodb get all |
| 133 | + kubectl -n postgresql get all |
0 commit comments