Skip to content

Commit

Permalink
feat(container): add waiters (#3098)
Browse files Browse the repository at this point in the history
  • Loading branch information
Codelax committed May 2, 2023
1 parent d0c1da8 commit ff568a1
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 23 deletions.
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

0 comments on commit ff568a1

Please sign in to comment.