Skip to content

Commit

Permalink
print forwarding information (act like kubectl port-forward) to remov…
Browse files Browse the repository at this point in the history
…e any confusion
  • Loading branch information
mhewedy committed Jun 8, 2020
1 parent 7bea68e commit aea5554
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions vms/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const rangeSep = "-"
//
// output format: ["-L", "0.0.0.0:<local port>:localhost:<vm port>"]
//
func getPortForwardArgs(ports string) ([]string, error) {
a, err := mapPorts(ports)
func getPortForwardArgs(vmName, ports string) ([]string, error) {
a, err := mapPorts(vmName, ports)
if err != nil {
return nil, err
}
Expand All @@ -37,7 +37,7 @@ func getPortForwardArgs(ports string) ([]string, error) {
return args, nil
}

func mapPorts(ports string) ([]string, error) {
func mapPorts(vmName, ports string) ([]string, error) {

args := strings.Fields(ports)
var result []string
Expand All @@ -58,6 +58,7 @@ func mapPorts(ports string) ([]string, error) {
}

for vm, local := range portMap {
fmt.Printf("Forwarding from %s:%s -> localhost:%s\n", vmName, vm, local)
result = append(result, "0.0.0.0:"+local+":localhost:"+vm)
}
}
Expand Down
2 changes: 1 addition & 1 deletion vms/port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestGetPortForwardArgs(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := mapPorts(tt.args.ports)
got, err := mapPorts("", tt.args.ports)
if (err != nil) != tt.wantErr {
t.Errorf("mapPorts() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
2 changes: 1 addition & 1 deletion vms/vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func PortForward(vmName string, ports string) error {
return err
}

a, err := getPortForwardArgs(ports)
a, err := getPortForwardArgs(vmName, ports)
if err != nil {
return err
}
Expand Down

0 comments on commit aea5554

Please sign in to comment.