Skip to content

Commit

Permalink
Fixes #964: Add the --wait flag to install (#966)
Browse files Browse the repository at this point in the history
This is the initial work for `install --wait`.   Follow up work to come with issue: #1418

Signed-off-by: Anthony Dahanne <anthony.dahanne@gmail.com>
  • Loading branch information
anthonydahanne committed Mar 11, 2020
1 parent 321d4ac commit 451d5c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/kudoctl/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ func newInstallCmd(fs afero.Fs) *cobra.Command {
installCmd.Flags().StringVar(&options.AppVersion, "app-version", "", "A specific app version in the official GitHub repo. (default to the most recent)")
installCmd.Flags().StringVar(&options.OperatorVersion, "operator-version", "", "A specific operator version int the official GitHub repo. (default to the most recent)")
installCmd.Flags().BoolVar(&options.SkipInstance, "skip-instance", false, "If set, install will install the Operator and OperatorVersion, but not an Instance. (default \"false\")")
installCmd.Flags().BoolVar(&options.Wait, "wait", false, "Specify if the CLI should wait for the install to complete before returning (default \"false\")")
return installCmd
}
3 changes: 2 additions & 1 deletion pkg/kudoctl/cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Options struct {
OperatorVersion string
SkipInstance bool
RequestTimeout int64
Wait bool
}

// DefaultOptions initializes the install command options to its defaults
Expand Down Expand Up @@ -75,5 +76,5 @@ func installOperator(operatorArgument string, options *Options, fs afero.Fs, set
return fmt.Errorf("failed to resolve operator package for: %s %w", operatorArgument, err)
}

return kudo.InstallPackage(kc, pkg.Resources, options.SkipInstance, options.InstanceName, settings.Namespace, options.Parameters)
return kudo.InstallPackage(kc, pkg.Resources, options.SkipInstance, options.InstanceName, settings.Namespace, options.Parameters, options.Wait)
}
23 changes: 22 additions & 1 deletion pkg/kudoctl/util/kudo/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kudo
import (
"fmt"
"strings"
"time"

"github.com/kudobuilder/kudo/pkg/apis/kudo/v1beta1"
"github.com/kudobuilder/kudo/pkg/kudoctl/clog"
Expand All @@ -11,7 +12,7 @@ import (

// InstallPackage installs package resources.
// If skipInstance is set to true, only a package's Operator and OperatorVersion is installed.
func InstallPackage(kc *Client, resources *packages.Resources, skipInstance bool, instanceName, namespace string, parameters map[string]string) error {
func InstallPackage(kc *Client, resources *packages.Resources, skipInstance bool, instanceName, namespace string, parameters map[string]string, wait bool) error {
// PRE-INSTALLATION SETUP
operatorName := resources.Operator.ObjectMeta.Name
clog.V(3).Printf("operator name: %v", operatorName)
Expand Down Expand Up @@ -63,6 +64,26 @@ func InstallPackage(kc *Client, resources *packages.Resources, skipInstance bool
if _, err := kc.InstallInstanceObjToCluster(resources.Instance, namespace); err != nil {
return fmt.Errorf("failed to install instance %s: %v", instanceName, err)
}
if wait {
for {
instance, err := kc.GetInstance(instanceName, namespace)

if err != nil {
return fmt.Errorf("failed to get instance %s: %v", instanceName, err)
}
lastPlanStatus := instance.GetLastExecutedPlanStatus()

if err != nil {
return fmt.Errorf("failed to get plan status %s: %v", instanceName, err)
}
if lastPlanStatus == nil || !lastPlanStatus.Status.IsFinished() {
fmt.Printf("plan status %s still pending, please wait...\n", instanceName)
time.Sleep(2 * time.Second)
} else {
break
}
}
}
clog.Printf("instance.%s/%s created", resources.Instance.APIVersion, resources.Instance.Name)
} else {
return clog.Errorf("cannot install instance '%s' of operator '%s-%s' because an instance of that name already exists in namespace %s",
Expand Down
2 changes: 1 addition & 1 deletion pkg/kudoctl/util/kudo/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func Test_InstallPackage(t *testing.T) {
testResources.OperatorVersion.Spec.Parameters = tt.parameters
namespace := "default" //nolint:goconst

err := InstallPackage(kc, &testResources, tt.skipInstance, "", namespace, tt.installParameters)
err := InstallPackage(kc, &testResources, tt.skipInstance, "", namespace, tt.installParameters, false)
if tt.err != "" {
assert.ErrorContains(t, err, tt.err)
}
Expand Down

0 comments on commit 451d5c4

Please sign in to comment.