|
| 1 | +name: Helm integration tests |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + build-operator: |
| 6 | + description: "Build operator image from source (false = use published image from chart defaults)" |
| 7 | + required: false |
| 8 | + type: boolean |
| 9 | + default: true |
| 10 | + secrets: |
| 11 | + MONDOO_TEST_ORG_TOKEN: |
| 12 | + required: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-operator: |
| 19 | + if: inputs.build-operator |
| 20 | + runs-on: ubuntu-latest |
| 21 | + name: Build operator container |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 24 | + with: |
| 25 | + ref: ${{ github.event.pull_request.head.sha }} |
| 26 | + persist-credentials: false |
| 27 | + fetch-depth: 0 # fetch is needed for "git tag --list" in the Makefile |
| 28 | + - name: Import environment variables from file |
| 29 | + run: cat ".github/env" >> $GITHUB_ENV |
| 30 | + - uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 |
| 31 | + with: |
| 32 | + go-version: "${{ env.golang-version }}" |
| 33 | + - name: Build operator container image |
| 34 | + run: make docker-save |
| 35 | + - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 36 | + with: |
| 37 | + name: helm-operator-build |
| 38 | + path: operator.tar |
| 39 | + retention-days: 1 |
| 40 | + |
| 41 | + helm-tests: |
| 42 | + name: Helm integration tests (${{ matrix.k8s-version }}) |
| 43 | + runs-on: ubuntu-latest |
| 44 | + needs: [build-operator] |
| 45 | + if: always() && (needs.build-operator.result == 'success' || needs.build-operator.result == 'skipped') |
| 46 | + |
| 47 | + permissions: |
| 48 | + contents: read |
| 49 | + checks: write |
| 50 | + statuses: write |
| 51 | + |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + k8s-version: [v1.32.0, v1.35.0] |
| 56 | + |
| 57 | + steps: |
| 58 | + - name: Checkout |
| 59 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 60 | + with: |
| 61 | + fetch-depth: 0 |
| 62 | + |
| 63 | + - name: Import environment variables from file |
| 64 | + run: cat ".github/env" >> $GITHUB_ENV |
| 65 | + |
| 66 | + - name: Install Go |
| 67 | + uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 |
| 68 | + with: |
| 69 | + go-version: "${{ env.golang-version }}" |
| 70 | + |
| 71 | + - name: Start minikube |
| 72 | + uses: medyagh/setup-minikube@master |
| 73 | + with: |
| 74 | + memory: 4000m |
| 75 | + kubernetes-version: ${{ matrix.k8s-version }} |
| 76 | + |
| 77 | + - name: Install Helm |
| 78 | + uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1 |
| 79 | + with: |
| 80 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + id: install |
| 82 | + |
| 83 | + - name: Download operator build artifact |
| 84 | + if: inputs.build-operator |
| 85 | + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 |
| 86 | + with: |
| 87 | + name: helm-operator-build |
| 88 | + |
| 89 | + - name: Load operator image into minikube |
| 90 | + if: inputs.build-operator |
| 91 | + run: minikube image load operator.tar |
| 92 | + |
| 93 | + - name: Determine operator image tag |
| 94 | + id: image-tag |
| 95 | + run: | |
| 96 | + if [ "${{ inputs.build-operator }}" = "true" ]; then |
| 97 | + echo "tag=sha256-$(git rev-parse HEAD).sig" >> $GITHUB_OUTPUT |
| 98 | + else |
| 99 | + echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT |
| 100 | + fi |
| 101 | +
|
| 102 | + - name: Install Mondoo Operator Helm chart |
| 103 | + run: | |
| 104 | + HELM_ARGS="" |
| 105 | + if [ "${{ inputs.build-operator }}" = "true" ]; then |
| 106 | + HELM_ARGS="--set controllerManager.manager.image.tag=${{ steps.image-tag.outputs.tag }} --set controllerManager.manager.imagePullPolicy=Never" |
| 107 | + fi |
| 108 | + helm install mondoo-operator charts/mondoo-operator -n mondoo-operator --create-namespace --wait $HELM_ARGS |
| 109 | +
|
| 110 | + # Now that dependencies are cached the tests start almost immediately after minikube has started |
| 111 | + # this makes tests fail occasionally. This sleep gives the runner some time to become more stable |
| 112 | + # before the test execution starts. |
| 113 | + - name: Wait a bit for the runner to become more stable |
| 114 | + run: kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=60s |
| 115 | + |
| 116 | + - name: Run integration tests |
| 117 | + env: |
| 118 | + MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }} |
| 119 | + run: EXTERNAL_INSTALLATION=1 VERSION=${{ steps.image-tag.outputs.tag }} make test/integration/ci |
| 120 | + |
| 121 | + - run: mv integration-tests.xml integration-tests-helm-${{ matrix.k8s-version }}.xml |
| 122 | + if: success() || failure() |
| 123 | + |
| 124 | + - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 125 | + if: success() || failure() |
| 126 | + with: |
| 127 | + name: test-results-helm-${{ matrix.k8s-version }} |
| 128 | + path: integration-tests-helm-${{ matrix.k8s-version }}.xml |
| 129 | + |
| 130 | + - name: Upload test logs artifact |
| 131 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 132 | + if: failure() |
| 133 | + with: |
| 134 | + name: helm-test-logs-${{ matrix.k8s-version }} |
| 135 | + path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/ |
| 136 | + |
| 137 | + report-tests: |
| 138 | + name: Report helm test results |
| 139 | + runs-on: ubuntu-latest |
| 140 | + needs: [helm-tests] |
| 141 | + if: always() |
| 142 | + permissions: |
| 143 | + actions: read |
| 144 | + contents: read |
| 145 | + checks: write |
| 146 | + pull-requests: write |
| 147 | + steps: |
| 148 | + - name: Download test results |
| 149 | + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0 |
| 150 | + with: |
| 151 | + pattern: test-results-helm-* |
| 152 | + merge-multiple: true |
| 153 | + |
| 154 | + - name: Publish Test Results |
| 155 | + uses: EnricoMi/publish-unit-test-result-action@27d65e188ec43221b20d26de30f4892fad91df2f # v2.22.0 |
| 156 | + with: |
| 157 | + commit: ${{ github.event.workflow_run.head_sha }} |
| 158 | + event_file: ${{ github.event_path }} |
| 159 | + event_name: ${{ github.event.workflow_run.event }} |
| 160 | + files: "*.xml" |
0 commit comments