Skip to content

Commit

Permalink
Output port-forward logs when --verbose flag is set
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Lingerfelt <kl@buoyant.io>
  • Loading branch information
klingerf committed Jan 9, 2019
1 parent 4313521 commit 8e10e3b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cli/cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ const (
// showURL displays dashboard URLs without opening a browser.
showURL = "url"

// webDeployment is the name of the web UI's deployment in the install config
// webDeployment is the name of the web deployment in cli/install/template.go
webDeployment = "linkerd-web"

// webPort is the port on which the web UI is served in the web pod
// webPort is the http port from the web pod spec in cli/install/template.go
webPort = 8084
)

Expand Down Expand Up @@ -74,6 +74,7 @@ func newCmdDashboard() *cobra.Command {
webDeployment,
options.port,
webPort,
verbose,
)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize port-forward: %s\n", err)
Expand Down
13 changes: 12 additions & 1 deletion pkg/k8s/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"strings"

v1 "k8s.io/api/core/v1"
Expand All @@ -24,6 +25,7 @@ type PortForward struct {
url *url.URL
localPort int
remotePort int
emitLogs bool
stopCh chan struct{}
readyCh chan struct{}
config *rest.Config
Expand All @@ -36,6 +38,7 @@ type PortForward struct {
func NewPortForward(
configPath, kubeContext, namespace, deployName string,
localPort, remotePort int,
emitLogs bool,
) (*PortForward, error) {
config, err := GetConfig(configPath, kubeContext)
if err != nil {
Expand Down Expand Up @@ -90,6 +93,7 @@ func NewPortForward(
url: req.URL(),
localPort: localPort,
remotePort: remotePort,
emitLogs: emitLogs,
stopCh: make(chan struct{}, 1),
readyCh: make(chan struct{}),
config: config,
Expand All @@ -103,10 +107,17 @@ func (pf *PortForward) Run() error {
return err
}

out := ioutil.Discard
errOut := ioutil.Discard
if pf.emitLogs {
out = os.Stdout
errOut = os.Stderr
}

ports := []string{fmt.Sprintf("%d:%d", pf.localPort, pf.remotePort)}
dialer := spdy.NewDialer(upgrader, &http.Client{Transport: transport}, pf.method, pf.url)

fw, err := portforward.New(dialer, ports, pf.stopCh, pf.readyCh, ioutil.Discard, ioutil.Discard)
fw, err := portforward.New(dialer, ports, pf.stopCh, pf.readyCh, out, errOut)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion testutil/kubernetes_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (h *KubernetesHelper) ParseNamespacedResource(resource string) (string, str
// tests can use for access to the given deployment. Note that the port-forward
// remains running for the duration of the test.
func (h *KubernetesHelper) URLFor(namespace, deployName string, remotePort int) (string, error) {
pf, err := k8s.NewPortForward("", "", namespace, deployName, 0, remotePort)
pf, err := k8s.NewPortForward("", "", namespace, deployName, 0, remotePort, false)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 8e10e3b

Please sign in to comment.