Skip to content

Commit 91e80d5

Browse files
authored
🐛 fix integration tests errors (#1411)
* fix: refactor mondoooperatorconfig.yaml to use set for spec properties * feat: add helm integration tests workflow and integrate with publish and tests workflows * fix: improve stability of helm integration tests by adding wait for cluster readiness * fix: update helm integration tests to use specific image tag and improve cluster readiness checks * fix: pin helm to v3 and disable createConfig in helm integration tests * fix: update helm integration tests to improve stability and skip tests for external installations
1 parent b195dcb commit 91e80d5

File tree

6 files changed

+198
-104
lines changed

6 files changed

+198
-104
lines changed

.github/workflows/helm-tests.yaml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
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+
ref: ${{ github.event.pull_request.head.sha }}
62+
persist-credentials: false
63+
fetch-depth: 0 # fetch is needed for "git tag --list" in the Makefile
64+
65+
- name: Import environment variables from file
66+
run: cat ".github/env" >> $GITHUB_ENV
67+
68+
- name: Install Go
69+
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
70+
with:
71+
go-version: "${{ env.golang-version }}"
72+
73+
- name: Start minikube
74+
uses: medyagh/setup-minikube@aba8d5ff1666d19b9549133e3b92e70d4fc52cb7 # master
75+
with:
76+
memory: 4000m
77+
kubernetes-version: ${{ matrix.k8s-version }}
78+
79+
- name: Install Helm
80+
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
81+
with:
82+
version: v3.17.0
83+
token: ${{ secrets.GITHUB_TOKEN }}
84+
id: install
85+
86+
- name: Download operator build artifact
87+
if: inputs.build-operator
88+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
89+
with:
90+
name: helm-operator-build
91+
92+
- name: Load operator image into minikube
93+
if: inputs.build-operator
94+
run: minikube image load operator.tar
95+
96+
- name: Wait for minikube to stabilize
97+
run: sleep 10
98+
99+
# Wait for the cluster to stabilize before installing anything.
100+
# Matches the pattern from integration-tests.yaml.
101+
- name: Wait for cluster to be ready
102+
run: for i in 1 2 3 4 5; do kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=180s && break || sleep 10; done
103+
104+
- name: Install Mondoo Operator Helm chart
105+
run: |
106+
HELM_ARGS="--set operator.createConfig=false"
107+
if [ "${{ inputs.build-operator }}" = "true" ]; then
108+
HELM_ARGS="$HELM_ARGS --set controllerManager.manager.image.tag=$(make print-version) --set controllerManager.manager.imagePullPolicy=Never"
109+
fi
110+
helm install mondoo-operator charts/mondoo-operator -n mondoo-operator --create-namespace --wait $HELM_ARGS
111+
112+
- name: Run integration tests
113+
env:
114+
MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
115+
run: EXTERNAL_INSTALLATION=1 make test/integration/ci
116+
117+
- run: mv integration-tests.xml integration-tests-helm-${{ matrix.k8s-version }}.xml
118+
if: success() || failure()
119+
120+
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
121+
if: success() || failure()
122+
with:
123+
name: test-results-helm-${{ matrix.k8s-version }}
124+
path: integration-tests-helm-${{ matrix.k8s-version }}.xml
125+
126+
- name: Upload test logs artifact
127+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
128+
if: failure()
129+
with:
130+
name: helm-test-logs-${{ matrix.k8s-version }}
131+
path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/
132+
133+
report-tests:
134+
name: Report helm test results
135+
runs-on: ubuntu-latest
136+
needs: [helm-tests]
137+
if: always() && !cancelled()
138+
permissions:
139+
actions: read
140+
contents: read
141+
checks: write
142+
pull-requests: write
143+
steps:
144+
- name: Download test results
145+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
146+
with:
147+
pattern: test-results-helm-*
148+
merge-multiple: true
149+
150+
- name: Publish Test Results
151+
uses: EnricoMi/publish-unit-test-result-action@27d65e188ec43221b20d26de30f4892fad91df2f # v2.22.0
152+
with:
153+
commit: ${{ github.event.workflow_run.head_sha }}
154+
event_file: ${{ github.event_path }}
155+
event_name: ${{ github.event.workflow_run.event }}
156+
files: "*.xml"

.github/workflows/publish.yaml

Lines changed: 9 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -240,107 +240,22 @@ jobs:
240240
# this should ensure the manifest is tagged latest, which is required for the install automation
241241
- release-helm
242242

243-
# publish helm chart after the release of container images is complete
243+
# Run helm integration tests using the published container images
244244
run-helm-tests:
245-
name: Run helm integration tests
246245
if: startsWith(github.ref, 'refs/tags/v')
247246
needs:
248247
- push-virtual-tag
249-
runs-on: ubuntu-latest
250-
248+
uses: ./.github/workflows/helm-tests.yaml
249+
with:
250+
build-operator: false
251251
permissions:
252252
contents: read
253+
actions: read
253254
checks: write
254255
statuses: write
255-
256-
strategy:
257-
fail-fast: false
258-
matrix:
259-
k8s-version: [v1.32.0, v1.35.0]
260-
261-
steps:
262-
- name: Checkout
263-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
264-
with:
265-
fetch-depth: 0
266-
267-
- name: Import environment variables from file
268-
run: cat ".github/env" >> $GITHUB_ENV
269-
270-
- name: Install Go
271-
uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0
272-
with:
273-
go-version: "${{ env.golang-version }}"
274-
275-
- name: Start minikube
276-
uses: medyagh/setup-minikube@master
277-
with:
278-
memory: 4000m
279-
kubernetes-version: ${{ matrix.k8s-version }}
280-
281-
- name: Install Helm
282-
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
283-
with:
284-
token: ${{ secrets.GITHUB_TOKEN }}
285-
id: install
286-
287-
- name: Extract Docker metadata
288-
id: meta
289-
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
290-
with:
291-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
292-
293-
- name: Install Mondoo Operator Helm chart
294-
run: helm install mondoo-operator charts/mondoo-operator -n mondoo-operator --create-namespace --wait
295-
296-
# Now that dependencies are cached the tests start almost immediately after minikube has started
297-
# this makes tests fail occasionally. This sleep gives the runner some time to become more stable
298-
# before the test execution starts.
299-
- name: Wait a bit for the runner to become more stable
300-
run: kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=60s
301-
302-
- name: Run integration tests
303-
env:
304-
MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
305-
run: EXTERNAL_INSTALLATION=1 VERSION=${{ steps.meta.outputs.version }} make test/integration/ci
306-
307-
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
308-
if: success() || failure() # run this step even if previous step failed
309-
with: # upload a combined archive with unit and integration test results
310-
name: test-results-helm-${{ matrix.k8s-version }}
311-
path: integration-tests-helm-${{ matrix.k8s-version }}.xml
312-
313-
- name: Upload test logs artifact
314-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
315-
if: failure()
316-
with:
317-
name: helm-test-logs-${{ matrix.k8s-version }}
318-
path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/
319-
320-
report-tests:
321-
name: Report test results
322-
runs-on: ubuntu-latest
323-
needs:
324-
- run-helm-tests
325-
permissions:
326-
actions: read # Required to read the artifact
327-
contents: read # Required to read the source
328-
checks: write # Required to write the results
329-
pull-requests: write # Required to write comments
330-
steps:
331-
- name: Download test results
332-
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
333-
with:
334-
pattern: test-results-*
335-
merge-multiple: true
336-
337-
- name: Publish Test Results
338-
uses: EnricoMi/publish-unit-test-result-action@27d65e188ec43221b20d26de30f4892fad91df2f # v2.22.0
339-
with:
340-
commit: ${{ github.event.workflow_run.head_sha }}
341-
event_file: ${{ github.event_path }}
342-
event_name: ${{ github.event.workflow_run.event }}
343-
files: "*.xml"
256+
pull-requests: write
257+
secrets:
258+
MONDOO_TEST_ORG_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
344259

345260
release-helm:
346261
name: Release helm chart
@@ -367,6 +282,7 @@ jobs:
367282
- name: Install Helm
368283
uses: azure/setup-helm@1a275c3b69536ee54be43f2070a358922e12c8d4 # v4.3.1
369284
with:
285+
version: v3.17.0
370286
token: ${{ secrets.GITHUB_TOKEN }}
371287
id: install
372288

.github/workflows/tests.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,16 @@ jobs:
4242
with:
4343
cnspecImageTag: ""
4444
secrets: inherit
45+
helm-tests:
46+
name: Helm tests
47+
needs: [unit-tests]
48+
if: needs.unit-tests.result == 'success'
49+
uses: ./.github/workflows/helm-tests.yaml
50+
permissions:
51+
contents: read
52+
actions: read
53+
checks: write
54+
statuses: write
55+
pull-requests: write
56+
secrets:
57+
MONDOO_TEST_ORG_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ LDFLAGS="-s -w -X go.mondoo.com/mondoo-operator/pkg/version.Version=$(VERSION) -
8686

8787
all: build
8888

89+
.PHONY: print-version
90+
print-version: ## Print the current VERSION
91+
@echo $(VERSION)
92+
8993
##@ General
9094

9195
# The help target prints out all targets with their descriptions organized

charts/mondoo-operator/templates/mondoooperatorconfig.yaml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@ metadata:
66
labels:
77
{{- include "mondoo-operator.labels" . | nindent 4 }}
88
spec:
9+
{{- $spec := dict }}
910
{{- if .Values.operator.httpProxy }}
10-
httpProxy: {{ .Values.operator.httpProxy | quote }}
11+
{{- $_ := set $spec "httpProxy" .Values.operator.httpProxy }}
1112
{{- end }}
1213
{{- if .Values.operator.httpsProxy }}
13-
httpsProxy: {{ .Values.operator.httpsProxy | quote }}
14+
{{- $_ := set $spec "httpsProxy" .Values.operator.httpsProxy }}
1415
{{- end }}
1516
{{- if .Values.operator.noProxy }}
16-
noProxy: {{ .Values.operator.noProxy | quote }}
17+
{{- $_ := set $spec "noProxy" .Values.operator.noProxy }}
1718
{{- end }}
1819
{{- if .Values.operator.containerProxy }}
19-
containerProxy: {{ .Values.operator.containerProxy | quote }}
20+
{{- $_ := set $spec "containerProxy" .Values.operator.containerProxy }}
2021
{{- end }}
2122
{{- if .Values.operator.imagePullSecrets }}
22-
imagePullSecrets:
23-
{{- toYaml .Values.operator.imagePullSecrets | nindent 4 }}
23+
{{- $_ := set $spec "imagePullSecrets" .Values.operator.imagePullSecrets }}
2424
{{- end }}
2525
{{- if .Values.operator.imageRegistry }}
26-
imageRegistry: {{ .Values.operator.imageRegistry | quote }}
26+
{{- $_ := set $spec "imageRegistry" .Values.operator.imageRegistry }}
2727
{{- end }}
2828
{{- if .Values.operator.registryMirrors }}
29-
registryMirrors:
30-
{{- toYaml .Values.operator.registryMirrors | nindent 4 }}
29+
{{- $_ := set $spec "registryMirrors" .Values.operator.registryMirrors }}
3130
{{- end }}
3231
{{- if .Values.operator.skipContainerResolution }}
33-
skipContainerResolution: {{ .Values.operator.skipContainerResolution }}
32+
{{- $_ := set $spec "skipContainerResolution" .Values.operator.skipContainerResolution }}
3433
{{- end }}
3534
{{- if .Values.operator.skipProxyForCnspec }}
36-
skipProxyForCnspec: {{ .Values.operator.skipProxyForCnspec }}
35+
{{- $_ := set $spec "skipProxyForCnspec" .Values.operator.skipProxyForCnspec }}
3736
{{- end }}
37+
{{- $spec | toYaml | nindent 2 }}
3838
{{- end }}

tests/integration/helm_chart_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1818
"k8s.io/apimachinery/pkg/types"
1919

20+
"go.mondoo.com/mondoo-operator/tests/framework/installer"
2021
"go.mondoo.com/mondoo-operator/tests/framework/utils"
2122
)
2223

@@ -93,6 +94,10 @@ func (s *HelmChartSuite) TestHelmTemplate() {
9394
}
9495

9596
func (s *HelmChartSuite) TestHelmInstallAndUninstall() {
97+
if _, ok := os.LookupEnv(installer.ExternalInstallationEnvVar); ok {
98+
s.T().Skip("Skipping helm install test when operator is installed externally (cluster-scoped resources conflict)")
99+
}
100+
96101
chartPath := filepath.Join(s.rootFolder, helmChartPath)
97102

98103
imageRepo := os.Getenv("MONDOO_OPERATOR_IMAGE_REPO")

0 commit comments

Comments
 (0)