setServiceOptions: %f format produces invalid autoscaling annotation values with trailing zeros
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 90/100
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
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
- Create a function with scale options in
func.yaml:
deploy:
options:
scale:
target: 100
utilization: 70
- Deploy the function:
func deploy - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from knative/func
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
lifecycle/stale
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
priority: p3
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
googleapis/librarian#7636 ·