Skip to content

Commit

Permalink
feat(container): add waiter to container deploy (#2681)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémy Léone <rleone@scaleway.com>
  • Loading branch information
Codelax and remyleone committed Dec 16, 2022
1 parent 7a35753 commit a33a8a0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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
}

0 comments on commit a33a8a0

Please sign in to comment.