Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connect): fix connect with enable_public for public facing #17

Merged
merged 1 commit into from
Aug 3, 2022
Merged
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
10 changes: 8 additions & 2 deletions cmd/multikf/cmd_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func NewConnectCommand(logger log.Logger, ioStreams genericclioptions.IOStreams)

func newConnectKubeflowCommand(logger log.Logger, ioStreams genericclioptions.IOStreams) *cobra.Command {
var (
port int // dedicated port
port int // dedicated port
enablePublic bool // enable public access
)
handle := func(machineName string) error {
m, err := findMachineByName(machineName, logger)
Expand All @@ -35,7 +36,11 @@ func newConnectKubeflowCommand(logger log.Logger, ioStreams genericclioptions.IO
}
}
logger.V(0).Infof("now you can open http://localhost:%d\n", destPort)
return m.GetKubeCli().Portforward(m.GetKubeConfig(), "svc/istio-ingressgateway", "istio-system", 80, destPort)
var listenedAddress string
if enablePublic {
listenedAddress = "0.0.0.0"
}
return m.GetKubeCli().Portforward(m.GetKubeConfig(), "svc/istio-ingressgateway", "istio-system", listenedAddress, 80, destPort)
}
cmd := &cobra.Command{
Use: "kubeflow",
Expand All @@ -46,5 +51,6 @@ func newConnectKubeflowCommand(logger log.Logger, ioStreams genericclioptions.IO
}

cmd.Flags().IntVar(&port, "port", 0, "customized port number for connect, ranged should be 65535> >1024, default is 0 (random)")
cmd.Flags().BoolVar(&enablePublic, "enable_public", false, "enable public access, default: false")
return cmd
}
8 changes: 7 additions & 1 deletion pkg/machine/kubectl/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (cli *CLI) PatchKubeflow(kubeConfigFile string) error {
return nil
}

func (cli *CLI) Portforward(kubeConfigFile, svc, namespace string, fromPort, toPort int) error {
func (cli *CLI) Portforward(kubeConfigFile, svc, namespace string, address string, fromPort, toPort int) error {
// TODO: auto reconnect
cmdAndArgs := []string{
cli.localKubectlBinaryPath,
Expand All @@ -244,6 +244,12 @@ func (cli *CLI) Portforward(kubeConfigFile, svc, namespace string, fromPort, toP
"--kubeconfig",
kubeConfigFile,
}
if len(address) != 0 {
cmdAndArgs = append(cmdAndArgs, []string{
"--address",
address,
}...)
}
sr, _, err := cli.runCmd(cmdAndArgs)
if err != nil {
return err
Expand Down