From aae74d08004abd598ccf414023e26461eb22abe9 Mon Sep 17 00:00:00 2001 From: Glyn Normington Date: Thu, 23 Aug 2018 17:56:24 +0100 Subject: [PATCH] Add --wait switch on riff function create Fixes https://github.com/projectriff/riff/issues/682 --- cmd/commands/function.go | 10 ++++++++++ cmd/commands/shared.go | 1 + docs/riff_function_create.md | 1 + pkg/core/function.go | 6 ++++-- pkg/core/mocks/Client.go | 1 + pkg/core/service.go | 1 + 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/commands/function.go b/cmd/commands/function.go index 5007b67bf..0fd5d9aec 100644 --- a/cmd/commands/function.go +++ b/cmd/commands/function.go @@ -137,6 +137,9 @@ From then on you can use the sub-commands for the 'service' command to interact } } else { printSuccessfulCompletion(cmd) + if !createFunctionOptions.Verbose && !createFunctionOptions.Wait { + fmt.Fprintf(cmd.OutOrStdout(), "Issue `riff service status %s` to see the status of the function\n", fnName) + } } return nil @@ -188,6 +191,13 @@ From then on you can use the sub-commands for the 'service' command to interact "verbose", "v", verboseUsage, ).NoOptDefVal = "true" + command.Flags().VarPF( + BroadcastBoolValue(false, + &createFunctionOptions.Wait, + ), + "wait", "w", waitUsage, + ).NoOptDefVal = "true" + command.Flags().Var( BroadcastStringValue("", &createInputChannelOptions.Bus, diff --git a/cmd/commands/shared.go b/cmd/commands/shared.go index 43439aa63..aaf9268df 100644 --- a/cmd/commands/shared.go +++ b/cmd/commands/shared.go @@ -28,4 +28,5 @@ or 'secretKeyRef' to select a key from a Secret. The following formats are suppo --env-from configMapKeyRef:{config-map-name}:{key-to-select} --env-from secretKeyRef:{secret-name}:{key-to-select}` verboseUsage = "print details of command progress" + waitUsage = "wait until the created resource reaches either a successful or an error state (automatic with --verbose)" ) diff --git a/docs/riff_function_create.md b/docs/riff_function_create.md index 6c7f5dc0f..682fcfa0a 100644 --- a/docs/riff_function_create.md +++ b/docs/riff_function_create.md @@ -47,6 +47,7 @@ riff function create [flags] -n, --namespace namespace the namespace of the subscription, channel, and function -o, --output channel name of the function's output channel, if any -v, --verbose print details of command progress + -w, --wait wait until the created resource reaches either a successful or an error state (automatic with --verbose) ``` ### Options inherited from parent commands diff --git a/pkg/core/function.go b/pkg/core/function.go index 9bde9736f..ac16ed3e0 100644 --- a/pkg/core/function.go +++ b/pkg/core/function.go @@ -97,10 +97,12 @@ func (c *client) CreateFunction(options CreateFunctionOptions, log io.Writer) (* return nil, err } - if options.Verbose { + if options.Verbose || options.Wait { stopChan := make(chan struct{}) errChan := make(chan error) - go c.displayFunctionCreationProgress(ns, s.Name, log, stopChan, errChan) + if options.Verbose { + go c.displayFunctionCreationProgress(ns, s.Name, log, stopChan, errChan) + } err := c.waitForSuccessOrFailure(ns, s.Name, stopChan, errChan) if err != nil { return nil, err diff --git a/pkg/core/mocks/Client.go b/pkg/core/mocks/Client.go index 990a87c83..ee55701f6 100644 --- a/pkg/core/mocks/Client.go +++ b/pkg/core/mocks/Client.go @@ -1,4 +1,5 @@ // Code generated by mockery v1.0.0. DO NOT EDIT. + package mocks import core "github.com/projectriff/riff/pkg/core" diff --git a/pkg/core/service.go b/pkg/core/service.go index 7a48c5217..257be9afa 100644 --- a/pkg/core/service.go +++ b/pkg/core/service.go @@ -47,6 +47,7 @@ type CreateServiceOptions struct { EnvFrom []string DryRun bool Verbose bool + Wait bool } func (c *client) CreateService(options CreateServiceOptions) (*v1alpha1.Service, error) {