Skip to content

Commit

Permalink
fix: deploy with options specified (knative#1482)
Browse files Browse the repository at this point in the history
Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>

Signed-off-by: Zbynek Roubalik <zroubalik@gmail.com>
  • Loading branch information
zroubalik authored and lance committed Feb 15, 2023
1 parent 07b855c commit d00575c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
41 changes: 41 additions & 0 deletions client_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"knative.dev/func/docker"
"knative.dev/func/knative"
. "knative.dev/func/testing"
"knative.dev/pkg/ptr"
)

/*
Expand Down Expand Up @@ -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")()
Expand Down
9 changes: 8 additions & 1 deletion knative/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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{
Expand Down

0 comments on commit d00575c

Please sign in to comment.