Skip to content

Commit e23654d

Browse files
author
Yago Carlos Fernandez Gou
committed
Address review: add waiters to create/update/delete operations
1 parent 0cb825f commit e23654d

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

internal/cmd/beta/intake/runner/create/create.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
"github.com/stackitcloud/stackit-sdk-go/services/intake"
1111

12+
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/intake/wait"
1213
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1314
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1415
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -18,6 +19,7 @@ import (
1819
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1920
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
2021
"github.com/stackitcloud/stackit-cli/internal/pkg/services/intake/client"
22+
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
2123
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2224
)
2325

@@ -87,6 +89,17 @@ func NewCreateCmd(p *params.CmdParams) *cobra.Command {
8789
return fmt.Errorf("create Intake Runner: %w", err)
8890
}
8991

92+
// Wait for async operation, if async mode not enabled
93+
if !model.Async {
94+
s := spinner.New(p.Printer)
95+
s.Start("Creating STACKIT Intake Runner instance")
96+
_, err = wait.CreateOrUpdateIntakeRunnerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, resp.GetId()).WaitWithContext(ctx)
97+
if err != nil {
98+
return fmt.Errorf("wait for STACKIT Instance creation: %w", err)
99+
}
100+
s.Stop()
101+
}
102+
90103
return outputResult(p.Printer, model.OutputFormat, projectLabel, resp)
91104
},
92105
}

internal/cmd/beta/intake/runner/delete/delete.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ import (
55
"fmt"
66

77
"github.com/spf13/cobra"
8+
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/intake/wait"
89
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
910
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1011
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
1112
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
1213
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1314
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1415
"github.com/stackitcloud/stackit-cli/internal/pkg/services/intake/client"
16+
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
1517
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1618
"github.com/stackitcloud/stackit-sdk-go/services/intake"
1719
)
@@ -64,7 +66,23 @@ func NewDeleteCmd(p *params.CmdParams) *cobra.Command {
6466
if err = req.Execute(); err != nil {
6567
return fmt.Errorf("delete Intake Runner: %w", err)
6668
}
67-
p.Printer.Info("Deleted runner %s\n", model.RunnerId)
69+
70+
// Wait for async operation, if async mode not enabled
71+
if !model.Async {
72+
s := spinner.New(p.Printer)
73+
s.Start("Deleting STACKIT Intake Runner instance")
74+
_, err = wait.DeleteIntakeRunnerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.RunnerId).WaitWithContext(ctx)
75+
if err != nil {
76+
return fmt.Errorf("wait for STACKIT Instance deletion: %w", err)
77+
}
78+
s.Stop()
79+
}
80+
81+
operationState := "Deleted"
82+
if model.Async {
83+
operationState = "Triggered deletion of"
84+
}
85+
p.Printer.Info("%s stackit Intake Runner instance %s \n", operationState, model.RunnerId)
6886

6987
return nil
7088
},

internal/cmd/beta/intake/runner/update/update.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/goccy/go-yaml"
99
"github.com/spf13/cobra"
1010

11+
"github.com/stackitcloud/stackit-cli/internal/cmd/beta/intake/wait"
1112
"github.com/stackitcloud/stackit-cli/internal/cmd/params"
1213
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
1314
cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -17,6 +18,7 @@ import (
1718
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
1819
"github.com/stackitcloud/stackit-cli/internal/pkg/projectname"
1920
"github.com/stackitcloud/stackit-cli/internal/pkg/services/intake/client"
21+
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"
2022
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2123
"github.com/stackitcloud/stackit-sdk-go/services/intake"
2224
)
@@ -83,6 +85,17 @@ func NewUpdateCmd(p *params.CmdParams) *cobra.Command {
8385
return fmt.Errorf("update Intake Runner: %w", err)
8486
}
8587

88+
// Wait for async operation, if async mode not enabled
89+
if !model.Async {
90+
s := spinner.New(p.Printer)
91+
s.Start("Updating STACKIT Intake Runner instance")
92+
_, err = wait.CreateOrUpdateIntakeRunnerWaitHandler(ctx, apiClient, model.ProjectId, model.Region, model.RunnerId).WaitWithContext(ctx)
93+
if err != nil {
94+
return fmt.Errorf("wait for STACKIT Instance creation: %w", err)
95+
}
96+
s.Stop()
97+
}
98+
8699
return outputResult(p.Printer, model.OutputFormat, projectLabel, resp)
87100
},
88101
}

0 commit comments

Comments
 (0)