Skip to content

fix: preserve fractional scale target minimum - #4067

Open
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/schema-fractional-numeric-constraints
Open

Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/schema-fractional-numeric-constraints

Conversation

@Elvand-Lie

@Elvand-Lie Elvand-Lie commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Changes

  • 🐛 Preserve the 0.01 minimum for scale.target in the generated func.yaml schema instead of emitting 0.

/kind bug

Fixes #4066

Problem

ScaleOptions.Target declares jsonschema_extras:"minimum=0.01", but the pinned github.com/alecthomas/jsonschema implementation parses minimum extras with strconv.Atoi. Because the parse error is discarded, the fractional value is emitted as minimum: 0. This makes the generated schema weaker than runtime validation, which rejects target values below 0.01.

Fix

After the normal schema reflection pass, restore the fractional minimum for ScaleOptions.Target from its existing jsonschema_extras tag before the schema is marshalled. The correction is intentionally scoped to the currently affected field and does not duplicate the 0.01 value inside the generator.

Test

Added a regression test that verifies:

  • ScaleOptions.target.minimum is emitted as 0.01
  • the neighbouring utilization bounds remain 1 and 100
  • regenerating schema/func_yaml-schema.json changes only minimum: 0 to minimum: 0.01

Validated locally with:

go test -race -count=1 ./schema/... ./pkg/functions/...
go test -count=1 ./schema/generator/ -run TestTargetMinimumIsPreserved
go vet ./schema/generator/...
git diff --check

Note on #4063

#4063 moves the target field to KPAScaleOptions and currently uses exclusiveMinimum=true as a workaround for this truncation. Its generated schema still contains minimum: 0, so under JSON Schema draft-04 it currently represents target > 0.

When the two changes are reconciled, this correction will need to follow KPAScaleOptions.Target and the exclusiveMinimum=true workaround should be removed. Keeping both after restoring minimum: 0.01 would instead require target > 0.01, while runtime validation accepts target >= 0.01.

#4063 is separate and is not modified by this PR.

Release Note

The generated func.yaml schema now preserves the 0.01 minimum for scale.target.

@knative-prow knative-prow Bot added the kind/bug Bugs label Sep 26, 2026
@knative-prow

knative-prow Bot commented Sep 26, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Elvand-Lie
Once this PR has been reviewed and has the lgtm label, please assign matejvasek for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow

knative-prow Bot commented Sep 26, 2026

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@knative-prow knative-prow Bot added needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels Sep 26, 2026
@lkingland

Copy link
Copy Markdown
Member

Thanks for the contribution. I think this will need a rebase as the scale option has a PR coming in now which moves it up to top-level.

@knative-prow-robot knative-prow-robot added the needs-rebase Cannot be merged due to conflicts with HEAD. label Sep 28, 2026
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.
@Elvand-Lie
Elvand-Lie force-pushed the fix/schema-fractional-numeric-constraints branch from b965ed0 to 71bbb54 Compare September 28, 2026 18:26
@knative-prow-robot knative-prow-robot removed the needs-rebase Cannot be merged due to conflicts with HEAD. label Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Bugs needs-ok-to-test 🤖 Needs an org member to approve testing size/L 🤖 PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

func.yaml schema generator truncates fractional minimum values (e.g. 0.01 -> 0)

3 participants