Skip to content

feat(k8s): devops k8s tunnel keeps the cloudflared forward to k8s.<domain> running - #2567

Merged
dan-petty merged 2 commits into
mainfrom
feat/1641-k8s-tunnel-command
Oct 29, 2026
Merged

dan-petty merged 2 commits into
mainfrom
feat/1641-k8s-tunnel-command

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Off the home network, the tunnel kubeconfig context worked only while cloudflared access tcp ran in a terminal that someone kept open. When the listener stopped, kubectl failed with "connection refused" on the local port, and nothing said that the forward was missing. A second listener failed with "address already in use".

devops k8s tunnel keeps the forward running:

  • start reads the hostname from the new setting k8s.tunnel_host, with no fallback: an unset setting stops it with an error that names the setting. It runs cloudflared access login --quiet https://<host> with the terminal attached, so cloudflared shows its login URL or opens a browser, and stores the token without printing it. Then it starts cloudflared access tcp --hostname <host> --url 127.0.0.1:<port> --logfile <file> in a session of its own, records the process under the data directory and waits until the port accepts connections. A recorded forward that runs is reported, and no second forward starts. --context adds or updates the <cluster>-tunnel cluster and context from the cluster, the user and the CA data of the home context, as k8s/README.md gave them by hand. --dry-run starts nothing.
  • stop signals the forward's process group through terminate_process_group and removes the record.
  • status reports the forward, whether its port accepts connections and whether the API server of the tunnel context answers /version. A 401 or a 403 counts as an answer, because the request reached the API server.

cloudflared does the forwarding and the login. The tunnel uses the lock and the pid-and-start-time liveness check of the port-forward daemon. The process runner gains spawn_detached, which process_fake records and answers with a process the test gives. KubernetesService.is_cluster_reachable and the new api_server_answers share one probe of /version that tells an error status apart from no answer. The port defaults to 16443 (DEFAULT_K8S_TUNNEL_PORT). k8s/README.md gives the command in place of the manual steps.

Closes #1641

Change: openspec/changes/archive/2026-10-28-1641-k8s-tunnel-command/

…main> running

Off the home network, the tunnel kubeconfig context worked only while
`cloudflared access tcp` ran in a terminal that someone kept open. When
the listener stopped, kubectl failed with "connection refused", and
nothing said that the forward was missing.

`devops k8s tunnel start` reads the hostname from the new setting
`k8s.tunnel_host`, runs `cloudflared access login --quiet` with the
terminal attached, then starts `cloudflared access tcp` in a session of
its own, records it under the data directory and waits until its port
accepts connections. A forward that already runs is reported, and no
second one starts. `--context` writes the `<cluster>-tunnel` cluster and
context from the home context. `stop` signals the forward's process
group, and `status` tells a listening port and an answering API server
apart: a 401 or 403 from `/version` counts as an answer.

The process runner gains `spawn_detached`, and the tunnel uses the lock
and the liveness check of the port-forward daemon.
@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence:

  • tests/k8s/test_k8s_tunnel.py: 11 tests. They failed first with ModuleNotFoundError: No module named 'devops_cli.k8s.tunnel', and pass now. They start no cloudflared: process_fake answers the login and records the detached forward, which is a git hash-object --stdin stand-in in its own session; a bound loopback socket opens when the forward "starts".
  • The full uv run devops ci before the rebase: every gate passed except deps (deptry: a direct urllib3 import is a transitive dependency). The fix shares one /version probe between is_cluster_reachable and api_server_answers, with no urllib3 import and no new suppression; devops ci deps passes. The test gate took 6 m 24 s on a shared host (load 12); perf(ci): the startup-import tests start 56 interpreters and take 204 s of the suite's 2,423 s #2369, perf(ci): each test shard collects only its own test files #2371 and perf(ci): measure coverage and branch cost #2373 cover suite speed.
  • After the rebase onto dbfbb65: 329 tests in the k8s, config-declaration, MCP, process, port-forward, service and swallowed-failures files pass; devops docs check and devops openspec check pass.
  • src type: ignore count stays at its ceiling of 51.

Pending a person: from off the home network, run devops config set k8s.tunnel_host k8s.<domain>, devops k8s tunnel start --context, complete the Access login, then kubectl --context <cluster>-tunnel get nodes. Review the diff in tuicr (tuicr -r origin/main..HEAD).

@dan-petty
dan-petty marked this pull request as ready for review October 29, 2026 00:06
@dan-petty
dan-petty merged commit f9493fa into main Oct 29, 2026
17 checks passed
@dan-petty
dan-petty deleted the feat/1641-k8s-tunnel-command branch October 29, 2026 00:06
dan-petty pushed a commit that referenced this pull request Oct 29, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.12.0](v0.11.3...v0.12.0)
(2026-10-29)


### Features

* **ai:** constrain structured replies on the openai and claude
providers ([#2550](#2550))
([4f7390a](4f7390a))
* **argo:** retire the Helm release records of the charts that Argo CD
renders ([#2568](#2568))
([cabfcd4](cabfcd4))
* **k8s:** devops k8s tunnel keeps the cloudflared forward to
k8s.&lt;domain&gt; running
([#2567](#2567))
([f9493fa](f9493fa)),
closes [#1641](#1641)
* **monitoring:** alert when the otel collector fails to export spans,
metric points or log records
([#2565](#2565))
([4fc8ff7](4fc8ff7))
* **telemetry:** the roadmap Service counts its GitHub writes, budget
holds, Firecrawl searches and own deliveries, and caps refine's comments
on one item
([#2556](#2556))
([9819877](9819877)),
closes [#2475](#2475)


### Bug Fixes

* **git:** report a worktree that a run in parallel removed as removed,
not a failed reclaim
([#2557](#2557))
([a556984](a556984)),
closes [#2408](#2408)
* **k8s:** the devops perimeter opens only the collector's OTLP/HTTP
port, 4318
([#2549](#2549))
([d156ce7](d156ce7))
* **sandbox:** devops sandbox logs reads each line with its stream from
a real engine
([#2546](#2546))
([e7216d5](e7216d5)),
closes [#2520](#2520)
* **service:** the webhook route refuses an unsigned or oversized
delivery before it reads the body, and a rate limit guards it
([#2553](#2553))
([40efcd4](40efcd4)),
closes [#2476](#2476)


### Performance Improvements

* **ai:** price a request with one load of the settings
([#2555](#2555))
([5d86538](5d86538)),
closes [#1420](#1420)


### Code Refactoring

* **config:** a default that backs a settings field is read only through
the settings
([#2561](#2561))
([0702d13](0702d13))
* **exceptions:** each exception class declares its error_code and
exit_code ([#2558](#2558))
([410dece](410dece))
* **review:** render the review report from one input, outside the
orchestrator
([#2563](#2563))
([9e73e6d](9e73e6d)),
closes [#1008](#1008)
* **security:** src has no unreviewed Bandit findings, and the gate
scans src at low severity
([#2560](#2560))
([45261dd](45261dd)),
closes [#1538](#1538)
* **security:** the scanners stop looking for mocks, and their tests run
on the scanner fake
([#2551](#2551))
([2b7f37a](2b7f37a))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(k8s): devops k8s tunnel keeps the cloudflared forward to k8s.<domain> running, so the tunnel context works off the home network

1 participant