From f3af4fe02d6b9d77262ae8a476ca00efc3fab679 Mon Sep 17 00:00:00 2001 From: jessebot Date: Thu, 25 Jul 2024 19:40:56 +0200 Subject: [PATCH] Add GHA ci test for S3 - Tests enabling bare minimum parameters to use S3 Object store as your primary storage. - Spin up a small MinIO instance to test that uploading a file via DAV actually creates the nextcloud storage bucket and puts the file into it. - Also changes main test name from run-tests to test Signed-off-by: jessebot --- .github/tests/minio_test_values.yaml | 23 ++++++++++++++++ .github/tests/test_upload_job.yaml | 26 ++++++++++++++++++ .github/workflows/lint-test.yaml | 40 +++++++++++++++++++++++++--- 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .github/tests/minio_test_values.yaml create mode 100644 .github/tests/test_upload_job.yaml diff --git a/.github/tests/minio_test_values.yaml b/.github/tests/minio_test_values.yaml new file mode 100644 index 00000000..d76fc68f --- /dev/null +++ b/.github/tests/minio_test_values.yaml @@ -0,0 +1,23 @@ +## minio helm chart values for use in ci tests: +# https://github.com/minio/minio/blob/master/helm/minio/values.yaml + +# make service name predictable +fullnameOverride: minio + +## minio mode, i.e. standalone or distributed +mode: standalone + +## Configure resource requests and limits +## ref: http://kubernetes.io/docs/user-guide/compute-resources/ +resources: + requests: + memory: 1Gi + +## Enable persistence using Persistent Volume Claims +## ref: http://kubernetes.io/docs/user-guide/persistent-volumes/ +persistence: + enabled: false + +# default credentials +rootUser: nextcloud +rootPassword: rootpass123 diff --git a/.github/tests/test_upload_job.yaml b/.github/tests/test_upload_job.yaml new file mode 100644 index 00000000..ec9b9a17 --- /dev/null +++ b/.github/tests/test_upload_job.yaml @@ -0,0 +1,26 @@ +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: create-nextcloud-file + namespace: nextcloud +spec: + template: + metadata: + name: create-nextcloud-file + spec: + containers: + - name: create-nextcloud-file + image: curlimages/curl + command: + - /bin/sh + - -c + - | + echo "testing123" > test_upload.txt && \ + curl \ + -w "%{http_code}" \ + -u admin:changeme \ + -T test_upload.txt \ + "http://nextcloud.nextcloud.svc.cluster.local:8080/remote.php/dav/files/admin/test_upload.txt" && \ + echo -e "\nTried to uploaded a file, test_upload.txt, to Nextcloud." + restartPolicy: Never diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index a6205de0..4c673cbc 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -56,7 +56,7 @@ jobs: if: steps.list-changed.outputs.changed == 'true' run: ct lint --target-branch ${{ github.event.repository.default_branch }} - run-tests: + test: runs-on: ubuntu-22.04 needs: [changes, lint] # only run this job if there are helm chart file changes @@ -82,6 +82,12 @@ jobs: - name: Horizontal Pod Autoscaling Enabled helm_args: '--helm-extra-set-args "--set=hpa.enabled=true --set=hpa.minPods=2 --set=hpa.maxPods=3 --set=hpa.targetCPUUtilizationPercentage=75"' + # test the helm chart with s3 as the primary storage + - name: S3 Enabled as Primary Storage + # we need to skip the clean up so we can test adding a file + helm_args: | + --namespace nextcloud --skip-clean-up --helm-extra-set-args "--set=fullnameOverride=nextcloud --set=nextcloud.objectStore.s3.enabled=true --set=nextcloud.objectStore.s3.accessKey=nextcloud --set=nextcloud.objectStore.s3.secretKey=rootpass123 --set=nextcloud.objectStore.s3.host=minio.nextcloud.svc.cluster.local --set=nextcloud.objectStore.s3.port=9000 --set=nextcloud.objectStore.s3.ssl=false --set=nextcloud.objectStore.s3.bucket=nextcloud --set=nextcloud.objectStore.s3.usePathStyle=true --set=image.flavor=fpm --set=nginx.enabled=true --set=nextcloud.host=nextcloud --set=nextcloud.trustedDomains[0]='*'" + steps: - name: Checkout uses: actions/checkout@v4 @@ -112,15 +118,43 @@ jobs: uses: helm/kind-action@v1.10.0 if: steps.list-changed.outputs.changed == 'true' + - name: Install MinIO for testing S3 as Primary Storage + if: matrix.test_cases.name == 'S3 Enabled as Primary Storage' + # installs minio community helm chart here: + # https://github.com/minio/minio/tree/master/helm/minio + run: | + helm repo add minio https://charts.min.io/ && \ + helm install minio \ + --namespace nextcloud \ + --create-namespace \ + --wait \ + --wait-for-jobs \ + --timeout 2m0s \ + --values .github/tests/minio_test_values.yaml \ + minio/minio + - name: Run chart-testing (install ${{ matrix.test_cases.name }}) id: install if: steps.list-changed.outputs.changed == 'true' run: ct install --target-branch ${{ github.event.repository.default_branch }} ${{ matrix.test_cases.helm_args }} + - name: Try adding a file to Nextcloud + if: matrix.test_cases.name == 'S3 Enabled as Primary Storage' + # applies a kubernetes job that uploads a file and then checks log of finished pod + run: | + kubectl config set-context --current --namespace=nextcloud && \ + kubectl apply -f ./.github/tests/test_upload_job.yaml --wait=true && \ + sleep 2 && \ + kubectl wait --for=condition=Complete --timeout=2m job/create-nextcloud-file && \ + echo "Here's the logs from the job:" && \ + kubectl logs --tail=-1 -f -l batch.kubernetes.io/job-name=create-nextcloud-file && \ + echo "Here's the logs from the nextcloud pod:" && \ + kubectl logs -l app.kubernetes.io/name=nextcloud + summary: runs-on: ubuntu-latest-low - needs: [changes, run-tests] + needs: [changes, test] if: always() steps: - name: Summary - run: if ${{ needs.changes.outputs.src != 'false' && needs.run-tests.result != 'success' }}; then exit 1; fi + run: if ${{ needs.changes.outputs.src != 'false' && needs.test.result != 'success' }}; then exit 1; fi