Skip to content

Commit ff568a1

Browse files
authored
feat(container): add waiters (#3098)
1 parent d0c1da8 commit ff568a1

File tree

6 files changed

+49
-23
lines changed

6 files changed

+49
-23
lines changed

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

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

2929
FLAGS:
3030
-h, --help help for create
31+
-w, --wait wait until the container is ready
3132

3233
GLOBAL FLAGS:
3334
-c, --config string The path to the config file

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

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

2929
FLAGS:
3030
-h, --help help for update
31+
-w, --wait wait until the container is ready
3132

3233
GLOBAL FLAGS:
3334
-c, --config string The path to the config file

cmd/scw/testdata/test-all-usage-container-namespace-update-usage.golden

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

1616
FLAGS:
1717
-h, --help help for update
18+
-w, --wait wait until the namespace is ready
1819

1920
GLOBAL FLAGS:
2021
-c, --config string The path to the config file

internal/namespaces/container/v1beta1/custom.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ func GetCommands() *core.Commands {
1414
human.RegisterMarshalerFunc(container.CronStatus(""), human.EnumMarshalFunc(cronStatusMarshalSpecs))
1515

1616
cmds.MustFind("container", "container", "deploy").Override(containerContainerDeployBuilder)
17+
cmds.MustFind("container", "container", "create").Override(containerContainerCreateBuilder)
18+
cmds.MustFind("container", "container", "update").Override(containerContainerUpdateBuilder)
1719
cmds.MustFind("container", "namespace", "create").Override(containerNamespaceCreateBuilder)
20+
cmds.MustFind("container", "namespace", "update").Override(containerNamespaceUpdateBuilder)
1821
cmds.MustFind("container", "namespace", "delete").Override(containerNamespaceDeleteBuilder)
1922

2023
cmds.Add(containerDeployCommand())

internal/namespaces/container/v1beta1/custom_container.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,30 @@ var (
2626
}
2727
)
2828

29+
func waitForContainer(ctx context.Context, _, respI interface{}) (interface{}, error) {
30+
c := respI.(*container.Container)
31+
32+
client := core.ExtractClient(ctx)
33+
api := container.NewAPI(client)
34+
return api.WaitForContainer(&container.WaitForContainerRequest{
35+
ContainerID: c.ID,
36+
Region: c.Region,
37+
Timeout: scw.TimeDurationPtr(containerDeployTimeout),
38+
RetryInterval: core.DefaultRetryInterval,
39+
})
40+
}
41+
2942
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-
}
43+
command.WaitFunc = waitForContainer
44+
return command
45+
}
46+
47+
func containerContainerCreateBuilder(command *core.Command) *core.Command {
48+
command.WaitFunc = waitForContainer
49+
return command
50+
}
51+
52+
func containerContainerUpdateBuilder(command *core.Command) *core.Command {
53+
command.WaitFunc = waitForContainer
4254
return command
4355
}

internal/namespaces/container/v1beta1/custom_namespace.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,27 @@ var (
2525
}
2626
)
2727

28+
func waitForContainerNamespace(ctx context.Context, _, respI interface{}) (interface{}, error) {
29+
ns := respI.(*container.Namespace)
30+
31+
client := core.ExtractClient(ctx)
32+
api := container.NewAPI(client)
33+
return api.WaitForNamespace(&container.WaitForNamespaceRequest{
34+
NamespaceID: ns.ID,
35+
Region: ns.Region,
36+
Timeout: scw.TimeDurationPtr(containerNamespaceActionTimeout),
37+
RetryInterval: core.DefaultRetryInterval,
38+
})
39+
}
40+
2841
func containerNamespaceCreateBuilder(c *core.Command) *core.Command {
29-
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
30-
res := respI.(*container.Namespace)
42+
c.WaitFunc = waitForContainerNamespace
3143

32-
client := core.ExtractClient(ctx)
33-
api := container.NewAPI(client)
34-
return api.WaitForNamespace(&container.WaitForNamespaceRequest{
35-
NamespaceID: res.ID,
36-
Region: res.Region,
37-
Timeout: scw.TimeDurationPtr(containerNamespaceActionTimeout),
38-
RetryInterval: core.DefaultRetryInterval,
39-
})
40-
}
44+
return c
45+
}
46+
47+
func containerNamespaceUpdateBuilder(c *core.Command) *core.Command {
48+
c.WaitFunc = waitForContainerNamespace
4149

4250
return c
4351
}

0 commit comments

Comments
 (0)