Report namespace and pod name when port-forward fails (#5504)

Subject
Related to issue #5457 

Problem
Linkerd only reports the local port and the remote port whenever port-forwarding fails.
Linkerd could print out namespace and port if port-forwarding fails instead of just at the error state and then force users to collate the port themselves

Solution
Linkerd needs to print the namespace and the pod name.
- [x] Add two new string variables namespace and podName in `struct PortForward`
- [x] assign the values to the variables when a new Instance is being created in `func NewPortForward()`
run() function propagates the errors that occurred while port-forwarding
- [x] Format the error being returned by `ForwardPorts()` from client-go using `fmt.Errorf()` and add `namespace` and `podName` as suffix and return error

The error is being returned by ForwardPorts() from client-go https://github.com/kubernetes/client-go/blob/master/tools/portforward/portforward.go#L188

Fixes #5457 

Signed-off-by: Piyush Singariya <piyushsingariya@gmail.com>
This commit is contained in:
Piyush Singariya 2021-01-12 05:19:27 +05:30 committed by GitHub
parent 898de71098
commit aa20c3e88e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

View File

@ -25,6 +25,8 @@ type PortForward struct {
method string
url *url.URL
host string
namespace string
podName string
localPort int
remotePort int
emitLogs bool
@ -140,6 +142,8 @@ func newPortForward(
method: "POST",
url: req.URL(),
host: host,
namespace: namespace,
podName: podName,
localPort: localPort,
remotePort: remotePort,
emitLogs: emitLogs,
@ -172,7 +176,12 @@ func (pf *PortForward) run() error {
return err
}
return fw.ForwardPorts()
err = fw.ForwardPorts()
if err != nil {
err = fmt.Errorf("%s for %s/%s", err, pf.namespace, pf.podName)
return err
}
return nil
}
// Init creates and runs a port-forward connection.