Skip to content

Commit 806c832

Browse files
chris-rockclaude
andcommitted
⭐️ Improve Helm chart management and cleanup (#849, #821)
- Add pre-delete hook to clean up MondooAuditConfig resources on uninstall - Add cleanup subcommand to operator CLI (replaces external kubectl image) - Replace helmify-based chart generation with hand-maintained templates - Add hack/update-helm-crds.sh script to update only CRDs from generated sources - Add chart-testing (ct) linting to CI and Makefile - Add Mondoo icon to Helm chart - Add Helm chart integration tests The cleanup hook now uses the operator's own image instead of a third-party kubectl image, eliminating a supply chain dependency. Fixes #849, Fixes #821 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent feff81f commit 806c832

14 files changed

Lines changed: 1980 additions & 1045 deletions

File tree

.github/workflows/lint.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ jobs:
4040
# Disabled until existing shellcheck warnings are addressed
4141
shellcheck: false
4242

43+
helm-lint:
44+
runs-on: ubuntu-latest
45+
name: Helm Lint
46+
steps:
47+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
48+
with:
49+
fetch-depth: 0
50+
51+
- name: Set up Helm
52+
uses: azure/setup-helm@b9e51907a09c216f16ebe8536097933489208112 # v4.3.0
53+
54+
- name: Set up chart-testing
55+
uses: helm/chart-testing-action@0d28d3144d3a25ea2cc349d6e59901c4ff469b3b # v2.7.0
56+
57+
- name: Run chart-testing (lint)
58+
run: ct lint --charts charts/mondoo-operator --validate-maintainers=false
59+
4360
license-check:
4461
runs-on: ubuntu-latest
4562
steps:

Makefile

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ test/integration: manifests generate generate-manifests load-k3d
146146
else
147147
test/integration: manifests generate generate-manifests load-minikube
148148
endif
149-
go test -ldflags $(LDFLAGS) -v -timeout 20m -p 1 ./tests/integration/...
149+
MONDOO_OPERATOR_IMAGE_TAG=$(VERSION) go test -ldflags $(LDFLAGS) -v -timeout 20m -p 1 ./tests/integration/...
150150

151151
ifeq ($(K8S_DISTRO),gke)
152152
test/integration/ci: gotestsum
@@ -159,11 +159,15 @@ test/integration/ci: gotestsum load-k3d/ci
159159
else
160160
test/integration/ci: gotestsum load-minikube/ci
161161
endif
162-
$(GOTESTSUM) --junitfile integration-tests.xml -- ./tests/integration/... -ldflags $(LDFLAGS) -v -timeout 20m -p 1
162+
MONDOO_OPERATOR_IMAGE_TAG=$(VERSION) $(GOTESTSUM) --junitfile integration-tests.xml -- ./tests/integration/... -ldflags $(LDFLAGS) -v -timeout 20m -p 1
163163

164164
test/integration/external-cluster: ## Run external cluster integration test (requires k3d management cluster)
165165
K8S_DISTRO=k3d go test -ldflags $(LDFLAGS) -v -timeout 15m -p 1 ./tests/integration/... -run TestExternalClusterSuite
166166

167+
.PHONY: test/integration/helm
168+
test/integration/helm: load-k3d ## Run Helm chart integration tests
169+
MONDOO_OPERATOR_IMAGE_TAG=$(VERSION) go test -ldflags $(LDFLAGS) -v -timeout 15m -p 1 ./tests/integration/... -run TestHelmChartSuite
170+
167171
##@ Build
168172

169173
build: manifests generate fmt vet ## Build manager binary.
@@ -351,17 +355,27 @@ catalog-build: opm ## Build a catalog image.
351355
catalog-push: ## Push a catalog image.
352356
$(MAKE) docker-push IMG=$(CATALOG_IMG)
353357

354-
HELMIFY = $(LOCALBIN)/helmify
355-
helmify: $(LOCALBIN) ## Download helmify locally if necessary.
356-
GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@v0.4.18
357-
358-
helm: manifests kustomize helmify
359-
$(KUSTOMIZE) build config/default | $(HELMIFY) $(CHART_NAME)
360-
# The above command creates a helm chart, which has duplicate labels after templating
361-
# We can remove the static doublicate labels here
362-
sed -i -z 's#\(\n[[:blank:]]*selector:\)\n[[:blank:]]*app.kubernetes.io/name: mondoo-operator#\1#' charts/mondoo-operator/templates/metrics-service.yaml
363-
sed -i -z 's#\([[:blank:]]*selector:\n[[:blank:]]*matchLabels:\)\n[[:blank:]]*app.kubernetes.io/name: mondoo-operator#\1#' charts/mondoo-operator/templates/deployment.yaml
364-
sed -i -z 's#\([[:blank:]]*template:\n[[:blank:]]*metadata:\n[[:blank:]]*labels:\)\n[[:blank:]]*app.kubernetes.io/name: mondoo-operator#\1#' charts/mondoo-operator/templates/deployment.yaml
358+
##@ Helm Chart Management
359+
# The Helm chart templates are hand-maintained. Only CRDs are auto-generated.
360+
# See: https://github.com/mondoohq/mondoo-operator/issues/821
361+
362+
.PHONY: helm/crds
363+
helm/crds: manifests kustomize ## Update only the CRD templates in the Helm chart from generated CRDs.
364+
./hack/update-helm-crds.sh
365+
366+
.PHONY: helm/lint
367+
helm/lint: ## Lint the Helm chart using chart-testing (ct).
368+
@if command -v ct >/dev/null 2>&1; then \
369+
ct lint --charts charts/mondoo-operator --validate-maintainers=false; \
370+
else \
371+
echo "chart-testing (ct) not found, falling back to helm lint"; \
372+
echo "Install ct for more comprehensive linting: brew install chart-testing"; \
373+
helm lint charts/mondoo-operator; \
374+
fi
375+
376+
.PHONY: helm/template
377+
helm/template: ## Render Helm chart templates for debugging.
378+
helm template test charts/mondoo-operator
365379

366380
# Install prettier gloablly via
367381
# yarn global add prettier --prefix /usr/local

charts/mondoo-operator/Chart.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ version: 12.0.1
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
2424
appVersion: "12.0.1"
25+
icon: https://raw.githubusercontent.com/mondoohq/mondoo-operator/main/charts/mondoo-operator/icon.svg

charts/mondoo-operator/icon.svg

Lines changed: 7 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)