fix(kuma-cp): allow empty 'to' override#16212
Merged
Automaat merged 1 commit intokumahq:masterfrom Apr 13, 2026
Merged
Conversation
Relax validators on MeshLoadBalancingStrategy and MeshRetry to permit empty 'to' lists. This enables narrow-scope policies to disable rules inherited from broader policies via merge (RFC 7396 replaces 'to: [...]' with 'to: []' for that Dataplane). Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Relaxes validation in Kuma policy APIs to allow to: [] as an explicit override, enabling narrow-scope policies (e.g., per-Dataplane) to disable rules inherited from broader-scope policies—consistent with the existing merge semantics (slice replacement via RFC 7396 JSON Merge Patch).
Changes:
- Remove the “needs at least one item” validation constraint for empty
toinMeshRetryandMeshLoadBalancingStrategy. - Update validator tests to treat empty
toas a valid override case and drop the previous “empty to is invalid” expectations.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/plugins/policies/meshretry/api/v1alpha1/validator.go | Removes the len(to)==0 violation so empty to can pass validation. |
| pkg/plugins/policies/meshretry/api/v1alpha1/validator_test.go | Updates test cases to assert empty to is valid (override use-case). |
| pkg/plugins/policies/meshloadbalancingstrategy/api/v1alpha1/validator.go | Removes the len(to)==0 violation so empty to can pass validation. |
| pkg/plugins/policies/meshloadbalancingstrategy/api/v1alpha1/validator_test.go | Drops the “needs at least one item” expectation and adds a valid empty-to override case. |
Contributor
Reviewer Checklist🔍 Each of these sections need to be checked by the reviewer of the PR 🔍:
|
bartsmykla
approved these changes
Apr 13, 2026
Automaat
added a commit
that referenced
this pull request
Apr 14, 2026
## Motivation Closes #13294. Several policy validators reject empty `to` lists, which blocks users from using a narrow-scope policy to disable rules inherited from a broader policy. Example that currently fails validation: ```yaml apiVersion: kuma.io/v1alpha1 kind: MeshHealthCheck metadata: name: disable-for-web spec: targetRef: kind: Dataplane labels: app: web to: [] ``` > Changelog: fix(policies): allow empty 'to' override ## Implementation information Relaxes the `len(to) == 0` check in: - `MeshLoadBalancingStrategy` validator - `MeshRetry` validator The merge layer (`pkg/plugins/policies/core/rules/merge/merge.go`) already supports this override semantic: it uses RFC 7396 JSON Merge Patch and replaces (not appends) slice fields. So a narrower policy with `to: []` overwrites the inherited `to: [...]` for matched Dataplanes, resulting in no rules applied (Envoy defaults take over). Only the validators were blocking the UX; no merge logic changes required. Policies not touched: - `MeshRateLimit` — already permits empty `to` on gateway scope - `MeshHealthCheck` / `MeshHTTPRoute` / `MeshTCPRoute` — no explicit length check, already allowed - `MeshAccessLog` / `MeshCircuitBreaker` / `MeshFaultInjection` / `MeshTimeout` — require at least one of `from`/`to`/`rules`, which is the right rule for policies that support the `rules` format Tests updated: - `meshloadbalancingstrategy/api/v1alpha1/validator_test.go`: drop the "needs at least one item" expectation; add a valid case for empty `to` override - `meshretry/api/v1alpha1/validator_test.go`: convert the empty `to` error case to a valid case; add an explicit override entry ## Supporting documentation - Issue: #13294 - Merge semantics: `pkg/plugins/policies/core/rules/merge/merge.go` Signed-off-by: Marcin Skalski <skalskimarcin33@gmail.com>
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.
Motivation
Closes #13294.
Several policy validators reject empty
tolists, which blocks usersfrom using a narrow-scope policy to disable rules inherited from a
broader policy. Example that currently fails validation:
Implementation information
Relaxes the
len(to) == 0check in:MeshLoadBalancingStrategyvalidatorMeshRetryvalidatorThe merge layer (
pkg/plugins/policies/core/rules/merge/merge.go) alreadysupports this override semantic: it uses RFC 7396 JSON Merge Patch and
replaces (not appends) slice fields. So a narrower policy with
to: []overwrites the inherited
to: [...]for matched Dataplanes, resultingin no rules applied (Envoy defaults take over). Only the validators
were blocking the UX; no merge logic changes required.
Policies not touched:
MeshRateLimit— already permits emptytoon gateway scopeMeshHealthCheck/MeshHTTPRoute/MeshTCPRoute— no explicitlength check, already allowed
MeshAccessLog/MeshCircuitBreaker/MeshFaultInjection/MeshTimeout— require at least one offrom/to/rules, whichis the right rule for policies that support the
rulesformatTests updated:
meshloadbalancingstrategy/api/v1alpha1/validator_test.go: drop the"needs at least one item" expectation; add a valid case for empty
tooverridemeshretry/api/v1alpha1/validator_test.go: convert the emptytoerror case to a valid case; add an explicit override entry
Supporting documentation
toare correct #13294pkg/plugins/policies/core/rules/merge/merge.go