knative / knative/func

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
lifecycle/stale
Dominant language
Go
Stars
365
Forks
223
Avg merge
2d 3h
Merged PRs (30d)
25

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
1. Create a function with scale options in `func.yaml`:
```yaml
deploy:
options:
scale:
target: 100
utilization: 70
```
2. Deploy the function: `func deploy`
3. Inspect the deployed Knative Service annotations:
```bash
kubectl get ksvc -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
```go
// 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:
```go
toUpdate[autoscaling.TargetAnnotationKey] = fmt.Sprintf("%g", *options.Scale.Target)
toUpdate[autoscaling.TargetUtilizationPercentageKey] = fmt.Sprintf("%g", *options.Scale.Utilization)
```

Contributor guide

Open the contributing guide

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.