Skip to content

Migrate kubectl exec to WebSockets from SPDY#758

Open
andyvandy wants to merge 2 commits into
skevetter:mainfrom
andyvandy:main
Open

Migrate kubectl exec to WebSockets from SPDY#758
andyvandy wants to merge 2 commits into
skevetter:mainfrom
andyvandy:main

Conversation

@andyvandy
Copy link
Copy Markdown

@andyvandy andyvandy commented May 20, 2026

( clone of PR loft-sh#1980 )

I've added websocket support since I want to setup a capsule kube api proxy which was dropping connections due to lack of SPDY support.

Per KEP-4006, I prioritize trying WebSockets first given Websockets have been the default for 4 versions now and will be the standard going forward. I used NewFallbackExecutor as suggested in the KEP to avoid breaking existing use cases.

This follows the implementation used by kubectl: https://github.com/kubernetes/kubectl/blob/8144b746a47f142759a073a46f581de92b1886aa/pkg/cmd/exec/exec.go#L146-L166

I've built this locally and have been using it successfully for myself and a few others. Disclosure: this fix was found with the assistance of claude/copilot.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Kubernetes command execution reliability by preferring a modern connection method and adding smarter fallback selection when upgrade or proxy errors occur, resulting in more stable and compatible remote command sessions across diverse cluster environments.

Review Change Stack

Per [KEP-4006](https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/4006-transition-spdy-to-websockets), prioritize trying WebSockets first
given it has been the default for 4 versions now and will be the standard going forward.
Use a NewFallbackExecutor as is suggested in the KEP to avoid breaking existing use cases.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19752af9-df44-4fc4-817f-f3415cf2c727

📥 Commits

Reviewing files that changed from the base of the PR and between 4add125 and 2b0cedf.

📒 Files selected for processing (1)
  • pkg/driver/kubernetes/client.go

📝 Walkthrough

Walkthrough

Client.Exec now attempts a WebSocket-based Kubernetes exec first and constructs an SPDY executor as a fallback, wrapped with remotecommand.NewFallbackExecutor that uses httpstream.IsUpgradeFailure and httpstream.IsHTTPSProxyError to decide when to fall back.

Changes

Kubernetes WebSocket Executor Fallback

Layer / File(s) Summary
WebSocket-first exec with SPDY fallback
pkg/driver/kubernetes/client.go
Adds the httpstream import and changes Client.Exec to build a WebSocket executor as primary and an SPDY executor as fallback, wrapped by remotecommand.NewFallbackExecutor and using httpstream.IsUpgradeFailure / httpstream.IsHTTPSProxyError to trigger the fallback.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Migrate kubectl exec to WebSockets from SPDY' directly and accurately describes the main technical change in the changeset—updating the Kubernetes client to use WebSocket-based execution instead of SPDY.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/driver/kubernetes/client.go`:
- Line 128: The fallback predicate passed to remotecommand.NewFallbackExecutor
currently only uses httpstream.IsUpgradeFailure; update the call in the
remotecommand.NewFallbackExecutor invocation (the websocketExec, spdyExec
creation site) to use a combined predicate that checks both
httpstream.IsUpgradeFailure and httpstream.IsHTTPSProxyError (i.e., call
NewFallbackExecutor with a predicate that returns true if either
IsUpgradeFailure or IsHTTPSProxyError matches) so HTTPS-proxy dial failures will
trigger the SPDY fallback just like kubectl.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 635de3ff-cde9-4e2d-a7ba-7614d78d4fa7

📥 Commits

Reviewing files that changed from the base of the PR and between 95d2230 and 4add125.

📒 Files selected for processing (1)
  • pkg/driver/kubernetes/client.go

Comment thread pkg/driver/kubernetes/client.go Outdated
pick up the same additional error handling that was introduced by this commit to the kubectl client. kubernetes/kubectl@2c588bc

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@skevetter
Copy link
Copy Markdown
Owner

Happy to get this merged in once the failing jobs are fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants