-
Notifications
You must be signed in to change notification settings - Fork 532
fix: add default value validation for AI policy configuration #11594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: add default value validation for AI policy configuration #11594
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances default value handling in AI policy configurations by validating JSON literals and refining template generation.
- Introduces JSON validation for
FieldDefault.Value
when it appears to be an object or array - Updates
applyDefaults
to correctly build Inja templates for override and non-override cases - Adds comprehensive unit tests for default value processing in
ai_policy_test.go
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go | Add JSON validity checks and adjust template logic for defaults |
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy_test.go | Add TestDefault cases covering valid/invalid JSON defaults |
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
9ced92b
to
f255c4a
Compare
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
internal/kgateway/extensions2/plugins/trafficpolicy/ai_policy.go
Outdated
Show resolved
Hide resolved
Signed-off-by: zhengkezhou1 <[email protected]>
Signed-off-by: zhengkezhou1 <[email protected]>
Signed-off-by: zhengkezhou1 <[email protected]>
3f45dc1
to
7fd6a25
Compare
Entry( | ||
"TrafficPolicy with ai invalided default values", | ||
translatorTestCase{ | ||
inputFile: "traffic-policy/ai-invalid-default-value.yaml", | ||
outputFile: "traffic-policy/ai-invalid-default-value.yaml", | ||
gwNN: types.NamespacedName{ | ||
Namespace: "infra", | ||
Name: "example-gateway", | ||
}, | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to verify the exception when translation fails?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can potentially do a check similar to this if there's an error in the status:
Expect(translatortest.AreReportsSuccess(gwNN, reportsMap)).NotTo(HaveOccurred()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think since the traffic policy doesn't have the error in the status, this can just confirm the output is as expected and the error assertions can happen in ai_policy_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@npolshakova I think we'd see an error surface on the TP & HTTPRoute status (now that #11535 has landed), right? preProcessAITrafficPolicy is called during the builder's Translate method and we propagate those errors to the policy IR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah confirmed locally the TP rejects the invalid config from the original issue:
...
conditions:
- lastTransitionTime: "2025-07-09T20:29:22Z"
message: 'field custom_list contains invalid JSON string: [1,2,3'
observedGeneration: 1
reason: Invalid
status: "False"
type: Accepted
I think we'd need to fix the merge conflict & merge with main to see the HTTPRoute updated as well. Right now it's reporting an Accepted=true state on my local cluster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shashankram @npolshakova I've added test cases for non-JSON scenarios and included comments for the new code logic.
Signed-off-by: zhengkezhou1 <[email protected]>
@zhengkezhou1 Looks like there's some merge conflicts with the gateway translator suite. Can we also merge with main? I think we'd see the HTTPRoute status get affected by this change in addition to the error reflecting on the TP status. |
Description
Fixes #11559
Change Type
Changelog
Additional Notes