setServiceOptions: %f format produces invalid autoscaling annotation values with trailing zeros

Open Beginner friendly
#3,901 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
90/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
devops

Research direction

Start in pkg/knative/deployer.go around lines 592 and 598, where setServiceOptions formats the scale annotations. Check the generated values using the func.yaml scale options and kubectl command from the report; done means the target and utilization annotations contain clean numeric strings without trailing zeros.

Written by the indexing model from the issue text.

Description

lifecycle/stale

Description

setServiceOptions in pkg/knative/deployer.go uses fmt.Sprintf("%f", ...) to format the Target and Utilization autoscaling annotation values. Go's %f verb produces 6 trailing decimal places by default (e.g., "100.000000"), which is not the expected format for Knative autoscaling annotations.

Steps to Reproduce

  1. Create a function with scale options in func.yaml:
deploy:
  options:
    scale:
      target: 100
      utilization: 70
  1. Deploy the function: func deploy
  2. Inspect the deployed Knative Service annotations:
kubectl get ksvc <name> -o jsonpath='{.spec.template.metadata.annotations}'

Expected Behavior

Annotations should contain clean numeric strings:

  • autoscaling.knative.dev/target: "100"
  • autoscaling.knative.dev/target-utilization-percentage: "70"

Actual Behavior

Annotations contain float-formatted strings with trailing zeros:

  • autoscaling.knative.dev/target: "100.000000"
  • autoscaling.knative.dev/target-utilization-percentage: "70.000000"

Relevant Code

// pkg/knative/deployer.go:592
toUpdate[autoscaling.TargetAnnotationKey] = fmt.Sprintf("%f", *options.Scale.Target)
// pkg/knative/deployer.go:598
toUpdate[autoscaling.TargetUtilizationPercentageKey] = fmt.Sprintf("%f", *options.Scale.Utilization)

Suggested Fix

Replace %f with %g to strip trailing zeros:

toUpdate[autoscaling.TargetAnnotationKey] = fmt.Sprintf("%g", *options.Scale.Target)
toUpdate[autoscaling.TargetUtilizationPercentageKey] = fmt.Sprintf("%g", *options.Scale.Utilization)
Dominant language
Go
Stars
365
Forks
223
Avg merge
2d 3h
Merged PRs (30d)
25

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from knative/func

All issues in knative/func

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.