Skip to content
Open
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
1 change: 1 addition & 0 deletions flytectl/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 flytectl/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.

124 changes: 64 additions & 60 deletions flytectl/cmd/config/subcommand/sandbox/sandbox_config.go
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
package sandbox

import (
"fmt"

"github.com/flyteorg/flyte/flytectl/pkg/docker"
)

// Config holds configuration flags for sandbox command.
type Config struct {
DeprecatedSource string `json:"source" pflag:",deprecated, path of your source code, please build images with local daemon"`

// Flytectl sandbox only supports Flyte version available in Github release https://github.com/flyteorg/flyte/tags.
// Flytectl sandbox will only work for v0.10.0+.
// Default value dind represents the latest release.
Version string `json:"version" pflag:",Version of flyte. Only supports flyte releases greater than v0.10.0"`

// Optionally it is possible to specify a specific fqn for the docker image with the tag. This should be
// Flyte compliant sandbox image. Usually useful, if you want to push the image to your own registry and relaunch
// from there.
Image string `json:"image" pflag:",Optional. Provide a fully qualified path to a Flyte compliant docker image."`

// Default value false represents that Flytectl will not use the latest pre-release if it exists.
Prerelease bool `json:"pre" pflag:",Optional. Pre release Version of flyte will be used for sandbox."`

// Agent Service
DisableAgent bool `json:"disable-agent" pflag:",Optional. Disable the agent service."`

// Connector Service
DisableConnector bool `json:"disable-connector" pflag:",Optional. Disable the connector service."`

// Optionally it is possible to pass in environment variables to sandbox container.
Env []string `json:"env" pflag:",Optional. Provide Env variable in key=value format which can be passed to sandbox container."`

// Optionally it is possible to use local sandbox image
// Flytectl will not pull the image from the registry if the local flag passes. It is usually useful while testing your local images without pushing them to a registry.
ImagePullPolicy docker.ImagePullPolicy `json:"imagePullPolicy" pflag:",Optional. Defines the image pull behavior [Always/IfNotPresent/Never]"`

ImagePullOptions docker.ImagePullOptions `json:"imagePullOptions" pflag:",Optional. Defines image pull options (e.g. auth)"`

// 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."`

// Allow user to specify the port for the sandbox
Port string `json:"port" pflag:",Optional. Specify the port for the Kubernetes in the sandbox."`
}

//go:generate pflags Config --default-var DefaultConfig --bind-default-var
var (
DefaultConfig = &Config{
Port: "6443", // Default port for the sandbox
}
)

func (c Config) GetK8sEndpoint() string {
return fmt.Sprintf("https://127.0.0.1:%s", c.Port)
}
package sandbox

import (
"fmt"

"github.com/flyteorg/flyte/flytectl/pkg/docker"
)

// Config holds configuration flags for sandbox command.
type Config struct {
DeprecatedSource string `json:"source" pflag:",deprecated, path of your source code, please build images with local daemon"`

// Flytectl sandbox only supports Flyte version available in Github release https://github.com/flyteorg/flyte/tags.
// Flytectl sandbox will only work for v0.10.0+.
// Default value dind represents the latest release.
Version string `json:"version" pflag:",Version of flyte. Only supports flyte releases greater than v0.10.0"`

// Optionally it is possible to specify a specific fqn for the docker image with the tag. This should be
// Flyte compliant sandbox image. Usually useful, if you want to push the image to your own registry and relaunch
// from there.
Image string `json:"image" pflag:",Optional. Provide a fully qualified path to a Flyte compliant docker image."`

// Default value false represents that Flytectl will not use the latest pre-release if it exists.
Prerelease bool `json:"pre" pflag:",Optional. Pre release Version of flyte will be used for sandbox."`

// Agent Service
DisableAgent bool `json:"disable-agent" pflag:",Optional. Disable the agent service."`

// Connector Service
DisableConnector bool `json:"disable-connector" pflag:",Optional. Disable the connector service."`

// Optionally it is possible to pass in environment variables to sandbox container.
Env []string `json:"env" pflag:",Optional. Provide Env variable in key=value format which can be passed to sandbox container."`

// Optionally it is possible to use local sandbox image
// Flytectl will not pull the image from the registry if the local flag passes. It is usually useful while testing your local images without pushing them to a registry.
ImagePullPolicy docker.ImagePullPolicy `json:"imagePullPolicy" pflag:",Optional. Defines the image pull behavior [Always/IfNotPresent/Never]"`

ImagePullOptions docker.ImagePullOptions `json:"imagePullOptions" pflag:",Optional. Defines image pull options (e.g. auth)"`

// 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."`

// Allow user to specify the port for the sandbox
Port string `json:"port" pflag:",Optional. Specify the port for the Kubernetes in the sandbox."`

// Allow user to specify custom port mappings for the sandbox
Ports []string `json:"ports" pflag:",Optional. Custom port mappings for sandbox."`
}

//go:generate pflags Config --default-var DefaultConfig --bind-default-var
var (
DefaultConfig = &Config{
Port: "6443", // Default port for the sandbox
}
)

func (c Config) GetK8sEndpoint() string {
return fmt.Sprintf("https://127.0.0.1:%s", c.Port)
}

19 changes: 19 additions & 0 deletions flytectl/cmd/config/subcommand/sandbox/sandbox_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package sandbox

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetK8sEndpoint(t *testing.T) {
cfg := Config{
Port: "6443",
}
assert.Equal(t, "https://127.0.0.1:6443", cfg.GetK8sEndpoint())

customCfg := Config{
Port: "30086",
}
assert.Equal(t, "https://127.0.0.1:30086", customCfg.GetK8sEndpoint())
}
6 changes: 5 additions & 1 deletion flytectl/pkg/docker/docker_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ func GetDevPorts() (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error
}

// GetSandboxPorts will return sandbox ports
func GetSandboxPorts() (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error) {
func GetSandboxPorts(customPorts []string) (map[nat.Port]struct{}, map[nat.Port][]nat.PortBinding, error) {
if len(customPorts) > 0 {
return nat.ParsePortSpecs(customPorts)
}

return nat.ParsePortSpecs([]string{
// Notice that two host ports are mapped to the same container port in the case of Flyteconsole, this is done to
// support the generated URLs produced by pyflyte run
Expand Down
35 changes: 34 additions & 1 deletion flytectl/pkg/docker/docker_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestPullDockerImage(t *testing.T) {
}

func TestStartContainer(t *testing.T) {
p1, p2, _ := GetSandboxPorts()
p1, p2, _ := GetSandboxPorts(nil)

t.Run("Successfully create a container", func(t *testing.T) {
setupSandbox()
Expand Down Expand Up @@ -508,3 +508,36 @@ func TestCopyFile(t *testing.T) {
assert.Equal(t, myErr, err)
})
}

func TestGetSandboxPorts(t *testing.T) {
t.Run("Default sandbox ports", func(t *testing.T) {
exposedPorts, portBindings, err := GetSandboxPorts(nil)
assert.Nil(t, err)
assert.Equal(t, 6, len(exposedPorts))
assert.Equal(t, 6, len(portBindings))
assert.Equal(t, 2, len(portBindings["30081/tcp"]))
})

t.Run("Empty slice returns default sandbox ports", func(t *testing.T) {
exposedPorts, portBindings, err := GetSandboxPorts([]string{})
assert.Nil(t, err)
assert.Equal(t, 6, len(exposedPorts))
assert.Equal(t, 6, len(portBindings))
assert.Equal(t, 2, len(portBindings["30081/tcp"]))
})

t.Run("Custom sandbox ports", func(t *testing.T) {
customPorts := []string{"30080:30081", "30086:30086"}
exposedPorts, portBindings, err := GetSandboxPorts(customPorts)
assert.Nil(t, err)
assert.Equal(t, 2, len(exposedPorts))
assert.Equal(t, 2, len(portBindings))
})

t.Run("Invalid custom sandbox ports", func(t *testing.T) {
invalidPorts := []string{"invalid-port-format"}
_, _, err := GetSandboxPorts(invalidPorts)
assert.NotNil(t, err)
})
}

7 changes: 5 additions & 2 deletions flytectl/pkg/sandbox/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,17 @@ func StartDemoCluster(ctx context.Context, args []string, sandboxConfig *sandbox

func StartSandboxCluster(ctx context.Context, args []string, sandboxConfig *sandboxCmdConfig.Config) error {
demoImagePrefix := "dind"
exposedPorts, portBindings, err := docker.GetSandboxPorts()

exposedPorts, portBindings, err := docker.GetSandboxPorts(sandboxConfig.Ports)
if err != nil {
return err
}

err = StartClusterForSandbox(ctx, args, sandboxConfig, sandboxImageName, demoImagePrefix, exposedPorts, portBindings, util.SandBoxConsolePort)
if err != nil {
return err
}

util.PrintSandboxStartMessage(util.SandBoxConsolePort, docker.SandboxKubeconfig, sandboxConfig.DryRun)
return nil
}
}
2 changes: 1 addition & 1 deletion flytectl/pkg/sandbox/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func dummyReader() io.ReadCloser {

func TestStartFunc(t *testing.T) {
defaultImagePrefix := "dind"
exposedPorts, portBindings, _ := docker.GetSandboxPorts()
exposedPorts, portBindings, _ := docker.GetSandboxPorts(nil)
config := sandboxCmdConfig.DefaultConfig
config.Image = "dummyimage"
config.ImagePullOptions = docker.ImagePullOptions{
Expand Down
Loading