Skip to content

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

Description

@Elvand-Lie

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions