Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/functions/function.go
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@ func (f Function) ImageNameWithDigest(newDigest string) string {
return f.Build.Image
}
image := f.Build.Image
if image == "" {
return ""
}

// overwrite current digest
shaIndex := strings.Index(image, "@sha256:")
Expand Down
4 changes: 2 additions & 2 deletions pkg/knative/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,13 +589,13 @@ func setServiceOptions(template *servingv1.RevisionTemplateSpec, options fn.Opti
}

if options.Scale.Target != nil {
toUpdate[autoscaling.TargetAnnotationKey] = fmt.Sprintf("%f", *options.Scale.Target)
toUpdate[autoscaling.TargetAnnotationKey] = fmt.Sprintf("%g", *options.Scale.Target)
} else {
toRemove = append(toRemove, autoscaling.TargetAnnotationKey)
}

if options.Scale.Utilization != nil {
toUpdate[autoscaling.TargetUtilizationPercentageKey] = fmt.Sprintf("%f", *options.Scale.Utilization)
toUpdate[autoscaling.TargetUtilizationPercentageKey] = fmt.Sprintf("%g", *options.Scale.Utilization)
} else {
toRemove = append(toRemove, autoscaling.TargetUtilizationPercentageKey)
}
Expand Down
30 changes: 30 additions & 0 deletions pkg/knative/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
v1 "k8s.io/client-go/kubernetes/typed/core/v1"
fn "knative.dev/func/pkg/functions"
"knative.dev/pkg/ptr"
"knative.dev/serving/pkg/apis/autoscaling"
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
)

Expand Down Expand Up @@ -451,6 +452,35 @@ func TestGenerateNewService_ResourceSetsPopulated(t *testing.T) {
}
}

func TestSetServiceOptions_ScaleAnnotationFormat(t *testing.T) {
target := 100.0
utilization := 70.0
template := &servingv1.RevisionTemplateSpec{
Spec: servingv1.RevisionSpec{
PodSpec: corev1.PodSpec{
Containers: []corev1.Container{{}},
},
},
}
options := fn.Options{
Scale: &fn.ScaleOptions{
Target: &target,
Utilization: &utilization,
},
}

if err := setServiceOptions(template, options); err != nil {
t.Fatalf("setServiceOptions returned unexpected error: %v", err)
}

if got := template.Annotations[autoscaling.TargetAnnotationKey]; got != "100" {
t.Errorf("expected target annotation to be %q, got %q", "100", got)
}
if got := template.Annotations[autoscaling.TargetUtilizationPercentageKey]; got != "70" {
t.Errorf("expected utilization annotation to be %q, got %q", "70", got)
}
}

func assertAuth(uname, pwd string, w http.ResponseWriter, r *http.Request) bool {
user, pass, ok := r.BasicAuth()
if ok && user == uname && pass == pwd {
Expand Down
Loading