Repository navigation
Description
Context & Rationale
Since ed6428f (#676), cloudflare tunnel sync reads the current tunnel config and merges into it. It still loses settings in four cases, all reproduced on release/v0.2.24:
- Per-route settings are dropped. Routes it keeps lose their own
originRequestsettings, such asnoTLSVerifyandhttpHostHeader, because the route model keeps only service, hostname and path (cloudflare/client.py:84-102,:507-514). - The catch-all is replaced. A custom catch-all becomes
http_status:404(cloudflare/client.py:148). - A failed read wipes the config. If reading the current config fails, the error is swallowed (
cloudflare/client.py:609-610) and sync falls back to replacing the whole tunnel config. That wipeswarp-routingand every route it didn't generate. --dry-runhides removals. It shows additions and preserved routes but no removals or replaced services (commands/cloudflare.py:502-525,:590-598). After a read error it silently shows additions only.
test_cloudflare_client_sync_tunnel_routes_preserves_rules checks only the mocked return value, so it passes on the old replace-all code.
URL setup has the same overwrite problem. Gateway discovery still matches the bare substrings "ai" and "llm-gateway" instead of CONST_K8S_INGRESS_SERVICE_PATTERNS (config/constants.py:2176, unused). As a result, a domain containing "ai" picks whichever ingress comes first. _should_update_url (commands/k8s/networking.py:278) also lets a discovered FQDN overwrite a custom remote ai.gateway_url.
The deleted-tunnel filter and the valkey host and port guard from #666 work, but have no tests. Found while checking the #666 fix.
Scope & Deliverables
- Deliverable:
- Sync keeps every field of the rules it preserves and keeps a custom catch-all.
- When the current config can't be read, sync stops with an error instead of replacing it.
--dry-runshows additions, removals and replaced services from the merged result.- Gateway discovery uses the service patterns with exact service and namespace matches, and only unset or local URLs are updated.
- Tests assert the payload sync sends, including
originRequest, the catch-all andwarp-routing. They also cover the read failure, deleted tunnels and the valkey guard.
- Constraint: sync never sends a config that drops a route it didn't generate.
Strategic Alignment
- Milestone: Backlog (no release)
- Design: none
- Depends on: none
Generated by Claude Code
Update 2026-10-08: refinement
The defects hold; #897 landed. The dry-run deliverable conflicts with #412: --dry-run makes no request and prints the GET and PUT it would send; a removal preview needs a separate reading mode, out of scope.
- The PUT body keeps
originRequest, a custom catch-all andwarp-routing. - A failed GET sends no PUT;
--dry-runmakes no request. - A remote
ai.gateway_urlofhttps://example.com/v1is kept.
Proposed design
Problem statement
Cloudflare tunnel sync and Kubernetes URL setup overwrite settings they should preserve. Tunnel sync drops per-route originRequest fields (noTLSVerify, httpHostHeader), replaces a custom catch-all with http_status:404, and when the GET of the current config fails it silently falls back to a full replace that wipes warp-routing and user-added routes. URL setup matches ingress services by bare substrings ("ai", "llm-gateway") instead of the defined CONST_K8S_INGRESS_SERVICE_PATTERNS, and _should_update_url lets a discovered FQDN overwrite a user-set remote ai.gateway_url. The fix must make sync preserve every field of routes it keeps, abort on a failed read, and make URL setup respect existing remote values.
Acceptance criteria
- Criterion 1: The PUT body sent by tunnel sync preserves originRequest settings (noTLSVerify, httpHostHeader) on every route it keeps, preserves a custom catch-all rule, and preserves warp-routing.
Verification: A unit test asserts the exact PUT payload: for a pre-existing route with originRequest.noTLSVerify=true and originRequest.httpHostHeader set, the payload contains those fields; a custom catch-all (e.g. service pointing to a custom backend) is present unchanged; warp-routing block is present unchanged. - Criterion 2: When the GET of the current tunnel config fails, sync raises an error and sends no PUT request.
Verification: A unit test mocks the GET to raise an exception and asserts that the PUT method is never called and that the command exits with a non-zero status and an error message. - Criterion 3: --dry-run makes no network request (neither GET nor PUT) and prints the GET and PUT it would send.
Verification: A unit test mocks the HTTP client, runs sync with --dry-run, and asserts zero calls to the HTTP client while stdout contains the serialized GET and PUT payloads. - Criterion 4: Gateway discovery matches ingress services using CONST_K8S_INGRESS_SERVICE_PATTERNS with exact service-name and namespace matches, not bare substring matching.
Verification: A unit test provides two ingresses, one with service name containing 'ai' as a substring but not matching the pattern, and one matching the pattern exactly; only the latter is selected. - Criterion 5: _should_update_url does not overwrite a remote custom ai.gateway_url (e.g.
https://example.com/v1) with a discovered FQDN.
Verification: A unit test sets ai.gateway_url tohttps://example.com/v1, runs URL setup with a discovered FQDN, and asserts the setting remainshttps://example.com/v1. - Criterion 6: Tests cover the deleted-tunnel filter and the valkey host-and-port guard from fix(k8s): cloudflare sync and url configuration overwrite existing settings #666.
Verification: Unit tests assert that a tunnel whose name matches a deleted-tunnel pattern is excluded from the sync payload, and that a valkey URL with a non-default port is not overwritten.
Key questions
- What should happen when the GET of the current tunnel config fails?: Sync stops with an error and sends no PUT; it must not fall back to replacing the whole tunnel config. (proposed)
- Should --dry-run show removals and replaced services?: No. Per the 2026-10-08 update, --dry-run makes no request and prints the GET and PUT it would send; a removal preview needs a separate reading mode and is out of scope (conflicts with feat(cli): reachable
--dry-runpreviews for delegated commands #412). (proposed) - How should gateway discovery match ingress services?: Use CONST_K8S_INGRESS_SERVICE_PATTERNS with exact service-name and namespace matches instead of bare substring matching on 'ai' and 'llm-gateway'. (proposed) [sources: src/devops_cli/config/constants.py:2776]
- When should _should_update_url allow overwriting an existing URL?: Only when the existing URL is unset or is a local (cluster-internal) address. A remote custom URL such as
https://example.com/v1must be kept. (proposed) [sources: src/devops_cli/commands/k8s/networking.py:285]
Open questions
- What fields must the route model preserve when keeping an existing route? (missing verified source)
- Does the existing test test_cloudflare_client_sync_tunnel_routes_preserves_rules adequately verify the fix? (missing verified source)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
[end-marker]
Proposed design
Problem statement
Cloudflare tunnel sync and Kubernetes URL setup overwrite settings they should preserve. Tunnel sync drops per-route originRequest fields (noTLSVerify, httpHostHeader), replaces a custom catch-all with http_status:404, and when the GET of the current config fails it silently falls back to a full replace that wipes warp-routing and user-added routes. URL setup matches ingress services by bare substrings ("ai", "llm-gateway") instead of the defined CONST_K8S_INGRESS_SERVICE_PATTERNS, and _should_update_url lets a discovered FQDN overwrite a user-set remote ai.gateway_url. The fix must make sync preserve every field of routes it keeps, abort on a failed read, and make URL setup respect existing remote values.
Acceptance criteria
- Criterion 1: The PUT body sent by tunnel sync preserves originRequest settings (noTLSVerify, httpHostHeader) on every route it keeps, preserves a custom catch-all rule, and preserves warp-routing.
Verification: A unit test asserts the exact PUT payload: for a pre-existing route with originRequest.noTLSVerify=true and originRequest.httpHostHeader set, the payload contains those fields; a custom catch-all (e.g. service pointing to a custom backend) is present unchanged; warp-routing block is present unchanged. - Criterion 2: When the GET of the current tunnel config fails, sync raises an error and sends no PUT request.
Verification: A unit test mocks the GET to raise an exception and asserts that the PUT method is never called and that the command exits with a non-zero status and an error message. - Criterion 3: --dry-run makes no network request (neither GET nor PUT) and prints the GET and PUT it would send.
Verification: A unit test mocks the HTTP client, runs sync with --dry-run, and asserts zero calls to the HTTP client while stdout contains the serialized GET and PUT payloads. - Criterion 4: Gateway discovery matches ingress services using CONST_K8S_INGRESS_SERVICE_PATTERNS with exact service-name and namespace matches, not bare substring matching.
Verification: A unit test provides two ingresses, one with service name containing 'ai' as a substring but not matching the pattern, and one matching the pattern exactly; only the latter is selected. - Criterion 5: _should_update_url does not overwrite a remote custom ai.gateway_url (e.g.
https://example.com/v1) with a discovered FQDN.
Verification: A unit test sets ai.gateway_url tohttps://example.com/v1, runs URL setup with a discovered FQDN, and asserts the setting remainshttps://example.com/v1. - Criterion 6: Tests cover the deleted-tunnel filter and the valkey host-and-port guard from fix(k8s): cloudflare sync and url configuration overwrite existing settings #666.
Verification: Unit tests assert that a tunnel whose name matches a deleted-tunnel pattern is excluded from the sync payload, and that a valkey URL with a non-default port is not overwritten.
Key questions
- What should happen when the GET of the current tunnel config fails?: Sync stops with an error and sends no PUT; it must not fall back to replacing the whole tunnel config. (proposed) [sources: src/devops_cli/cloudflare/client.py:609]
- Should --dry-run show removals and replaced services?: No. Per the 2026-10-08 update, --dry-run makes no request and prints the GET and PUT it would send; a removal preview needs a separate reading mode and is out of scope (conflicts with feat(cli): reachable
--dry-runpreviews for delegated commands #412). (proposed) [sources: src/devops_cli/commands/cloudflare.py:502] - How should gateway discovery match ingress services?: Use CONST_K8S_INGRESS_SERVICE_PATTERNS with exact service-name and namespace matches instead of bare substring matching on 'ai' and 'llm-gateway'. (proposed) [sources: src/devops_cli/config/constants.py:2786]
- When should _should_update_url allow overwriting an existing URL?: Only when the existing URL is unset or is a local (cluster-internal) address. A remote custom URL such as
https://example.com/v1must be kept. (proposed) [sources: src/devops_cli/commands/k8s/networking.py:285]
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
[end-marker]
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
dan-petty commentedon Oct 1, 2026
Placement (2026-10-01): v0.2.28. Value High, Effort Medium. Not Ready yet.
Checked against
release/v0.2.24at d38251e. What stops it being Ready:dan-petty commentedon Oct 3, 2026
Consolidation note (2026-10-03): #818 is merged into #1104, which rewrites the Prometheus lookups in
commands/k8s/networking.py. Whichever of this item and #1104 lands first moves configure-urls onto exact (key, namespace, service) entries fromCONST_K8S_INGRESS_SERVICE_PATTERNS(config/constants.py:2974, unread today), and the other reuses that table. This item's scope and v0.2.28 placement are unchanged.Lines cited at dcafadf.
Other items rewrite the lines this item's URL-setup work touches in
commands/k8s/networking.py. They land on that file in this order: #897 (v0.2.27), this item, #887, then #1112, #1111 and #1113.Local or remote URL
_should_update_url(:280-296). Today that function decides with two hand-rolled checks:CONST_LOCAL_HOSTNAMEShost set (:296);_is_fqdn_url(:255-277, called at:292), which tests the same set andCONST_LOCAL_DOMAIN_SUFFIXESwithendswith(:267-269).:267,:296) with one loopback predicate:ipaddressis_loopback, plusdns.nameequality forlocalhost.ipaddress.ip_address. Add no host list, suffix tuple orendswithtest, and do not extend_is_fqdn_url. If fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897 has not landed, keep the existingCONST_LOCAL_HOSTNAMEStest as it is, so fix(security): egress guards refuse cloud metadata in every numeric, NAT64 and provider form, classified by ipaddress and one maintained library #897 swaps it in one place.lan,internal,localandcluster.local, which the suffix list lets a NodePort URL replace today._is_fqdn_urlwithout a caller, delete it andtest_is_fqdn_url(tests/test_k8s_networking.py:239-252) rather than leave dead code. fix(security): local names come from the public suffix list, and domains match on DNS labels, not string suffixes #887 then only adds its_should_update_urlrows to the tests.Valkey guard
_should_update_valkey(:419-444) calls_should_update_urlat:432, so this item's rule carries over to it.CONST_LOCAL_HOSTNAMEScomparison (:440-441, imported at:423) with its loopback predicate, and adds the first_should_update_valkeytest: withvalkey.urlunset, an existing remotevalkey.hostofexample.comis kept when the detected host is127.0.0.2. That test covers this item's "valkey guard" criterion; add guard tests only for behaviour this item changes.valkey.hostandvalkey.portwith onevalkey.url, sends it through_apply_service_url(:299-312), and deletes_should_update_valkeyand the host and port writes (:486-490). Its tests keep a remotevalkey.urlofvalkey://[2001:db8::5]:6379,valkey://[::ffff:192.0.2.5]:6379orvalkey://example.com:6379when bootstrap detects a localhost URL.split(":")[0]at:436reads a configuredvalkey.hostof::ffff:192.0.2.5as an empty host, so a discoveredlocalhostendpoint overwrites the remote setting (measured offline). Do not patch that line with another string check; fix(valkey): one validated URL names every Valkey endpoint, valkey-py dials an address that one check vetted, and the unused cache layer goes #1113 removes it.dan-petty-bot commentedon Oct 6, 2026
Moved to the backlog: it was New, not Ready, when v0.2.28 started. (devops roadmap reprioritize)
dan-petty-bot commentedon Oct 10, 2026
Status set to Ready at 5c5df79 (see proposed design in issue body).
fix(k8s): tunnel sync and url setup preserve existing routes, catch-a…
dan-petty commentedon Oct 11, 2026
Merged
feat(release): v0.2.34 (#1566)