From 69204ac09f922ef0929397d0a7e4e2215f3d74f0 Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Thu, 27 Apr 2023 14:30:34 +0200 Subject: [PATCH 1/2] feat(container): add waiters --- ...ge-container-container-create-usage.golden | 1 + ...ge-container-container-update-usage.golden | 1 + .../namespaces/container/v1beta1/custom.go | 2 ++ .../container/v1beta1/custom_container.go | 36 ++++++++++++------- 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cmd/scw/testdata/test-all-usage-container-container-create-usage.golden b/cmd/scw/testdata/test-all-usage-container-container-create-usage.golden index 01bad8340e..50bc870f5b 100644 --- a/cmd/scw/testdata/test-all-usage-container-container-create-usage.golden +++ b/cmd/scw/testdata/test-all-usage-container-container-create-usage.golden @@ -28,6 +28,7 @@ ARGS: FLAGS: -h, --help help for create + -w, --wait wait until the container is ready GLOBAL FLAGS: -c, --config string The path to the config file diff --git a/cmd/scw/testdata/test-all-usage-container-container-update-usage.golden b/cmd/scw/testdata/test-all-usage-container-container-update-usage.golden index 45218691ef..0247908171 100644 --- a/cmd/scw/testdata/test-all-usage-container-container-update-usage.golden +++ b/cmd/scw/testdata/test-all-usage-container-container-update-usage.golden @@ -28,6 +28,7 @@ ARGS: FLAGS: -h, --help help for update + -w, --wait wait until the container is ready GLOBAL FLAGS: -c, --config string The path to the config file diff --git a/internal/namespaces/container/v1beta1/custom.go b/internal/namespaces/container/v1beta1/custom.go index 1381772125..6608c26dc0 100644 --- a/internal/namespaces/container/v1beta1/custom.go +++ b/internal/namespaces/container/v1beta1/custom.go @@ -14,6 +14,8 @@ func GetCommands() *core.Commands { human.RegisterMarshalerFunc(container.CronStatus(""), human.EnumMarshalFunc(cronStatusMarshalSpecs)) cmds.MustFind("container", "container", "deploy").Override(containerContainerDeployBuilder) + cmds.MustFind("container", "container", "create").Override(containerContainerCreateBuilder) + cmds.MustFind("container", "container", "update").Override(containerContainerUpdateBuilder) cmds.MustFind("container", "namespace", "create").Override(containerNamespaceCreateBuilder) cmds.MustFind("container", "namespace", "delete").Override(containerNamespaceDeleteBuilder) diff --git a/internal/namespaces/container/v1beta1/custom_container.go b/internal/namespaces/container/v1beta1/custom_container.go index 66c295e8e0..e01f315183 100644 --- a/internal/namespaces/container/v1beta1/custom_container.go +++ b/internal/namespaces/container/v1beta1/custom_container.go @@ -26,18 +26,30 @@ var ( } ) +func waitForContainer(ctx context.Context, _, respI interface{}) (interface{}, error) { + c := respI.(*container.Container) + + client := core.ExtractClient(ctx) + api := container.NewAPI(client) + return api.WaitForContainer(&container.WaitForContainerRequest{ + ContainerID: c.ID, + Region: c.Region, + Timeout: scw.TimeDurationPtr(containerDeployTimeout), + RetryInterval: core.DefaultRetryInterval, + }) +} + func containerContainerDeployBuilder(command *core.Command) *core.Command { - command.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) { - req := argsI.(*container.DeployContainerRequest) - - client := core.ExtractClient(ctx) - api := container.NewAPI(client) - return api.WaitForContainer(&container.WaitForContainerRequest{ - ContainerID: req.ContainerID, - Region: req.Region, - Timeout: scw.TimeDurationPtr(containerDeployTimeout), - RetryInterval: core.DefaultRetryInterval, - }) - } + command.WaitFunc = waitForContainer + return command +} + +func containerContainerCreateBuilder(command *core.Command) *core.Command { + command.WaitFunc = waitForContainer + return command +} + +func containerContainerUpdateBuilder(command *core.Command) *core.Command { + command.WaitFunc = waitForContainer return command } From cb1087a02e2a8ee5fbe5bf15fac3cfad81d789ce Mon Sep 17 00:00:00 2001 From: Jules Casteran Date: Tue, 2 May 2023 11:58:29 +0200 Subject: [PATCH 2/2] add waiter to namespace update --- ...ge-container-namespace-update-usage.golden | 1 + .../namespaces/container/v1beta1/custom.go | 1 + .../container/v1beta1/custom_namespace.go | 30 ++++++++++++------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/cmd/scw/testdata/test-all-usage-container-namespace-update-usage.golden b/cmd/scw/testdata/test-all-usage-container-namespace-update-usage.golden index fa4d5cea9a..feeb0c641a 100644 --- a/cmd/scw/testdata/test-all-usage-container-namespace-update-usage.golden +++ b/cmd/scw/testdata/test-all-usage-container-namespace-update-usage.golden @@ -15,6 +15,7 @@ ARGS: FLAGS: -h, --help help for update + -w, --wait wait until the namespace is ready GLOBAL FLAGS: -c, --config string The path to the config file diff --git a/internal/namespaces/container/v1beta1/custom.go b/internal/namespaces/container/v1beta1/custom.go index 6608c26dc0..b984641862 100644 --- a/internal/namespaces/container/v1beta1/custom.go +++ b/internal/namespaces/container/v1beta1/custom.go @@ -17,6 +17,7 @@ func GetCommands() *core.Commands { cmds.MustFind("container", "container", "create").Override(containerContainerCreateBuilder) cmds.MustFind("container", "container", "update").Override(containerContainerUpdateBuilder) cmds.MustFind("container", "namespace", "create").Override(containerNamespaceCreateBuilder) + cmds.MustFind("container", "namespace", "update").Override(containerNamespaceUpdateBuilder) cmds.MustFind("container", "namespace", "delete").Override(containerNamespaceDeleteBuilder) cmds.Add(containerDeployCommand()) diff --git a/internal/namespaces/container/v1beta1/custom_namespace.go b/internal/namespaces/container/v1beta1/custom_namespace.go index 4f2b3653d9..fc6d75c5f4 100644 --- a/internal/namespaces/container/v1beta1/custom_namespace.go +++ b/internal/namespaces/container/v1beta1/custom_namespace.go @@ -25,19 +25,27 @@ var ( } ) +func waitForContainerNamespace(ctx context.Context, _, respI interface{}) (interface{}, error) { + ns := respI.(*container.Namespace) + + client := core.ExtractClient(ctx) + api := container.NewAPI(client) + return api.WaitForNamespace(&container.WaitForNamespaceRequest{ + NamespaceID: ns.ID, + Region: ns.Region, + Timeout: scw.TimeDurationPtr(containerNamespaceActionTimeout), + RetryInterval: core.DefaultRetryInterval, + }) +} + func containerNamespaceCreateBuilder(c *core.Command) *core.Command { - c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) { - res := respI.(*container.Namespace) + c.WaitFunc = waitForContainerNamespace - client := core.ExtractClient(ctx) - api := container.NewAPI(client) - return api.WaitForNamespace(&container.WaitForNamespaceRequest{ - NamespaceID: res.ID, - Region: res.Region, - Timeout: scw.TimeDurationPtr(containerNamespaceActionTimeout), - RetryInterval: core.DefaultRetryInterval, - }) - } + return c +} + +func containerNamespaceUpdateBuilder(c *core.Command) *core.Command { + c.WaitFunc = waitForContainerNamespace return c }