Skip to content

Commit a33a8a0

Browse files
Codelaxremyleone
andauthored
feat(container): add waiter to container deploy (#2681)
Co-authored-by: Rémy Léone <rleone@scaleway.com>
1 parent 7a35753 commit a33a8a0

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

cmd/scw/testdata/test-all-usage-container-container-deploy-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ARGS:
1111

1212
FLAGS:
1313
-h, --help help for deploy
14+
-w, --wait wait until the container is ready
1415

1516
GLOBAL FLAGS:
1617
-c, --config string The path to the config file

internal/namespaces/container/v1beta1/custom.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ func GetCommands() *core.Commands {
1313
human.RegisterMarshalerFunc(container.ContainerStatus(""), human.EnumMarshalFunc(containerStatusMarshalSpecs))
1414
human.RegisterMarshalerFunc(container.CronStatus(""), human.EnumMarshalFunc(cronStatusMarshalSpecs))
1515

16+
cmds.MustFind("container", "container", "deploy").Override(containerContainerDeployBuilder)
17+
1618
return cmds
1719
}

internal/namespaces/container/v1beta1/custom_container.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package container
22

33
import (
4+
"context"
5+
"time"
6+
47
"github.com/fatih/color"
8+
"github.com/scaleway/scaleway-cli/v2/internal/core"
59
"github.com/scaleway/scaleway-cli/v2/internal/human"
610
container "github.com/scaleway/scaleway-sdk-go/api/container/v1beta1"
11+
"github.com/scaleway/scaleway-sdk-go/scw"
712
)
813

914
var (
15+
containerDeployTimeout = 12*time.Minute + 30*time.Second
16+
1017
containerStatusMarshalSpecs = human.EnumMarshalSpecs{
1118
container.ContainerStatusCreated: &human.EnumMarshalSpec{Attribute: color.FgGreen},
1219
container.ContainerStatusCreating: &human.EnumMarshalSpec{Attribute: color.FgBlue},
@@ -18,3 +25,19 @@ var (
1825
container.ContainerStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint},
1926
}
2027
)
28+
29+
func containerContainerDeployBuilder(command *core.Command) *core.Command {
30+
command.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
31+
req := argsI.(*container.DeployContainerRequest)
32+
33+
client := core.ExtractClient(ctx)
34+
api := container.NewAPI(client)
35+
return api.WaitForContainer(&container.WaitForContainerRequest{
36+
ContainerID: req.ContainerID,
37+
Region: req.Region,
38+
Timeout: scw.TimeDurationPtr(containerDeployTimeout),
39+
RetryInterval: core.DefaultRetryInterval,
40+
})
41+
}
42+
return command
43+
}

0 commit comments

Comments
 (0)