Add timeout option to service create (#1643)

* Add timeout option to service create

* Changed unit tests to reflect the default timeout value

* Fixed timeout help message

* Added unit test for --timeout flag

* Moved --timeout flag to shared flags
This commit is contained in:
Gunjan Vyas 2022-04-13 21:44:09 +05:30 committed by GitHub
parent bb7fd73821
commit 0ac405d4b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 1 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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).

View File

@ -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
}

View File

@ -478,6 +478,7 @@ func getService(name string) *servingv1.Service {
Requests: corev1.ResourceList{},
},
}}
return service
}

View File

@ -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",