operator/v1: replace anyOf with CEL XValidation for maxConnections#2861
operator/v1: replace anyOf with CEL XValidation for maxConnections#2861asadawar wants to merge 1 commit into
Conversation
The maxConnections field on IngressControllerTuningOptions used an
anyOf pattern in the manual-override CRD manifest to validate that
values are either sentinel values (-1, 0) or in the range 2000-2000000.
When both branches of the anyOf failed, the API server only reported
the enum branch error ("must be one of: -1, 0"), omitting the valid
range and producing an incomplete error message.
Replace the anyOf with a CEL XValidation rule on the MaxConnections
field, which produces a clear, unified error message:
"maxConnections must be 0, -1, or between 2000 and 2000000"
Add integration tests for valid values (-1, 2000, 50000, 2000000),
invalid values (1, 500, 1999, 3000000), and validation ratcheting
(update to valid, update to another invalid, retain invalid while
updating other fields).
Bug: https://issues.redhat.com/browse/OCPBUGS-86570
Assisted-by: Claude Code
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
Hello @asadawar! Some important instructions when contributing to openshift/api: |
|
[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 |
|
Hi @asadawar. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
📝 WalkthroughWalkthroughThis PR implements validation constraints for the 🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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.
🧹 Nitpick comments (1)
operator/v1/tests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml (1)
681-812: ⚡ Quick winConsider adding test coverage for
maxConnections: 0.The CEL rule on line 2037 of
operator/v1/types_ingress.goexplicitly allowsself == 0, and the field documentation states that 0 is a permitted value (treated as default). While the current tests comprehensively cover-1, the valid range boundaries (2000, 2000000), mid-range values (50000), and various invalid values, there is no explicit test verifying thatmaxConnections: 0is accepted.Adding a test case for this edge value would complete the coverage of all documented permitted values.
🤖 Prompt for 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. In `@operator/v1/tests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml` around lines 681 - 812, Add a test case that verifies maxConnections: 0 is accepted — create a new test entry (e.g. name "Should be able to create an IngressController with maxConnections of 0") modeled after the existing valid cases (like the -1 and 2000 cases) with an initial YAML containing spec.tuningOptions.maxConnections: 0 and an expected YAML that includes the defaulted policies (httpEmptyRequestsPolicy, idleConnectionTerminationPolicy, closedClientConnectionPolicy) and tuningOptions.maxConnections: 0; this will exercise the CEL rule referenced in types_ingress.go that allows self == 0 and complete coverage of permitted values.
🤖 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.
Nitpick comments:
In `@operator/v1/tests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml`:
- Around line 681-812: Add a test case that verifies maxConnections: 0 is
accepted — create a new test entry (e.g. name "Should be able to create an
IngressController with maxConnections of 0") modeled after the existing valid
cases (like the -1 and 2000 cases) with an initial YAML containing
spec.tuningOptions.maxConnections: 0 and an expected YAML that includes the
defaulted policies (httpEmptyRequestsPolicy, idleConnectionTerminationPolicy,
closedClientConnectionPolicy) and tuningOptions.maxConnections: 0; this will
exercise the CEL rule referenced in types_ingress.go that allows self == 0 and
complete coverage of permitted values.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 9937caba-83df-49ba-9bad-95689ab5e295
⛔ Files ignored due to path filters (7)
operator/v1/zz_generated.crd-manifests/0000_50_ingress_00_ingresscontrollers-CustomNoUpgrade.crd.yamlis excluded by!**/zz_generated.crd-manifests/*operator/v1/zz_generated.crd-manifests/0000_50_ingress_00_ingresscontrollers-Default.crd.yamlis excluded by!**/zz_generated.crd-manifests/*operator/v1/zz_generated.crd-manifests/0000_50_ingress_00_ingresscontrollers-DevPreviewNoUpgrade.crd.yamlis excluded by!**/zz_generated.crd-manifests/*operator/v1/zz_generated.crd-manifests/0000_50_ingress_00_ingresscontrollers-OKD.crd.yamlis excluded by!**/zz_generated.crd-manifests/*operator/v1/zz_generated.crd-manifests/0000_50_ingress_00_ingresscontrollers-TechPreviewNoUpgrade.crd.yamlis excluded by!**/zz_generated.crd-manifests/*operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/AAA_ungated.yamlis excluded by!**/zz_generated.featuregated-crd-manifests/**operator/v1/zz_generated.featuregated-crd-manifests/ingresscontrollers.operator.openshift.io/IngressControllerDynamicConfigurationManager.yamlis excluded by!**/zz_generated.featuregated-crd-manifests/**
📒 Files selected for processing (3)
operator/v1/manual-override-crd-manifests/ingresscontrollers.operator.openshift.io/AAA_ungated.yamloperator/v1/tests/ingresscontrollers.operator.openshift.io/AAA_ungated.yamloperator/v1/types_ingress.go
💤 Files with no reviewable changes (1)
- operator/v1/manual-override-crd-manifests/ingresscontrollers.operator.openshift.io/AAA_ungated.yaml
|
/ok-to-test CC @Miciah This LGTM but would like Miciah to ack |
|
@asadawar: The following tests failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
The This is the same pattern as PR #2837, where the approver used Why the anyOf must be removed (not kept alongside CEL): When both The CEL error message never appears. The only way to get a clear error message is to remove the anyOf and let CEL handle the validation. The |
Summary
anyOfOpenAPI schema validation with CELXValidationrule forIngressControllerTuningOptions.maxConnectionsanyOfpattern (enum[-1, 0]OR range[2000, 2000000]) produced incomplete error messages when both branches failed: the API server only reported "must be one of: -1, 0", omitting the valid rangeBefore (anyOf error)
After (CEL error)
Context
The original
anyOfwas added in PR #1161 (April 2022) before CELXValidationwas widely adopted in this repo. The file now has 30 XValidation rules, including 3 on the adjacenthttpKeepAliveTimeoutfield in the same struct. CEL and OpenAPI structural validation ratchet identically underCRDValidationRatcheting(GA since Kubernetes 1.30), so there is no behavioral change for existing stored objects.Test plan
make update(full codegen) completes successfullymake -C tests test), including:Bug: https://issues.redhat.com/browse/OCPBUGS-86570