Skip to content

fix(k8s): prevent deploy-stack and port-forward from unconditionally overwriting config with localhost (#637) - #638

Merged
dan-petty merged 1 commit into
release/v0.2.23from
fix/637-k8s-deploy-stack-no-config-overwrite
Sep 27, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.23from
fix/637-k8s-deploy-stack-no-config-overwrite

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

Resolves #637 by preventing devops k8s deploy-stack and devops k8s port-forward from unconditionally mutating configuration files and starting background port-forwarding daemons by default.

Key Changes

  • Deploy Stack Lifecycle:
    • Added --port-forward / --no-port-forward (default: False) and --configure-urls / --no-configure-urls (default: False) to devops k8s deploy-stack.
    • Decomposed deploy_stack into discrete helper functions (_deploy_helm_repos, _apply_manifest_files, _install_single_release, _post_deploy_networking, _post_deploy_credentials) reducing cyclomatic complexity to $\le 5$.
  • Port Forwarding:
    • Added --update-config / --no-update-config (default: False) to devops k8s port-forward.
    • Decomposed port_forward into _build_port_forward_details, _collect_port_forward_services, and _launch_port_forwards.
  • URL Resolution & Config Protection:
    • Inverted priority in _resolve_accessible_url: test detected_url reachability first; only fallback to localhost if detected_url is unreachable or unconfigured.
    • Added _should_update_url and _update_ollama_urls to ensure existing custom endpoints (such as remote Ollama inference hosts) are never overwritten by loopback addresses.
    • Fixed telemetry endpoint lookup on settings.telemetry.
  • Documentation & Tests:
    • Updated CLI command reference documentation (README.md, docs/CLI_REFERENCE.md, docs/commands/k8s.md).
    • Added 6 dedicated unit tests in tests/test_k8s_networking.py covering flag defaults, priority resolution, Ollama URL preservation, and service spec mapping.
    • Updated tests/test_k8s.py for reachable endpoint preference.

Verification

  • Local Gated CI Suite (uv run devops ci): Passed with 100% compliance across all 10 quality gates.
  • Unit Tests: tests/test_k8s_networking.py and tests/test_k8s.py passed (70 tests total).
  • Cyclomatic Complexity: All modified functions verified $M \le 10$ and nesting depth $\le 5$.

Closes #637

…overwriting config with localhost (#637)

Problem:
`devops k8s deploy-stack` unconditionally launched background port-forward
daemons and invoked `configure-urls`, overwriting custom endpoints in
`config.yaml` with loopback (`http://localhost:...`) addresses. Furthermore,
`_resolve_accessible_url` probed preferred localhost ports before checking
the actual detected cluster URL, silently replacing reachable cluster
endpoints whenever localhost ports were occupied. Additionally,
`devops k8s port-forward` automatically mutated configuration files.

Solution:
- Make port-forwarding and configuration updates opt-in for `deploy-stack`
  via `--port-forward / --no-port-forward` and `--configure-urls / --no-configure-urls`
  (both defaulting to `False`).
- Make configuration updates opt-in for `port-forward` via `--update-config /
  --no-update-config` (defaulting to `False`).
- Invert resolution priority in `_resolve_accessible_url`: test `detected_url`
  reachability first; only fallback to localhost if `detected_url` is unreachable
  or unconfigured.
- Protect existing custom remote endpoints (including `settings.ai.ollama_urls`)
  from being overwritten by loopback addresses in `_should_update_url` and
  `_update_ollama_urls`.
- Decompose `deploy_stack` and `port_forward` to satisfy cyclomatic complexity
  and nesting limits.
- Update CLI reference documentation and add comprehensive unit tests.

Verification:
- `uv run pytest tests/test_k8s_networking.py tests/test_k8s.py`: 70 tests passed.
- `uv run devops ci`: All 10 quality gates passed (coverage >= 90%, zero errors).

Closes #637
@dan-petty dan-petty added this to the v0.2.23 milestone Sep 27, 2026
@dan-petty dan-petty added type/bug Type bug: the code does not do what it must scope/k8s Kubernetes commands, Helm charts, pods, services, and policies priority/p1-high Priority P1: high-impact work for the next planned milestone labels Sep 27, 2026
@dan-petty
dan-petty marked this pull request as ready for review September 27, 2026 08:26
@dan-petty
dan-petty merged commit dcd56b2 into release/v0.2.23 Sep 27, 2026
8 checks passed
@dan-petty
dan-petty deleted the fix/637-k8s-deploy-stack-no-config-overwrite branch September 27, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1-high Priority P1: high-impact work for the next planned milestone scope/k8s Kubernetes commands, Helm charts, pods, services, and policies type/bug Type bug: the code does not do what it must

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant