diff --git a/docs/cmd/kn_service_update.md b/docs/cmd/kn_service_update.md index 8c37dee855..9be0a55d1c 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 367b2893fd..17b13e08f3 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -21,9 +21,8 @@ import ( "strings" "github.com/spf13/cobra" - "knative.dev/serving/pkg/apis/config" - 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" @@ -172,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. @@ -219,10 +223,6 @@ func (p *ConfigurationEditFlags) AddCreateFlags(command *cobra.Command) { "Labels to set for both Service and Revision. name=value; you may provide this flag "+ "any number of times to set multiple labels.") p.markFlagMakesRevision("label") - 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") } // Apply mutates the given service according to the flags in the command. @@ -456,6 +456,10 @@ func (p *ConfigurationEditFlags) Apply( } } + if cmd.Flags().Changed("timeout") { + service.Spec.Template.Spec.TimeoutSeconds = &p.TimeoutSeconds + } + return nil } diff --git a/pkg/kn/commands/service/create.go b/pkg/kn/commands/service/create.go index e0fefd453a..df52b846cb 100644 --- a/pkg/kn/commands/service/create.go +++ b/pkg/kn/commands/service/create.go @@ -265,7 +265,6 @@ func constructService(cmd *cobra.Command, editFlags ConfigurationEditFlags, name }, } service.Spec.Template.Spec.Containers = []corev1.Container{{}} - service.Spec.Template.Spec.TimeoutSeconds = &editFlags.TimeoutSeconds err := editFlags.Apply(&service, nil, cmd) if err != nil { diff --git a/pkg/kn/commands/service/create_mock_test.go b/pkg/kn/commands/service/create_mock_test.go index 210484439e..67a83a6f23 100644 --- a/pkg/kn/commands/service/create_mock_test.go +++ b/pkg/kn/commands/service/create_mock_test.go @@ -19,7 +19,6 @@ import ( "time" "knative.dev/serving/pkg/apis/autoscaling" - "knative.dev/serving/pkg/apis/config" "gotest.tools/v3/assert" corev1 "k8s.io/api/core/v1" @@ -480,8 +479,6 @@ func getService(name string) *servingv1.Service { }, }} - var defaultTimeout int64 = config.DefaultRevisionTimeoutSeconds - service.Spec.Template.Spec.TimeoutSeconds = &defaultTimeout return service }