Repository: knative/client (go)

Issue:
kn needs the ability top set a default timeout for the service

### Feature request

kn create needs a flag for setting the default timeout for the service

### Use case

I want to create my services with a default timeout of 10 seconds rather than the standard 300 - currently I can't create a service with the timeout of 10 secs and need to post-create change it (in this case using the OpenShift UI/YAML editor) which creates a new revision

There are flags for most things when creating a service but this one (timeoutSeconds) seems to be missing

/kind proposal


Pull request description:
Add timeout option to service create
## Description

Add `--timeout` option which will set the field, `timeoutInSeconds` in service spec. 

<!-- Please add a short summary about what the pull request is going to bring on the table -->

## Changes

<!-- Please add list of more detailed changes. These changes should be reflected also in the commit messages -->

* Added the flag


## Reference

<!-- Please add the corresponding issue number which this pull request is about to fix -->
Fixes #1181 

<!--
Please add an entry to CHANGELOG.adoc file, too, as part of your Pull Request.

In the following cases, add a short description of PR to the unreleased section in CHANGELOG.adoc:

- 🎁 New feature
- 🐛 Bug fix
- ✨ Feature Update
- 🐣 Refactoring
- 🗑️ Remove feature or internal logic

See other entries in CHANGELOG.adoc as an example for how to add the entry, including a reference to the corresponding issue/PR

PLEASE DON'T ADD THAT LINE HERE IN THE PULL-REQUEST DESCRIPTION BUT DIRECTLY IN CHANGELOG.ADOC AND ADD CHANGELOG.ADOC AS PART OF YOUR PULL-REQUEST.
-->

<!--
To automatically lint go code in this pull request uncomment the line below. You get feedback as comments on your pull request then -->

<!--
/lint
-->


Patch:
diff --git a/docs/cmd/kn_service_apply.md b/docs/cmd/kn_service_apply.md
index 978cc4ec..341b9455 100644
--- a/docs/cmd/kn_service_apply.md
+++ b/docs/cmd/kn_service_apply.md
@@ -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)
diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md
index 1a0c8ca9..9d7e6968 100644
--- a/docs/cmd/kn_service_create.md
+++ b/docs/cmd/kn_service_create.md
@@ -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)
diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md
index 8c37dee8..9be0a55d 100644
--- a/docs/cmd/kn_service_update.md
+++ b/docs/cmd/kn_service_update.md
@@ -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).
diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go
index f66e9836..17b13e08 100644
--- a/pkg/kn/commands/service/configuration_edit_flags.go
+++ b/pkg/kn/commands/service/configuration_edit_flags.go
@@ -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"
@@ -54,6 +54,7 @@ type ConfigurationEditFlags struct {
 	AnnotationsRevision []string
 	ClusterLocal        bool
 	ScaleInit           int
+	TimeoutSeconds      int64
 
 	// Preferences about how to do the action.
 	LockToDigest         bool
@@ -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.
@@ -450,6 +456,10 @@ func (p *ConfigurationEditFlags) Apply(
 		}
 	}
 
+	if cmd.Flags().Changed("timeout") {
+		service.Spec.Template.Spec.TimeoutSeconds = &p.TimeoutSeconds
+	}
+
 	return nil
 }
 


Test patch:
diff --git a/pkg/kn/commands/service/create_mock_test.go b/pkg/kn/commands/service/create_mock_test.go
index 290fb91e..67a83a6f 100644
--- a/pkg/kn/commands/service/create_mock_test.go
+++ b/pkg/kn/commands/service/create_mock_test.go
@@ -478,6 +478,7 @@ func getService(name string) *servingv1.Service {
 			Requests: corev1.ResourceList{},
 		},
 	}}
+
 	return service
 }
 
diff --git a/pkg/kn/commands/service/create_test.go b/pkg/kn/commands/service/create_test.go
index 1a938851..e1e2a1e2 100644
--- a/pkg/kn/commands/service/create_test.go
+++ b/pkg/kn/commands/service/create_test.go
@@ -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",