Return error channel from PortForward#12512
Return error channel from PortForward#12512caseydavenport wants to merge 1 commit intoprojectcalico:masterfrom
Conversation
The port-forward goroutine previously swallowed errors silently. Return a channel so callers can detect when the port-forward process exits and react (e.g., restart it or fail fast with a clear message).
There was a problem hiding this comment.
Pull request overview
This PR updates the e2e Kubectl helper’s port-forward implementation so callers can observe when the underlying kubectl port-forward process exits (and why), instead of errors being silently swallowed.
Changes:
- Change
Kubectl.PortForwardto return an additional<-chan errorthat yields theExec()result when port-forward terminates. - Update staged policy e2e test to accommodate the new return value (ignore the channel for now).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| e2e/pkg/utils/kubectl.go | Extends PortForward to return an error channel and propagates the kubectl command exit result via that channel. |
| e2e/pkg/tests/policy/staged_policy.go | Updates the call site to the new PortForward signature by ignoring the new error channel. |
| // local port to avoid conflicts when tests run in parallel. It returns the local port | ||
| // and a channel that receives an error (or nil) when the port-forward process exits. | ||
| // Callers can select on the channel to detect unexpected port-forward termination. | ||
| func (k *Kubectl) PortForward(ns, pod, remotePort, user string, timeOut chan time.Time) (int, <-chan error, error) { |
There was a problem hiding this comment.
timeOut is declared as a bidirectional chan time.Time, but PortForward never sends on it (it only passes it to WithTimeout). Keeping it bidirectional unnecessarily restricts callers (e.g., you can’t pass <-chan time.Time values like time.After(...) directly) and weakens the API contract. Consider changing the parameter type to <-chan time.Time (and adjusting the call sites accordingly).
| func (k *Kubectl) PortForward(ns, pod, remotePort, user string, timeOut chan time.Time) (int, <-chan error, error) { | |
| func (k *Kubectl) PortForward(ns, pod, remotePort, user string, timeOut <-chan time.Time) (int, <-chan error, error) { |
The port-forward goroutine in the e2e test helpers previously swallowed errors silently - if the underlying
kubectl port-forwardprocess died (pod restart, network blip, etc.), callers had no way to know. Tests would just getconnection refusedon the next poll and time out with misleading errors.PortForwardnow returns a<-chan erroralongside the port. Callers that don't care can_it (like the whisker test does today), but callers that need resilience can select on it to detect failures and restart.This is the OSS half of a fix for a flaky Linseed port-forward in the enterprise e2e suite. The enterprise side adds a supervisor loop in the Linseed
PortForward()that watches this channel and auto-restarts.