fix: move enum validation to items level for v1alpha1 operations field#691
Merged
JaydipGabani merged 2 commits intoopen-policy-agent:masterfrom Mar 12, 2026
Merged
Conversation
Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
There was a problem hiding this comment.
Pull request overview
Fixes v1alpha1 ConstraintTemplate CRD validation so invalid operations array values are rejected by the API server (aligning behavior with v1/v1beta1).
Changes:
- Corrected the kubebuilder marker on
v1alpha1.Target.Operationsto apply the enum to each array item. - Regenerated CRD manifests so the
enumis emitted underitemsforoperations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| constraint/pkg/apis/templates/v1alpha1/constrainttemplate_types.go | Moves enum validation from the array field to per-item validation via kubebuilder marker. |
| constraint/deploy/crds.yaml | Regenerated CRD output reflecting per-item enum for v1alpha1 operations. |
| constraint/config/crds/templates.gatekeeper.sh_constrainttemplates.yaml | Regenerated CRD output reflecting per-item enum for v1alpha1 operations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sozercan
approved these changes
Mar 9, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #691 +/- ##
===========================================
- Coverage 54.68% 43.98% -10.70%
===========================================
Files 71 97 +26
Lines 5241 5461 +220
===========================================
- Hits 2866 2402 -464
- Misses 2073 2749 +676
- Partials 302 310 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
In the ConstraintTemplate CRD, the v1alpha1
operationsfield hasenumon the array instead of on each item. This means v1alpha1 won't reject invalid operation values (e.g."INVALID") at the API server level, unlike v1 and v1beta1 which correctly validate each item.See: https://github.com/open-policy-agent/gatekeeper/blob/master/deploy/gatekeeper.yaml#L3220-L3231
Affected: Gatekeeper v3.21.0+, master, and all release branches. No functional impact for valid values.
Root Cause
Wrong kubebuilder marker in
constraint/pkg/apis/templates/v1alpha1/constrainttemplate_types.go:+kubebuilder:validation:Enumapplies the enum to the array field itself (meaningless), while+kubebuilder:validation:items:Enumcorrectly applies it to each item in the array — matching v1 and v1beta1.Changes
Target.Operationsfieldmake manifests