Skip to content

feat(container): add waiters #3098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions internal/namespaces/container/v1beta1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ 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", "update").Override(containerNamespaceUpdateBuilder)
cmds.MustFind("container", "namespace", "delete").Override(containerNamespaceDeleteBuilder)

cmds.Add(containerDeployCommand())
Expand Down
36 changes: 24 additions & 12 deletions internal/namespaces/container/v1beta1/custom_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
30 changes: 19 additions & 11 deletions internal/namespaces/container/v1beta1/custom_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down