Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
enable --force flag in flyte demo start (#432)
Browse files Browse the repository at this point in the history
Signed-off-by: Future Outlier <[email protected]>
Co-authored-by: Future Outlier <[email protected]>
  • Loading branch information
Future-Outlier and Future Outlier authored Oct 18, 2023
1 parent 64e0d7b commit 043a611
Show file tree
Hide file tree
Showing 10 changed files with 224 additions and 3 deletions.
55 changes: 55 additions & 0 deletions cmd/config/subcommand/docker/config_flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 116 additions & 0 deletions cmd/config/subcommand/docker/config_flags_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions cmd/config/subcommand/docker/docker_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package docker

//go:generate pflags Config --default-var DefaultConfig --bind-default-var
var (
DefaultConfig = &Config{
Force: false,
}
)

// Configs
type Config struct {
Force bool `json:"force" pflag:",Optional. Forcefully delete existing sandbox cluster if it exists."`
}
1 change: 1 addition & 0 deletions cmd/config/subcommand/sandbox/config_flags.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions cmd/config/subcommand/sandbox/config_flags_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cmd/config/subcommand/sandbox/sandbox_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Config struct {
// It's used for development. Users are able to start flyte locally via single binary and save the data to the minio or postgres in the sandbox.
Dev bool `json:"dev" pflag:",Optional. Only start minio and postgres in the sandbox."`
DryRun bool `json:"dryRun" pflag:",Optional. Only print the docker commands to bring up flyte sandbox/demo container.This will still call github api's to get the latest flyte release to use'"`

Force bool `json:"force" pflag:",Optional. Forcefully delete existing sandbox cluster if it exists."`
}

//go:generate pflags Config --default-var DefaultConfig --bind-default-var
Expand Down
12 changes: 12 additions & 0 deletions pkg/docker/docker_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package docker

// Config holds configuration flags for docker command.
var (
DefaultConfig = &Config{
Force: false,
}
)

type Config struct {
Force bool `json:"force" pflag:",Optional. Forcefully delete existing sandbox cluster if it exists."`
}
7 changes: 4 additions & 3 deletions pkg/docker/docker_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"github.com/docker/docker/client"
"github.com/enescakir/emoji"

"github.com/flyteorg/flytectl/clierrors"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/go-connections/nat"
"github.com/flyteorg/flytectl/clierrors"
"github.com/flyteorg/flytectl/cmd/config/subcommand/docker"
cmdUtil "github.com/flyteorg/flytectl/pkg/commandutils"
f "github.com/flyteorg/flytectl/pkg/filesystemutils"
)
Expand Down Expand Up @@ -93,8 +93,9 @@ func RemoveSandbox(ctx context.Context, cli Docker, reader io.Reader) error {
if err != nil {
return err
}

if c != nil {
if cmdUtil.AskForConfirmation("delete existing sandbox cluster", reader) {
if docker.DefaultConfig.Force || cmdUtil.AskForConfirmation("delete existing sandbox cluster", reader) {
err := cli.ContainerRemove(context.Background(), c.ID, types.ContainerRemoveOptions{
Force: true,
})
Expand Down
5 changes: 5 additions & 0 deletions pkg/docker/docker_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/stretchr/testify/mock"

"github.com/docker/docker/api/types"
"github.com/flyteorg/flytectl/cmd/config/subcommand/docker"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -88,6 +89,10 @@ func TestRemoveSandboxWithNoReply(t *testing.T) {
mockDocker.OnContainerRemove(ctx, mock.Anything, types.ContainerRemoveOptions{Force: true}).Return(nil)
err := RemoveSandbox(ctx, mockDocker, strings.NewReader("n"))
assert.NotNil(t, err)

docker.DefaultConfig.Force = true
err = RemoveSandbox(ctx, mockDocker, strings.NewReader(""))
assert.Nil(t, err)
})

t.Run("Successfully remove sandbox container with zero sandbox containers are running", func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/sandbox/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/docker/go-connections/nat"
"github.com/enescakir/emoji"
"github.com/flyteorg/flytectl/clierrors"
dockerCmdConfig "github.com/flyteorg/flytectl/cmd/config/subcommand/docker"
sandboxCmdConfig "github.com/flyteorg/flytectl/cmd/config/subcommand/sandbox"
"github.com/flyteorg/flytectl/pkg/configutil"
"github.com/flyteorg/flytectl/pkg/docker"
Expand Down Expand Up @@ -157,6 +158,7 @@ func startSandbox(ctx context.Context, cli docker.Docker, g github.GHRepoService
if sandboxConfig.DryRun {
docker.PrintRemoveContainer(docker.FlyteSandboxClusterName)
} else {
dockerCmdConfig.DefaultConfig.Force = sandboxConfig.Force
if err := docker.RemoveSandbox(ctx, cli, reader); err != nil {
if err.Error() != clierrors.ErrSandboxExists {
return nil, err
Expand Down

0 comments on commit 043a611

Please sign in to comment.