feat(ci): Implement drift detection as Go test in test/drift/#2933
feat(ci): Implement drift detection as Go test in test/drift/#2933RobuRishabh wants to merge 5 commits into
Conversation
- Add test/drift/drift_test.go with 17 subtests covering resource inventory, ClusterRoles, Roles, MutatingWebhookConfiguration, ValidatingWebhookConfiguration, and Deployment container specs - Update Makefile drift-check target to run go test ./test/drift/ - Update workflow path triggers for test/drift/** - Remove scripts/drift-check.sh and config/drift-check-allowlist.yaml in favor of logic encoded directly in Go Signed-off-by: roburishabh <roburishabh@outlook.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Pull request overview
Adds a CI drift-detection gate that semantically compares rendered Kubernetes objects from the Helm chart (source of truth) against the repository’s Kustomize manifests, to prevent future divergence.
Changes:
- Introduces a new Go test suite under
test/drift/that renders Helm + Kustomize outputs and compares RBAC rules, webhook configs, and deployment container specs. - Adds a Helm values file used to align Helm rendering with Kustomize defaults for fair comparison.
- Wires the drift check into CI via a dedicated GitHub Actions workflow and a
make drift-checktarget.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
test/drift/drift_test.go |
Implements Helm/Kustomize rendering, normalization, and semantic comparisons for drift detection. |
Makefile |
Adds a drift-check target for running the drift test locally and in CI. |
charts/spark-operator-chart/ci/drift-check-values.yaml |
Helm values used to render comparable output to Kustomize defaults. |
.github/workflows/kustomize-drift-check.yaml |
Adds a workflow that runs the drift check on relevant PRs/pushes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if err == io.EOF { | ||
| break | ||
| } | ||
| continue |
| for _, w := range wh.Webhooks { | ||
| e := webhookEntry{ | ||
| FailPolicy: string(*w.FailurePolicy), | ||
| SideEffects: string(*w.SideEffects), | ||
| } | ||
| if w.ClientConfig.Service != nil { |
| var entries []webhookEntry | ||
| for _, w := range wh.Webhooks { | ||
| e := webhookEntry{ | ||
| FailPolicy: string(*w.FailurePolicy), | ||
| SideEffects: string(*w.SideEffects), | ||
| } |
| for kind := range helmKinds { | ||
| assert.Contains(t, kustKinds, kind, | ||
| "resource kind %q exists in Helm but not in Kustomize", kind) | ||
| } | ||
| for kind := range kustKinds { | ||
| assert.Contains(t, helmKinds, kind, | ||
| "resource kind %q exists in Kustomize but not in Helm", kind) |
| // Role names differ | ||
| helmControllerRole = "spark-operator-controller" | ||
| kustControllerRole = "spark-operator-controller" | ||
| helmWebhookRole = "spark-operator-webhook" | ||
| kustWebhookRole = "spark-operator-webhook" | ||
|
|
| uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
Signed-off-by: roburishabh <roburishabh@outlook.com>
…Selector Signed-off-by: roburishabh <roburishabh@outlook.com>
Purpose of this PR
This PR implements an automated Helm-Kustomize Drift Detection Pipeline that uses the Helm chart as the "source of truth" and compares its rendered output against Kustomize build output, reporting any unauthorized divergence.
Proposed changes:
test/drift/drift_test.go— a Go test package that renders both Helm and Kustomize outputs into typed Kubernetes objects and performs semantic comparison of RBAC rules, webhook configurations, and deployment specstest/drift/drift-check-values.yaml— Helm values that align template output with Kustomize defaults for fair comparison.github/workflows/kustomize-drift-check.yaml— CI workflow triggered on PRs/pushes affectingconfig/,charts/,internal/, ortest/drift/Makefile:drift-checktarget for local developer experience (make drift-check)test/drift/fromunit-testtarget (it has its own dedicated workflow)Change Category
Rationale
The Kustomize manifests were abandoned and broke because there was no automated gate to ensure they stayed current with Helm chart updates. A byte-for-byte comparison isn't feasible due to inherent differences in naming, labeling, and parameterization schemes between Helm and Kustomize. Instead, this test performs semantic comparison by:
rbacv1.ClusterRole,appsv1.Deployment,admissionregistrationv1.MutatingWebhookConfiguration, etc.)This approach uses only libraries already in
go.mod(k8s.io/api,k8s.io/apimachinery,testify) and follows the same pattern as the existingtest/kustomize/package — no new external dependencies.Note: The drift-check workflow uses
continue-on-error: truebecause 7 genuine drift items currently exist between Helm and Kustomize. These will be fixed in follow-up PRs, after which thecontinue-on-errorwill be removed to make the check blocking.Checklist
Additional Notes
The values file is placed under
test/drift/(notcharts/spark-operator-chart/ci/) to avoid chart-testing automatically using it as an install test configuration.The test currently detects 7 genuine drift items:
These represent real accumulated drift that will be fixed in follow-up PRs. Once fixed, the CI gate will prevent future drift from being introduced silently.
Commands to test