From d00575cc9f47c8e2f74a3aedeba96fed41e28a9e Mon Sep 17 00:00:00 2001 From: Zbynek Roubalik Date: Fri, 6 Jan 2023 19:21:20 +0100 Subject: [PATCH] fix: `deploy` with options specified (#1482) Signed-off-by: Zbynek Roubalik Signed-off-by: Zbynek Roubalik --- client_int_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ knative/deployer.go | 9 ++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/client_int_test.go b/client_int_test.go index 4f4527f25..e39044fff 100644 --- a/client_int_test.go +++ b/client_int_test.go @@ -15,6 +15,7 @@ import ( "knative.dev/func/docker" "knative.dev/func/knative" . "knative.dev/func/testing" + "knative.dev/pkg/ptr" ) /* @@ -121,6 +122,46 @@ func TestDeploy(t *testing.T) { } } +// TestDeployWithOptions deploys function with all options explicitly set +func TestDeployWithOptions(t *testing.T) { + defer Within(t, "testdata/example.com/deployoptions")() + verbose := true + + ds := fn.DeploySpec{ + Options: fn.Options{ + Scale: &fn.ScaleOptions{ + Min: ptr.Int64(1), + Max: ptr.Int64(10), + Metric: ptr.String("concurrency"), + Target: ptr.Float64(5), + Utilization: ptr.Float64(5), + }, + Resources: &fn.ResourcesOptions{ + Requests: &fn.ResourcesRequestsOptions{ + CPU: ptr.String("10m"), + Memory: ptr.String("100m"), + }, + Limits: &fn.ResourcesLimitsOptions{ + CPU: ptr.String("1000m"), + Memory: ptr.String("1000M"), + Concurrency: ptr.Int64(10), + }, + }, + }, + } + + client := newClient(verbose) + + if err := client.New(context.Background(), fn.Function{Name: "deployoptions", Root: ".", Runtime: "go", Deploy: ds}); err != nil { + t.Fatal(err) + } + defer del(t, client, "deployoptions") + + if err := client.Deploy(context.Background(), "."); err != nil { + t.Fatal(err) + } +} + // TestRemove deletes func TestRemove(t *testing.T) { defer Within(t, "testdata/example.com/remove")() diff --git a/knative/deployer.go b/knative/deployer.go index 10a87fff3..298f894b7 100644 --- a/knative/deployer.go +++ b/knative/deployer.go @@ -347,6 +347,13 @@ func generateNewService(f fn.Function, decorator DeployDecorator) (*v1.Service, annotations = decorator.UpdateAnnotations(f, annotations) } + // we need to create a separate map for Annotations specified in a Revision, + // in case we will need to specify autoscaling annotations -> these could be only in a Revision not in a Service + revisionAnnotations := make(map[string]string) + for k, v := range annotations { + revisionAnnotations[k] = v + } + service := &v1.Service{ ObjectMeta: metav1.ObjectMeta{ Name: f.Name, @@ -358,7 +365,7 @@ func generateNewService(f fn.Function, decorator DeployDecorator) (*v1.Service, Template: v1.RevisionTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: labels, - Annotations: annotations, + Annotations: revisionAnnotations, }, Spec: v1.RevisionSpec{ PodSpec: corev1.PodSpec{