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

feat: add address option to the cli ui command #1468

Merged
Merged
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
14 changes: 8 additions & 6 deletions cli/cmd/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ var uiCmd = &cobra.Command{
}

localPort := cmd.Flag("port").Value.String()
if err := portForwardWithContext(ctx, uiPod, client, localPort); err != nil {
localAddress := cmd.Flag("address").Value.String()
if err := portForwardWithContext(ctx, uiPod, client, localPort, localAddress); err != nil {
fmt.Printf("\033[31mERROR\033[0m Cannot start port-forward: %s\n", err)
os.Exit(1)
}
},
}

func portForwardWithContext(ctx context.Context, uiPod *corev1.Pod, client *kube.Client, localPort string) error {
func portForwardWithContext(ctx context.Context, uiPod *corev1.Pod, client *kube.Client, localPort string, localAddress string) error {
stopChannel := make(chan struct{}, 1)
readyChannel := make(chan struct{})
signals := make(chan os.Signal, 1)
Expand All @@ -84,7 +85,7 @@ func portForwardWithContext(ctx context.Context, uiPod *corev1.Pod, client *kube
close(stopChannel)
}()

fmt.Printf("Odigos UI is available at: http://localhost:%s\n\n", localPort)
fmt.Printf("Odigos UI is available at: http://%s:%s\n\n", localAddress, localPort)
fmt.Printf("Port-forwarding from %s/%s\n", uiPod.Namespace, uiPod.Name)
fmt.Printf("Press Ctrl+C to stop\n")

Expand All @@ -95,7 +96,7 @@ func portForwardWithContext(ctx context.Context, uiPod *corev1.Pod, client *kube
Name(uiPod.Name).
SubResource("portforward")

return forwardPorts("POST", req.URL(), client.Config, stopChannel, readyChannel, localPort)
return forwardPorts("POST", req.URL(), client.Config, stopChannel, readyChannel, localPort, localAddress)
}

func createDialer(method string, url *url.URL, cfg *rest.Config) (httpstream.Dialer, error) {
Expand All @@ -115,15 +116,15 @@ func createDialer(method string, url *url.URL, cfg *rest.Config) (httpstream.Dia
return dialer, nil
}

func forwardPorts(method string, url *url.URL, cfg *rest.Config, stopCh chan struct{}, readyCh chan struct{}, localPort string) error {
func forwardPorts(method string, url *url.URL, cfg *rest.Config, stopCh chan struct{}, readyCh chan struct{}, localPort string, localAddress string) error {
dialer, err := createDialer(method, url, cfg)
if err != nil {
return err
}

port := fmt.Sprintf("%s:%d", localPort, defaultPort)
fw, err := portforward.NewOnAddresses(dialer,
[]string{"localhost"},
[]string{localAddress},
[]string{port}, stopCh, readyCh, nil, os.Stderr)

if err != nil {
Expand Down Expand Up @@ -156,4 +157,5 @@ func findOdigosUIPod(client *kube.Client, ctx context.Context, ns string) (*core
func init() {
rootCmd.AddCommand(uiCmd)
uiCmd.Flags().Int("port", defaultPort, "port to listen on")
uiCmd.Flags().String("address", "localhost", "Address to listen on")
}
Loading