diff --git a/pkg/cmd/adm/install_operator.go b/pkg/cmd/adm/install_operator.go index 6326bd5..92cc376 100644 --- a/pkg/cmd/adm/install_operator.go +++ b/pkg/cmd/adm/install_operator.go @@ -24,8 +24,9 @@ import ( ) type installArgs struct { - kubeConfig string - namespace string + kubeConfig string + namespace string + waitForReadyTimeout time.Duration } func NewInstallOperatorCmd() *cobra.Command { @@ -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) @@ -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) @@ -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)) diff --git a/pkg/cmd/adm/install_operator_test.go b/pkg/cmd/adm/install_operator_test.go index 8c63d9f..6c9a4fd 100644 --- a/pkg/cmd/adm/install_operator_test.go +++ b/pkg/cmd/adm/install_operator_test.go @@ -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) { @@ -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) @@ -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.") @@ -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.") @@ -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), ) @@ -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) @@ -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 @@ -194,7 +193,6 @@ func TestInstallOperator(t *testing.T) { // when err := installOperator(ctx, installArgs{}, "INVALIDOPERATOR", - 1*time.Second, commonclient.NewApplyClient(fakeClient), ) @@ -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), )