fix: preserve fractional scale target minimum - #4067
Elvand-Lie wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Elvand-Lie 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 @Elvand-Lie. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain 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. |
|
Thanks for the contribution. I think this will need a rebase as the |
The func.yaml schema generator published a lower bound that was looser
than the validation actually enforced. Reflection truncates the
fractional minimum declared on ScaleOptions.Target, so the schema said
"target": { "minimum": 0 }
where func.yaml validation requires target >= 0.01. A func.yaml with a
scale target of 0.001 therefore validated against the schema and was
rejected at deploy time.
The reflector (github.com/alecthomas/jsonschema) represents the
`minimum` keyword as an int and parses the tag value with strconv.Atoi,
discarding the error:
type Type struct {
Minimum int `json:"minimum,omitempty"`
}
ScaleOptions.Target declares jsonschema_extras:"minimum=0.01", so
"0.01" fails to parse and silently degrades to zero.
Re-apply that one keyword on the already-reflected ScaleOptions.target
property, reading the value back from the same struct tag so the
constraint stays declared once and cannot drift from the runtime check
it documents. Nothing else about the generated schema changes.
b965ed0 to
71bbb54
Compare
Changes
0.01minimum forscale.targetin the generated func.yaml schema instead of emitting0./kind bug
Fixes #4066
Problem
ScaleOptions.Targetdeclaresjsonschema_extras:"minimum=0.01", but the pinnedgithub.com/alecthomas/jsonschemaimplementation parsesminimumextras withstrconv.Atoi. Because the parse error is discarded, the fractional value is emitted asminimum: 0. This makes the generated schema weaker than runtime validation, which rejects target values below0.01.Fix
After the normal schema reflection pass, restore the fractional minimum for
ScaleOptions.Targetfrom its existingjsonschema_extrastag before the schema is marshalled. The correction is intentionally scoped to the currently affected field and does not duplicate the0.01value inside the generator.Test
Added a regression test that verifies:
ScaleOptions.target.minimumis emitted as0.01utilizationbounds remain1and100schema/func_yaml-schema.jsonchanges onlyminimum: 0tominimum: 0.01Validated locally with:
Note on #4063
#4063 moves the target field to
KPAScaleOptionsand currently usesexclusiveMinimum=trueas a workaround for this truncation. Its generated schema still containsminimum: 0, so under JSON Schema draft-04 it currently representstarget > 0.When the two changes are reconciled, this correction will need to follow
KPAScaleOptions.Targetand theexclusiveMinimum=trueworkaround should be removed. Keeping both after restoringminimum: 0.01would instead requiretarget > 0.01, while runtime validation acceptstarget >= 0.01.#4063 is separate and is not modified by this PR.
Release Note