Skip to content

Return error channel from PortForward#12512

Open
caseydavenport wants to merge 1 commit intoprojectcalico:masterfrom
caseydavenport:casey-portforward-errch
Open

Return error channel from PortForward#12512
caseydavenport wants to merge 1 commit intoprojectcalico:masterfrom
caseydavenport:casey-portforward-errch

Conversation

@caseydavenport
Copy link
Copy Markdown
Member

The port-forward goroutine in the e2e test helpers previously swallowed errors silently - if the underlying kubectl port-forward process died (pod restart, network blip, etc.), callers had no way to know. Tests would just get connection refused on the next poll and time out with misleading errors.

PortForward now returns a <-chan error alongside 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.

None

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).
@caseydavenport caseydavenport requested a review from a team as a code owner April 16, 2026 20:43
Copilot AI review requested due to automatic review settings April 16, 2026 20:43
@caseydavenport caseydavenport added docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact labels Apr 16, 2026
@marvin-tigera marvin-tigera added this to the Calico v3.33.0 milestone Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.PortForward to return an additional <-chan error that yields the Exec() 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.

Comment thread e2e/pkg/utils/kubectl.go
// 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) {
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required Docs not required for this change release-note-not-required Change has no user-facing impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants