Skip to content

Commit

Permalink
Add console endpoint config section and init arg (#361)
Browse files Browse the repository at this point in the history
* Add console endpoint init arg and config section

Signed-off-by: Andrew Dye <[email protected]>

* Log invalid endpoint

Signed-off-by: Andrew Dye <[email protected]>

Signed-off-by: Andrew Dye <[email protected]>
  • Loading branch information
andrewwdye authored Oct 13, 2022
1 parent a64a416 commit e2ed562
Show file tree
Hide file tree
Showing 11 changed files with 280 additions and 3 deletions.
1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/config/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/config/config_flags_test.go

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

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

import "github.com/flyteorg/flytestdlib/config"

//go:generate pflags ConsoleConfig --default-var DefaultConsoleConfig --bind-default-var

var (
DefaultConsoleConfig = &ConsoleConfig{}

cfg = config.MustRegisterSection("console", DefaultConsoleConfig)
)

// FilesConfig containing flags used for registration
type ConsoleConfig struct {
Endpoint string `json:"endpoint" pflag:",Endpoint of console, if different than flyte admin"`
}

func GetConfig() *ConsoleConfig {
return cfg.GetConfig().(*ConsoleConfig)
}
55 changes: 55 additions & 0 deletions flytectl/cmd/config/subcommand/config/consoleconfig_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 flytectl/cmd/config/subcommand/config/consoleconfig_flags_test.go

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

1 change: 1 addition & 0 deletions flytectl/cmd/config/subcommand/config/init_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var (

// Configs
type Config struct {
Console string `json:"console" pflag:",Endpoint of console, if different than flyte admin"`
Host string `json:"host" pflag:",Endpoint of flyte admin"`
Insecure bool `json:"insecure" pflag:",Enable insecure mode"`
}
16 changes: 13 additions & 3 deletions flytectl/cmd/configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Flyte Sandbox is a fully standalone minimal environment for running Flyte.
Read more about the Sandbox deployment :ref:` + "`here <deploy-sandbox-local>`" + `.
Generate remote cluster config:
::
flytectl config init --host=flyte.myexample.com
Expand All @@ -43,11 +42,15 @@ By default, the connection is secure.
Read more about remote deployment :ref:` + "`here <Deployment>`" + `.
Generate remote cluster config with insecure connection:
::
flytectl config init --host=flyte.myexample.com --insecure
Generate remote cluster config with separate console endpoint:
::
flytectl config init --host=flyte.myexample.com --console=console.myexample.com
Generate Flytectl config with a storage provider:
::
Expand Down Expand Up @@ -90,11 +93,18 @@ func initFlytectlConfig(reader io.Reader) error {
if len(initConfig.DefaultConfig.Host) > 0 {
trimHost := trimEndpoint(initConfig.DefaultConfig.Host)
if !validateEndpointName(trimHost) {
return errors.New("Please use a valid endpoint")
return fmt.Errorf("%s invalid, please use a valid admin endpoint", trimHost)
}
templateValues.Host = fmt.Sprintf("dns:///%s", trimHost)
templateValues.Insecure = initConfig.DefaultConfig.Insecure
}
if len(initConfig.DefaultConfig.Console) > 0 {
trimConsole := trimEndpoint(initConfig.DefaultConfig.Console)
if !validateEndpointName(trimConsole) {
return fmt.Errorf("%s invalid, please use a valid console endpoint", trimConsole)
}
templateValues.Console = initConfig.DefaultConfig.Console
}
var _err error
if _, err := os.Stat(configutil.ConfigFile); os.IsNotExist(err) {
_err = configutil.SetupConfig(configutil.ConfigFile, templateStr, templateValues)
Expand Down
2 changes: 2 additions & 0 deletions flytectl/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ admin:
endpoint: dns:///localhost:30081
insecure: true
authType: Pkce
console:
endpoint: http://localhost:30080
logger:
show-source: true
level: 0
Expand Down
5 changes: 5 additions & 0 deletions flytectl/pkg/configutil/configutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const (
endpoint: {{.Host}}
authType: Pkce
insecure: {{.Insecure}}
{{- if .Console}}
console:
endpoint: {{.Console}}
{{- end}}
logger:
show-source: true
level: 0`
Expand All @@ -21,6 +25,7 @@ logger:
type ConfigTemplateSpec struct {
Host string
Insecure bool
Console string
}

var (
Expand Down
52 changes: 52 additions & 0 deletions flytectl/pkg/configutil/configutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,60 @@ import (

f "github.com/flyteorg/flytectl/pkg/filesystemutils"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestSetupConfig(t *testing.T) {
file, err := os.CreateTemp("", "*.yaml")
require.NoError(t, err)

templateValue := ConfigTemplateSpec{
Host: "dns:///localhost:30081",
Insecure: true,
}
err = SetupConfig(file.Name(), AdminConfigTemplate, templateValue)
assert.NoError(t, err)
configBytes, err := ioutil.ReadAll(file)
assert.NoError(t, err)
expected := `admin:
# For GRPC endpoints you might want to use dns:///flyte.myexample.com
endpoint: dns:///localhost:30081
authType: Pkce
insecure: true
logger:
show-source: true
level: 0`
assert.Equal(t, expected, string(configBytes))

file, err = os.Create(file.Name())
require.NoError(t, err)
templateValue = ConfigTemplateSpec{
Host: "dns:///admin.example.com",
Insecure: true,
Console: "https://console.example.com",
}
err = SetupConfig(file.Name(), AdminConfigTemplate, templateValue)
assert.NoError(t, err)
configBytes, err = ioutil.ReadAll(file)
assert.NoError(t, err)
expected = `admin:
# For GRPC endpoints you might want to use dns:///flyte.myexample.com
endpoint: dns:///admin.example.com
authType: Pkce
insecure: true
console:
endpoint: https://console.example.com
logger:
show-source: true
level: 0`
assert.Equal(t, expected, string(configBytes))

// Cleanup
if file != nil {
_ = os.Remove(file.Name())
}
}

func TestConfigCleanup(t *testing.T) {
_, err := os.Stat(f.FilePathJoin(f.UserHomeDir(), ".flyte"))
if os.IsNotExist(err) {
Expand Down
1 change: 1 addition & 0 deletions flytectl/pkg/sandbox/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func startSandbox(ctx context.Context, cli docker.Docker, g github.GHRepoService
templateValues := configutil.ConfigTemplateSpec{
Host: "localhost:30081",
Insecure: true,
Console: fmt.Sprintf("http://localhost:%d", consolePort),
}
if err := configutil.SetupConfig(configutil.FlytectlConfig, configutil.GetTemplate(), templateValues); err != nil {
return nil, err
Expand Down

0 comments on commit e2ed562

Please sign in to comment.