diff --git a/docs/cmd/kn_service_create.md b/docs/cmd/kn_service_create.md index e7e61b8414..85fffedcfa 100644 --- a/docs/cmd/kn_service_create.md +++ b/docs/cmd/kn_service_create.md @@ -36,6 +36,7 @@ kn service create NAME --image IMAGE [flags] ### Options ``` + --async Don't wait for the service to become Ready. -e, --env stringArray Environment variable to set. NAME=value; you may provide this flag any number of times to set multiple environment variables. --force Create service forcefully, replaces existing service if any. -h, --help help for create @@ -45,6 +46,7 @@ kn service create NAME --image IMAGE [flags] -n, --namespace string List the requested object(s) in given namespace. --requests-cpu string The requested CPU (e.g., 250m). --requests-memory string The requested CPU (e.g., 64Mi). + --wait-timeout int Wait for that many seconds before giving up when creating a service. (default 60) ``` ### Options inherited from parent commands diff --git a/pkg/kn/commands/service/configuration_edit_flags.go b/pkg/kn/commands/service/configuration_edit_flags.go index 825da96190..78b04f6211 100644 --- a/pkg/kn/commands/service/configuration_edit_flags.go +++ b/pkg/kn/commands/service/configuration_edit_flags.go @@ -31,7 +31,7 @@ type ConfigurationEditFlags struct { RequestsFlags, LimitsFlags ResourceFlags ForceCreate bool Async bool - WaitTimeout int + WaitTimeout int } type ResourceFlags struct { diff --git a/pkg/kn/commands/service/service_create.go b/pkg/kn/commands/service/service_create.go index 94f8ef550e..2da13fdfa3 100644 --- a/pkg/kn/commands/service/service_create.go +++ b/pkg/kn/commands/service/service_create.go @@ -35,7 +35,6 @@ import ( v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) - func NewServiceCreateCommand(p *commands.KnParams) *cobra.Command { var editFlags ConfigurationEditFlags @@ -182,7 +181,7 @@ func constructService(cmd *cobra.Command, editFlags ConfigurationEditFlags, name } func showUrl(client serving_v1alpha1_client.ServingV1alpha1Interface, serviceName string, namespace string, out io.Writer) error { - service, err := client.Services(namespace).Get(serviceName,v1.GetOptions{}) + service, err := client.Services(namespace).Get(serviceName, v1.GetOptions{}) if err != nil { return fmt.Errorf("cannot fetch service %s in namespace %s for extracting the URL", serviceName, namespace) } @@ -205,7 +204,7 @@ func waitForService(client serving_v1alpha1_client.ServingV1alpha1Interface, ser // timeout. We have our own timeout which fire after "timeout" seconds and stop the watch var timeoutWatch int64 = int64(timeout + 30) opts := v1.ListOptions{ - FieldSelector: fields.OneTermEqualSelector("metadata.name", serviceName).String(), + FieldSelector: fields.OneTermEqualSelector("metadata.name", serviceName).String(), TimeoutSeconds: &timeoutWatch, } watcher, err := client.Services(namespace).Watch(opts) @@ -229,9 +228,9 @@ func waitForReadyCondition(watcher watch.Interface, timeout int) error { defer watcher.Stop() for { select { - case <- time.After(time.Duration(timeout) * time.Second): + case <-time.After(time.Duration(timeout) * time.Second): return fmt.Errorf("timeout: Service not ready after %d seconds", timeout) - case event, ok := <- watcher.ResultChan(): + case event, ok := <-watcher.ResultChan(): if !ok || event.Object == nil { return errors.New("timeout while waiting for service to become ready") } @@ -242,11 +241,10 @@ func waitForReadyCondition(watcher watch.Interface, timeout int) error { case corev1.ConditionTrue: return nil case corev1.ConditionFalse: - return fmt.Errorf("%s: %s",cond.Reason,cond.Message) + return fmt.Errorf("%s: %s", cond.Reason, cond.Message) } } } } } } - diff --git a/pkg/kn/commands/service/service_create_test.go b/pkg/kn/commands/service/service_create_test.go index 9ba480a8d9..a539e53d23 100644 --- a/pkg/kn/commands/service/service_create_test.go +++ b/pkg/kn/commands/service/service_create_test.go @@ -120,7 +120,7 @@ func TestServiceCreateEnv(t *testing.T) { func TestServiceCreateWithRequests(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--requests-cpu", "250m", "--requests-memory", "64Mi","--async"}, false) + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--requests-cpu", "250m", "--requests-memory", "64Mi", "--async"}, false) if err != nil { t.Fatal(err) @@ -146,7 +146,7 @@ func TestServiceCreateWithRequests(t *testing.T) { func TestServiceCreateWithLimits(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--limits-cpu", "1000m", "--limits-memory", "1024Mi","--async"}, false) + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--limits-cpu", "1000m", "--limits-memory", "1024Mi", "--async"}, false) if err != nil { t.Fatal(err) @@ -172,7 +172,7 @@ func TestServiceCreateWithLimits(t *testing.T) { func TestServiceCreateRequestsLimitsCPU(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--requests-cpu", "250m", "--limits-cpu", "1000m","--async"}, false) + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--requests-cpu", "250m", "--limits-cpu", "1000m", "--async"}, false) if err != nil { t.Fatal(err) @@ -209,7 +209,7 @@ func TestServiceCreateRequestsLimitsCPU(t *testing.T) { func TestServiceCreateRequestsLimitsMemory(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--requests-memory", "64Mi", "--limits-memory", "1024Mi","--async"}, false) + "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--requests-memory", "64Mi", "--limits-memory", "1024Mi", "--async"}, false) if err != nil { t.Fatal(err) @@ -248,7 +248,7 @@ func TestServiceCreateRequestsLimitsCPUMemory(t *testing.T) { action, created, _, err := fakeServiceCreate([]string{ "service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--requests-cpu", "250m", "--limits-cpu", "1000m", - "--requests-memory", "64Mi", "--limits-memory", "1024Mi","--async"}, false) + "--requests-memory", "64Mi", "--limits-memory", "1024Mi", "--async"}, false) if err != nil { t.Fatal(err) @@ -295,12 +295,12 @@ func parseQuantity(t *testing.T, quantityString string) resource.Quantity { func TestServiceCreateImageForce(t *testing.T) { _, _, _, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--image", "gcr.io/foo/bar:v1","--async"}, false) + "service", "create", "foo", "--image", "gcr.io/foo/bar:v1", "--async"}, false) if err != nil { t.Fatal(err) } action, created, output, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--force", "--image", "gcr.io/foo/bar:v2","--async"}, false) + "service", "create", "foo", "--force", "--image", "gcr.io/foo/bar:v2", "--async"}, false) if err != nil { t.Fatal(err) } else if !action.Matches("create", "services") { @@ -318,12 +318,12 @@ func TestServiceCreateImageForce(t *testing.T) { func TestServiceCreateEnvForce(t *testing.T) { _, _, _, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--image", "gcr.io/foo/bar:v1", "-e", "A=DOGS", "--env", "B=WOLVES","--async"}, false) + "service", "create", "foo", "--image", "gcr.io/foo/bar:v1", "-e", "A=DOGS", "--env", "B=WOLVES", "--async"}, false) if err != nil { t.Fatal(err) } action, created, output, err := fakeServiceCreate([]string{ - "service", "create", "foo", "--force", "--image", "gcr.io/foo/bar:v2", "-e", "A=CATS", "--env", "B=LIONS","--async"}, false) + "service", "create", "foo", "--force", "--image", "gcr.io/foo/bar:v2", "-e", "A=CATS", "--env", "B=LIONS", "--async"}, false) if err != nil { t.Fatal(err)