✨ feature: migrate structural validation to kubebuilder CEL markers (Phase 1)#444
Conversation
Signed-off-by: Vaishnav88sk <[email protected]>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Vaishnav88sk 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 |
WalkthroughChangesThe PR adds CRD validation rules for non-empty manifest lists, HTTPS client URLs, DNS-compatible managed cluster names, and matching ManagedClusterSetBinding names. CRD validation updates
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cluster/v1/types.go`:
- Around line 86-87: Replace the URL validation marker on the URL field in
cluster/v1/types.go:86-87 with a CEL expression that performs real URL
validation and requires an HTTPS scheme, rejecting malformed values such as
https://. Regenerate
cluster/v1/0000_00_clusters.open-cluster-management.io_managedclusters.crd.yaml:111-113
so its validation rule and message match the updated source marker.
In `@work/v1/types.go`:
- Around line 69-71: Make Manifests required in work/v1/types.go by removing its
optional marker while retaining the non-empty validation. Regenerate the CRDs so
the required-field schema is reflected in
work/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yaml, both
listed addon/v1alpha1 and addon/v1beta1 AddonTemplates locations, the second
addon/v1beta1 location, and
work/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml;
no other schema changes are needed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: faef0d51-045c-4ee7-8c02-f0ba16262ca3
📒 Files selected for processing (9)
addon/v1alpha1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yamladdon/v1beta1/0000_03_addon.open-cluster-management.io_addontemplates.crd.yamlcluster/v1/0000_00_clusters.open-cluster-management.io_managedclusters.crd.yamlcluster/v1/types.gocluster/v1beta2/0000_01_clusters.open-cluster-management.io_managedclustersetbindings.crd.yamlcluster/v1beta2/types_managedclustersetbinding.gowork/v1/0000_00_work.open-cluster-management.io_manifestworks.crd.yamlwork/v1/types.gowork/v1alpha1/0000_00_work.open-cluster-management.io_manifestworkreplicasets.crd.yaml
| // manifests represents a list of kubernetes resources to be deployed on a managed cluster. | ||
| // +optional | ||
| Manifests []Manifest `json:"manifests,omitempty"` | ||
| // +required |
There was a problem hiding this comment.
This is an API change that is no longer about using CEL as validation. I wonder if this is truly needed?
|
please add integration tests to test all the validations. |
Summary
This PR implements Phase 1 of the CEL Validation Migration as outlined and approved in Enhancement Proposal #181.
It replaces legacy Go-based structural webhook validation with native Kubernetes
+kubebuilder:validation:XValidationCEL markers directly on the Custom Resource structs.Validations Migrated:
ManagedCluster: Enforced HTTPS format forSpec.ManagedClusterClientConfigsURLs and regex format formetadata.name.ManagedClusterSetBinding: Enforced cross-field parity (metadata.name == spec.clusterSet).ManifestWork: Enforcedmanifestsarray is not empty.Note: The corresponding
ValidatingAdmissionPolicyadditions and FeatureGate operator updates (Phase 2) will be submitted in a follow-up PR to theocmrepository once this API change is merged.Related issue(s)
Fixes phase 1 of open-cluster-management-io/ocm#1566
Summary by CodeRabbit