Skip to content

fix: autoscaling annotation format and empty image guard#3903

Closed
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/autoscaling-format-and-empty-image-guard
Closed

fix: autoscaling annotation format and empty image guard#3903
Elvand-Lie wants to merge 1 commit into
knative:mainfrom
Elvand-Lie:fix/autoscaling-format-and-empty-image-guard

Conversation

@Elvand-Lie

Copy link
Copy Markdown
Contributor

Description

Two bug fixes:

1. Autoscaling annotations formatted with %f produce invalid values

setServiceOptions in pkg/knative/deployer.go uses fmt.Sprintf("%f", ...) to format scale Target and Utilization annotations, producing strings like "100.000000" instead of "100". Changed %f to %g which strips trailing zeros.

Files changed: pkg/knative/deployer.go (lines 592, 598)

2. ImageNameWithDigest produces invalid OCI reference when Build.Image is empty

No guard against empty Build.Image in ImageNameWithDigest. When called with non-empty digest but empty image, produces invalid @sha256:... reference. Added early return for empty image.

Files changed: pkg/functions/function.go (line 864)

Regression test

Added TestSetServiceOptions_ScaleAnnotationFormat that verifies scale annotations contain clean values ("100" not "100.000000").

Files changed: pkg/knative/deployer_test.go

Verification

  • go vet ./pkg/knative ./pkg/functions - clean
  • go test ./pkg/knative/ -count=1 - all 20 tests pass
  • go test ./pkg/functions/ -run TestFunction_ImageWithDigest -count=1 - all 5 tests pass

Two bug fixes:

1. pkg/knative/deployer.go: setServiceOptions used fmt.Sprintf(%f) to format
   autoscaling Target and Utilization annotations, producing values like
   100.000000 instead of 100. Changed to %g which strips trailing
   zeros (100.0 -> 100, 70.5 -> 70.5).

2. pkg/functions/function.go: ImageNameWithDigest did not guard against an
   empty Build.Image. When called with a non-empty digest but empty image
   name, it produced the invalid OCI reference @sha256:... (no image name
   prefix). Added early return for empty image.

Also adds a regression test TestSetServiceOptions_ScaleAnnotationFormat
that verifies the annotation values are clean integers.
@knative-prow knative-prow Bot requested review from dsimansk and jrangelramos June 17, 2026 20:37
@knative-prow

knative-prow Bot commented Jun 17, 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 jrangelramos 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 added size/M 🤖 PR changes 30-99 lines, ignoring generated files. needs-ok-to-test 🤖 Needs an org member to approve testing labels Jun 17, 2026
@knative-prow

knative-prow Bot commented Jun 17, 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.

@Elvand-Lie

Copy link
Copy Markdown
Contributor Author

Closing in favor of separate PRs per bug fix.

@Elvand-Lie Elvand-Lie closed this Jun 17, 2026
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.72%. Comparing base (f72ecda) to head (434a498).

Files with missing lines Patch % Lines
pkg/functions/function.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3903      +/-   ##
==========================================
- Coverage   53.93%   51.72%   -2.21%     
==========================================
  Files         200      200              
  Lines       23681    23682       +1     
==========================================
- Hits        12772    12250     -522     
- Misses       9674    10284     +610     
+ Partials     1235     1148      -87     
Flag Coverage Δ
e2e 33.41% <0.00%> (-0.01%) ⬇️
e2e go 29.38% <0.00%> (-0.01%) ⬇️
e2e node 25.70% <0.00%> (-0.01%) ⬇️
e2e python 29.71% <0.00%> (-0.01%) ⬇️
e2e quarkus 25.83% <0.00%> (-0.01%) ⬇️
e2e rust 25.30% <0.00%> (-0.01%) ⬇️
e2e springboot 23.99% <0.00%> (-0.01%) ⬇️
e2e typescript 25.80% <0.00%> (-0.03%) ⬇️
e2e-config-ci 26.90% <0.00%> (+<0.01%) ⬆️
integration ?
unit macos-14 43.08% <50.00%> (+0.03%) ⬆️
unit macos-latest 43.08% <50.00%> (+0.03%) ⬆️
unit ubuntu-24.04-arm 43.38% <40.00%> (+0.03%) ⬆️
unit ubuntu-latest 43.93% <50.00%> (+0.03%) ⬆️
unit windows-latest 43.15% <50.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Elvand-Lie Elvand-Lie deleted the fix/autoscaling-format-and-empty-image-guard branch June 17, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ok-to-test 🤖 Needs an org member to approve testing size/M 🤖 PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant