Skip to content

feat(container): add waiter to container deploy #2681

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 3 commits into from
Dec 16, 2022
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 @@ -11,6 +11,7 @@ ARGS:

FLAGS:
-h, --help help for deploy
-w, --wait wait until the container is ready

GLOBAL FLAGS:
-c, --config string The path to the config file
Expand Down
2 changes: 2 additions & 0 deletions internal/namespaces/container/v1beta1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ func GetCommands() *core.Commands {
human.RegisterMarshalerFunc(container.ContainerStatus(""), human.EnumMarshalFunc(containerStatusMarshalSpecs))
human.RegisterMarshalerFunc(container.CronStatus(""), human.EnumMarshalFunc(cronStatusMarshalSpecs))

cmds.MustFind("container", "container", "deploy").Override(containerContainerDeployBuilder)

return cmds
}
23 changes: 23 additions & 0 deletions internal/namespaces/container/v1beta1/custom_container.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package container

import (
"context"
"time"

"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-cli/v2/internal/human"
container "github.com/scaleway/scaleway-sdk-go/api/container/v1beta1"
"github.com/scaleway/scaleway-sdk-go/scw"
)

var (
containerDeployTimeout = 12*time.Minute + 30*time.Second

containerStatusMarshalSpecs = human.EnumMarshalSpecs{
container.ContainerStatusCreated: &human.EnumMarshalSpec{Attribute: color.FgGreen},
container.ContainerStatusCreating: &human.EnumMarshalSpec{Attribute: color.FgBlue},
Expand All @@ -18,3 +25,19 @@ var (
container.ContainerStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint},
}
)

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,
})
}
return command
}