[WIP] Port forwarding using client-go#1538
Conversation
evankanderson
left a comment
There was a problem hiding this comment.
A few notes; I'm assuming that overall we expect this to be somewhat faster with better cleanup because we aren't managing processes?
| func PortForward(logf logging.FormatLogger, config *rest.Config, clientSet *kubernetes.Clientset, pod *v1.Pod, localPort, remotePort int) (chan struct{}, error) { | ||
| req := clientSet.RESTClient().Post().Resource("pods").Namespace(pod.Namespace).Name(pod.Name).SubResource("portforward") | ||
| portForwardUrl := req.URL() | ||
| if !strings.HasPrefix(portForwardUrl.Path, "/api/v1") { |
There was a problem hiding this comment.
??? This seems like it deserves a comment at least.
| if err != nil { | ||
| return 0, fmt.Errorf("failed to port forward: %w", err) | ||
| // To close the port forwarding, just close the channel | ||
| func PortForward(logf logging.FormatLogger, config *rest.Config, clientSet *kubernetes.Clientset, pod *v1.Pod, localPort, remotePort int) (chan struct{}, error) { |
There was a problem hiding this comment.
The previous version took a *v1.PodList". (I also wonder if passing the logger, clientSet, etc would be more cleanly done via injection/context.Context.)
There was a problem hiding this comment.
That really didn't made sense, because you port forward one pod at the time. If you want to port forward more pods at the time, i think it's better the callee figures it out managing the various close ch
| "sync" | ||
| ) | ||
|
|
||
| type loggerWriter struct { |
There was a problem hiding this comment.
Should these be "prefixedWriter" or "prefixWriter"?
There was a problem hiding this comment.
My idea to name it loggerWriter is to clarify that you build this writer from a logger function
| c := exec.Command(parts[0], parts[1:]...) // #nosec | ||
| if err := c.Start(); err != nil { | ||
| return nil, fmt.Errorf("%s command failed: %w", cmd, err) | ||
| transport, upgrader, err := spdy.RoundTripperFor(config) |
There was a problem hiding this comment.
Wow, this really is SPDY: kubernetes/kubernetes#89163
There was a problem hiding this comment.
yeah :) i took that code straight from kubectl
6b75fe2 to
9ec82b9
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: slinkydeveloper The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
That's the point of this change plus we have the logging |
|
The following is the coverage report on the affected files.
|
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
fc14798 to
9472b73
Compare
|
@slinkydeveloper: PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
This Pull Request is stale because it has been open for 90 days with |
Removed code to perform port forwarding using an external process and replaced with code to perform port forwarding directly with client-go, included with proper shutdown and logging
Fixes #1536