Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout option to service create #1643

Merged
merged 5 commits into from
Apr 13, 2022
Merged
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
1 change: 1 addition & 0 deletions docs/cmd/kn_service_apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ kn service apply s0 --filename my-svc.yml
--scale-utilization int Percentage of concurrent requests utilization before scaling up. (default 70)
--scale-window string Duration to look back for making auto-scaling decisions. The service is scaled to zero if no request was received in during that time. (eg: 10s)
--service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace.
--timeout int Duration in seconds that the request routing layer will wait for a request delivered to a container to begin replying (default 300)
--user int The user ID to run the container (e.g., 1001).
--volume stringArray Add a volume from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret: or sc:). Example: --volume myvolume=cm:myconfigmap or --volume myvolume=secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --volume myvolume-.
--wait Wait for 'service apply' operation to be completed. (default true)
Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ kn service create NAME --image IMAGE
--service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace.
--tag strings Set tag (format: --tag revisionRef=tagName) where revisionRef can be a revision or '@latest' string representing latest ready revision. This flag can be specified multiple times.
--target string Work on local directory instead of a remote cluster (experimental)
--timeout int Duration in seconds that the request routing layer will wait for a request delivered to a container to begin replying (default 300)
--user int The user ID to run the container (e.g., 1001).
--volume stringArray Add a volume from a ConfigMap (prefix cm: or config-map:) or a Secret (prefix secret: or sc:). Example: --volume myvolume=cm:myconfigmap or --volume myvolume=secret:mysecret. You can use this flag multiple times. To unset a ConfigMap/Secret reference, append "-" to the name, e.g. --volume myvolume-.
--wait Wait for 'service create' operation to be completed. (default true)
Expand Down
1 change: 1 addition & 0 deletions docs/cmd/kn_service_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ kn service update NAME
--service-account string Service account name to set. An empty argument ("") clears the service account. The referenced service account must exist in the service's namespace.
--tag strings Set tag (format: --tag revisionRef=tagName) where revisionRef can be a revision or '@latest' string representing latest ready revision. This flag can be specified multiple times.
--target string Work on local directory instead of a remote cluster (experimental)
--timeout int Duration in seconds that the request routing layer will wait for a request delivered to a container to begin replying (default 300)
--traffic strings Set traffic distribution (format: --traffic revisionRef=percent) where revisionRef can be a revision or a tag or '@latest' string representing latest ready revision. This flag can be given multiple times with percent summing up to 100%.
--untag strings Untag revision (format: --untag tagName). This flag can be specified multiple times.
--user int The user ID to run the container (e.g., 1001).
Expand Down
12 changes: 11 additions & 1 deletion pkg/kn/commands/service/configuration_edit_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"strings"

"github.com/spf13/cobra"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"knative.dev/serving/pkg/apis/config"

knflags "knative.dev/client/pkg/kn/flags"
servinglib "knative.dev/client/pkg/serving"
Expand Down Expand Up @@ -54,6 +54,7 @@ type ConfigurationEditFlags struct {
AnnotationsRevision []string
ClusterLocal bool
ScaleInit int
TimeoutSeconds int64

// Preferences about how to do the action.
LockToDigest bool
Expand Down Expand Up @@ -170,6 +171,11 @@ func (p *ConfigurationEditFlags) addSharedFlags(command *cobra.Command) {

command.Flags().IntVar(&p.ScaleInit, "scale-init", 0, "Initial number of replicas with which a service starts. Can be 0 or a positive integer.")
p.markFlagMakesRevision("scale-init")

command.Flags().Int64Var(&p.TimeoutSeconds, "timeout", config.DefaultRevisionTimeoutSeconds,
"Duration in seconds that the request routing layer will wait for a request delivered to a "+""+
"container to begin replying")
p.markFlagMakesRevision("timeout")
}

// AddUpdateFlags adds the flags specific to update.
Expand Down Expand Up @@ -450,6 +456,10 @@ func (p *ConfigurationEditFlags) Apply(
}
}

if cmd.Flags().Changed("timeout") {
service.Spec.Template.Spec.TimeoutSeconds = &p.TimeoutSeconds
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/kn/commands/service/create_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ func getService(name string) *servingv1.Service {
Requests: corev1.ResourceList{},
},
}}

return service
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/kn/commands/service/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ func TestServiceCreateCommand(t *testing.T) {
assert.DeepEqual(t, template.Spec.Containers[0].Command, []string{"sh", "/app/start.sh"})
}

func TestServiceCreateTimeout(t *testing.T) {
action, created, _, err := fakeServiceCreate([]string{
"service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--timeout", "2"}, false)
assert.NilError(t, err)
assert.Assert(t, action.Matches("create", "services"))

timeoutSeconds := *created.Spec.Template.Spec.TimeoutSeconds
assert.NilError(t, err)
assert.DeepEqual(t, int64(2), timeoutSeconds)
}

func TestServiceCreateArg(t *testing.T) {
action, created, _, err := fakeServiceCreate([]string{
"service", "create", "foo", "--image", "gcr.io/foo/bar:baz",
Expand Down