Skip to content

Commit

Permalink
increase wait for install timeout (#65)
Browse files Browse the repository at this point in the history
* move timeout to options

---------

Co-authored-by: Devtools <[email protected]>
  • Loading branch information
mfrancisc and Devtools authored Aug 21, 2024
1 parent cdad74f commit 0ffc21a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
14 changes: 8 additions & 6 deletions pkg/cmd/adm/install_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import (
)

type installArgs struct {
kubeConfig string
namespace string
kubeConfig string
namespace string
waitForReadyTimeout time.Duration
}

func NewInstallOperatorCmd() *cobra.Command {
Expand All @@ -43,17 +44,18 @@ func NewInstallOperatorCmd() *cobra.Command {

cl := commonclient.NewApplyClient(kubeClient)
ctx := clicontext.NewTerminalContext(term)
return installOperator(ctx, commandArgs, args[0], time.Second*60, cl)
return installOperator(ctx, commandArgs, args[0], cl)
},
}

cmd.Flags().StringVar(&commandArgs.kubeConfig, "kubeconfig", "", "Path to the kubeconfig file to use.")
flags.MustMarkRequired(cmd, "kubeconfig")
cmd.Flags().StringVar(&commandArgs.namespace, "namespace", "", "The namespace where the operator will be installed. Host and Member should be installed in separate namespaces. If the namespace is not provided the standard namespace names are used: toolchain-host|member-operator.")
cmd.Flags().DurationVar(&commandArgs.waitForReadyTimeout, "timeout", time.Second*180, "The max timeout used when waiting for each of the resources to be installed.")
return cmd
}

func installOperator(ctx *clicontext.TerminalContext, args installArgs, operator string, timeout time.Duration, applyClient *commonclient.ApplyClient) error {
func installOperator(ctx *clicontext.TerminalContext, args installArgs, operator string, applyClient *commonclient.ApplyClient) error {
// validate cluster type
if operator != string(configuration.Host) && operator != string(configuration.Member) {
return fmt.Errorf("invalid operator type provided: %s. Valid ones are %s|%s", operator, configuration.Host, configuration.Member)
Expand Down Expand Up @@ -89,7 +91,7 @@ func installOperator(ctx *clicontext.TerminalContext, args installArgs, operator
return err
}
ctx.Println(fmt.Sprintf("CatalogSource %s created.", catalogSource.Name))
if err := waitUntilCatalogSourceIsReady(ctx, applyClient, namespacedName, timeout); err != nil {
if err := waitUntilCatalogSourceIsReady(ctx, applyClient, namespacedName, args.waitForReadyTimeout); err != nil {
return err
}
ctx.Printlnf("CatalogSource %s is ready", namespacedName)
Expand Down Expand Up @@ -119,7 +121,7 @@ func installOperator(ctx *clicontext.TerminalContext, args installArgs, operator
return err
}
ctx.Println(fmt.Sprintf("Subcription %s created.", subscription.Name))
if err := waitUntilInstallPlanIsComplete(ctx, applyClient, operatorName, namespace, timeout); err != nil {
if err := waitUntilInstallPlanIsComplete(ctx, applyClient, operatorName, namespace, args.waitForReadyTimeout); err != nil {
return err
}
ctx.Println(fmt.Sprintf("InstallPlan for the %s operator has been completed", operator))
Expand Down
23 changes: 10 additions & 13 deletions pkg/cmd/adm/install_operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func TestInstallOperator(t *testing.T) {
}
timeout := 1 * time.Second
args := installArgs{
kubeConfig: kubeconfig,
namespace: namespace,
kubeConfig: kubeconfig,
namespace: namespace,
waitForReadyTimeout: timeout,
}

t.Run("install "+operator+" operator is successful", func(t *testing.T) {
Expand All @@ -63,7 +64,7 @@ func TestInstallOperator(t *testing.T) {
ctx := clicontext.NewTerminalContext(term)

// when
err := installOperator(ctx, args, operator, timeout, commonclient.NewApplyClient(fakeClient))
err := installOperator(ctx, args, operator, commonclient.NewApplyClient(fakeClient))

// then
require.NoError(t, err)
Expand Down Expand Up @@ -97,7 +98,7 @@ func TestInstallOperator(t *testing.T) {
ctx := clicontext.NewTerminalContext(term)

// when
err := installOperator(ctx, args, operator, timeout, commonclient.NewApplyClient(fakeClient))
err := installOperator(ctx, args, operator, commonclient.NewApplyClient(fakeClient))

// then
require.ErrorContains(t, err, "failed waiting for catalog source to be ready.")
Expand All @@ -117,7 +118,7 @@ func TestInstallOperator(t *testing.T) {
ctx := clicontext.NewTerminalContext(term)

// when
err := installOperator(ctx, args, operator, timeout, commonclient.NewApplyClient(fakeClient))
err := installOperator(ctx, args, operator, commonclient.NewApplyClient(fakeClient))

// then
require.ErrorContains(t, err, "failed waiting for install plan to be complete.")
Expand All @@ -135,9 +136,8 @@ func TestInstallOperator(t *testing.T) {
ctx := clicontext.NewTerminalContext(term)

// when
err := installOperator(ctx, installArgs{namespace: namespace},
err := installOperator(ctx, installArgs{namespace: namespace, waitForReadyTimeout: 1 * time.Second},
operator,
1*time.Second,
commonclient.NewApplyClient(fakeClient),
)

Expand All @@ -156,7 +156,7 @@ func TestInstallOperator(t *testing.T) {
ctx := clicontext.NewTerminalContext(term)

// when
err := installOperator(ctx, args, operator, timeout, commonclient.NewApplyClient(fakeClient))
err := installOperator(ctx, args, operator, commonclient.NewApplyClient(fakeClient))

// then
require.NoError(t, err)
Expand All @@ -173,9 +173,8 @@ func TestInstallOperator(t *testing.T) {
ctx := clicontext.NewTerminalContext(term)

// when
err := installOperator(ctx, installArgs{namespace: "", kubeConfig: kubeconfig}, // we provide no namespace
err := installOperator(ctx, installArgs{namespace: "", kubeConfig: kubeconfig, waitForReadyTimeout: timeout}, // we provide no namespace
operator,
timeout,
commonclient.NewApplyClient(fakeClient),
)
// then
Expand All @@ -194,7 +193,6 @@ func TestInstallOperator(t *testing.T) {
// when
err := installOperator(ctx, installArgs{},
"INVALIDOPERATOR",
1*time.Second,
commonclient.NewApplyClient(fakeClient),
)

Expand All @@ -210,9 +208,8 @@ func TestInstallOperator(t *testing.T) {

// when
operator := "host"
err := installOperator(ctx, installArgs{namespace: "toolchain-host-operator"},
err := installOperator(ctx, installArgs{namespace: "toolchain-host-operator", waitForReadyTimeout: time.Second * 1},
operator,
1*time.Second,
commonclient.NewApplyClient(fakeClient),
)

Expand Down

0 comments on commit 0ffc21a

Please sign in to comment.