Skip to content

Commit

Permalink
Share demo/sandbox status command logic (flyteorg#364)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Shuy <[email protected]>

Signed-off-by: Daniel Shuy <[email protected]>
  • Loading branch information
daniel-shuy authored and robert-ulbrich-mercedes-benz committed Jul 2, 2024
1 parent 1464792 commit 8954d97
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 32 deletions.
19 changes: 3 additions & 16 deletions flytectl/cmd/demo/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package demo

import (
"context"
"fmt"

"github.com/enescakir/emoji"
"github.com/flyteorg/flytectl/pkg/sandbox"

cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flytectl/pkg/docker"
)
Expand All @@ -28,18 +28,5 @@ func demoClusterStatus(ctx context.Context, args []string, cmdCtx cmdCore.Comman
return err
}

return printStatus(ctx, cli)
}

func printStatus(ctx context.Context, cli docker.Docker) error {
c, err := docker.GetSandbox(ctx, cli)
if err != nil {
return err
}
if c == nil {
fmt.Printf("%v no demo cluster found \n", emoji.StopSign)
return nil
}
fmt.Printf("Flyte demo cluster container image [%s] with status [%s] is in state [%s]", c.Image, c.Status, c.State)
return nil
return sandbox.PrintStatus(ctx, cli)
}
19 changes: 3 additions & 16 deletions flytectl/cmd/sandbox/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package sandbox

import (
"context"
"fmt"

"github.com/enescakir/emoji"
"github.com/flyteorg/flytectl/pkg/sandbox"

cmdCore "github.com/flyteorg/flytectl/cmd/core"
"github.com/flyteorg/flytectl/pkg/docker"
)
Expand All @@ -28,18 +28,5 @@ func sandboxClusterStatus(ctx context.Context, args []string, cmdCtx cmdCore.Com
return err
}

return printStatus(ctx, cli)
}

func printStatus(ctx context.Context, cli docker.Docker) error {
c, err := docker.GetSandbox(ctx, cli)
if err != nil {
return err
}
if c == nil {
fmt.Printf("%v no Sandbox found \n", emoji.StopSign)
return nil
}
fmt.Printf("Flyte local sandbox cluster container image [%s] with status [%s] is in state [%s]", c.Image, c.Status, c.State)
return nil
return sandbox.PrintStatus(ctx, cli)
}
22 changes: 22 additions & 0 deletions flytectl/pkg/sandbox/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package sandbox

import (
"context"
"fmt"

"github.com/enescakir/emoji"
"github.com/flyteorg/flytectl/pkg/docker"
)

func PrintStatus(ctx context.Context, cli docker.Docker) error {
c, err := docker.GetSandbox(ctx, cli)
if err != nil {
return err
}
if c == nil {
fmt.Printf("%v no Sandbox found \n", emoji.StopSign)
return nil
}
fmt.Printf("Flyte local sandbox container image [%s] with status [%s] is in state [%s]", c.Image, c.Status, c.State)
return nil
}
37 changes: 37 additions & 0 deletions flytectl/pkg/sandbox/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package sandbox

import (
"testing"

"github.com/flyteorg/flytectl/cmd/testutils"

"github.com/docker/docker/api/types"
"github.com/flyteorg/flytectl/pkg/docker"
"github.com/flyteorg/flytectl/pkg/docker/mocks"
"github.com/stretchr/testify/assert"
)

func TestSandboxStatus(t *testing.T) {
t.Run("Sandbox status with zero result", func(t *testing.T) {
mockDocker := &mocks.Docker{}
s := testutils.Setup()
mockDocker.OnContainerList(s.Ctx, types.ContainerListOptions{All: true}).Return([]types.Container{}, nil)
err := PrintStatus(s.Ctx, mockDocker)
assert.Nil(t, err)
})
t.Run("Sandbox status with running sandbox", func(t *testing.T) {
s := testutils.Setup()
ctx := s.Ctx
mockDocker := &mocks.Docker{}
mockDocker.OnContainerList(ctx, types.ContainerListOptions{All: true}).Return([]types.Container{
{
ID: docker.FlyteSandboxClusterName,
Names: []string{
docker.FlyteSandboxClusterName,
},
},
}, nil)
err := PrintStatus(ctx, mockDocker)
assert.Nil(t, err)
})
}

0 comments on commit 8954d97

Please sign in to comment.