From de2b9aa19fd3144af09a1f9adf3f58ac4b4dc7e5 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Sun, 25 Oct 2026 20:29:21 +0000 Subject: [PATCH] fix(cli): drop devcontainer k8s auto-deploy for printed deploy-stack command Closes #1368 Remove Kubernetes stack auto-deployment from devcontainer startup. Subprocess isolation drops D-Bus session bus keys, which blocks keyring access. Remove the --deploy and --no-deploy options, _auto_deploy_k8s_stack, and DEVOPS_K8S_AUTO_DEPLOY. Print the devops k8s deploy-stack command with the minikube context after cluster startup. Fail-to-pass check: devops ci fail-to-pass --base origin/main passed (4 failed and 103 passed in tests/test_devcontainer.py, tests/test_docs_source_argv_collector.py). --- .devcontainer/devcontainer.json | 1 - README.md | 2 +- docs/CLI_REFERENCE.md | 3 +- docs/DEVCONTAINER_USAGE.md | 2 +- docs/commands/devcontainer.md | 3 +- .../.openspec.yaml | 2 + .../design.md | 19 +++ .../proposal.md | 51 ++++++++ .../specs/k8s-bootstrap/spec.md | 10 ++ .../tasks.md | 22 ++++ openspec/specs/k8s-bootstrap/spec.md | 7 ++ src/devops_cli/commands/devcontainer.py | 56 +++------ src/devops_cli/config/constants.py | 2 + src/devops_cli/lang/en/help.py | 5 +- src/devops_cli/lang/en/messages.py | 5 +- src/devops_cli/templates/devcontainer.json.j2 | 1 - tests/test_devcontainer.py | 109 ++++++++++-------- tests/test_docs_source_argv_collector.py | 9 +- 18 files changed, 202 insertions(+), 107 deletions(-) create mode 100644 openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/.openspec.yaml create mode 100644 openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/design.md create mode 100644 openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/proposal.md create mode 100644 openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/specs/k8s-bootstrap/spec.md create mode 100644 openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/tasks.md diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5d7fd64761..2f7e474b17 100755 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -43,7 +43,6 @@ ], "containerEnv": { "DEVOPS_CLI_CONFIG": "${containerWorkspaceFolder}/config.yaml", - "DEVOPS_K8S_AUTO_DEPLOY": "true", "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus", "GIT_CONFIG_COUNT": "4", "GIT_CONFIG_KEY_0": "credential.https://githubproxy.fjygbaifeng.eu.org.helper", diff --git a/README.md b/README.md index dce339a292..b91260a3db 100644 --- a/README.md +++ b/README.md @@ -180,7 +180,7 @@ The roadmap lives on GitHub: the issues are its items, the [project board](https | | `devops devcontainer post-create [OPTIONS]` | Execute DevContainer post-create setup tasks (history, shell completions, config prep). | | | `devops devcontainer post-start [OPTIONS]` | Execute DevContainer post-start tasks (SSH keys, git defaults, kubeconfig, MCP sync). | | | `devops devcontainer run-lifecycle [OPTIONS]` | Run specified DevContainer lifecycle hook tasks natively in Python. | -| | `devops devcontainer bootstrap-k8s [OPTIONS]` | Execute Minikube cluster startup and Kubernetes stack deployment in the background. | +| | `devops devcontainer bootstrap-k8s [OPTIONS]` | Execute Minikube cluster startup in the background. | | **workspace** | `devops workspace add [OPTIONS] ` | Add a folder to the VS Code workspace file. | | | `devops workspace remove [OPTIONS] ` | Remove a folder from the VS Code workspace file. | | | `devops workspace generate [OPTIONS]` | Regenerate the workspace file from all repos in the repos directory. | diff --git a/docs/CLI_REFERENCE.md b/docs/CLI_REFERENCE.md index 8979e6b5de..2e60137e4b 100644 --- a/docs/CLI_REFERENCE.md +++ b/docs/CLI_REFERENCE.md @@ -518,7 +518,7 @@ devops devcontainer run-lifecycle [OPTIONS] ### `devops devcontainer bootstrap-k8s` -**Execute Minikube cluster startup and Kubernetes stack deployment in the background.** +**Execute Minikube cluster startup in the background.** ```bash devops devcontainer bootstrap-k8s [OPTIONS] @@ -530,7 +530,6 @@ devops devcontainer bootstrap-k8s [OPTIONS] |---|---|---|---| | `--workspace`, `-w` | `path` | `.` | Workspace root directory path. | | `--stack`, `-s` | `string` | `infra` | Kubernetes stack to deploy (e.g. infra, llm, monitoring, all). | -| `--deploy` / `--no-deploy` | `boolean` | `True` | Auto-deploy Kubernetes stack after cluster startup. | | `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | --- diff --git a/docs/DEVCONTAINER_USAGE.md b/docs/DEVCONTAINER_USAGE.md index b63fd0321f..a5a30ec5b0 100644 --- a/docs/DEVCONTAINER_USAGE.md +++ b/docs/DEVCONTAINER_USAGE.md @@ -332,7 +332,7 @@ Containers scaffolded by `devops devcontainer init` run Debian's `gnome-keyring` ``` `devops devcontainer post-start` and `unlock-keyring` both warn about any host that still has a plaintext token, and print this command for it. - **Git over HTTPS**: `containerEnv` routes `github.com` and `gist.github.com` credentials through `gh auth git-credential`, so git uses the same keyring-backed token as `gh`. These `GIT_CONFIG_*` entries are read after every config file, so they override the helper VS Code adds to forward credentials from the host. While the keyring is locked, `git fetch` over HTTPS fails instead of quietly using the host's credentials. Other hosts are unchanged. -- **`devops` secrets**: `devops config` refuses to store a secret while the keyring is locked, and names `unlock-keyring` in the error. `devops k8s push-secrets`, and the `deploy-stack` that the post-start auto-deploy (`DEVOPS_K8S_AUTO_DEPLOY`) runs, stop before applying anything while it is locked; unlock it, then run `devops k8s deploy-stack --stack ` again. It also refuses keyring setups that could fall back to a plaintext backend. +- **`devops` secrets**: `devops config` refuses to store a secret while the keyring is locked, and names `unlock-keyring` in the error. `devops k8s push-secrets` and `devops k8s deploy-stack` stop before applying anything while it is locked; unlock it, then run `devops k8s deploy-stack --stack --context minikube`. It also refuses keyring setups that could fall back to a plaintext backend. > [!WARNING] > `gh` still falls back to a plaintext `hosts.yml` token if you log in while the keyring is locked (cli/cli#10108). Unlock first. post-start flags the fallback on the next container start. diff --git a/docs/commands/devcontainer.md b/docs/commands/devcontainer.md index 48d3e24cd1..214cca6625 100644 --- a/docs/commands/devcontainer.md +++ b/docs/commands/devcontainer.md @@ -156,7 +156,7 @@ devops devcontainer run-lifecycle [OPTIONS] ## `devops devcontainer bootstrap-k8s` -**Execute Minikube cluster startup and Kubernetes stack deployment in the background.** +**Execute Minikube cluster startup in the background.** ```bash devops devcontainer bootstrap-k8s [OPTIONS] @@ -168,7 +168,6 @@ devops devcontainer bootstrap-k8s [OPTIONS] |---|---|---|---| | `--workspace`, `-w` | `path` | `.` | Workspace root directory path. | | `--stack`, `-s` | `string` | `infra` | Kubernetes stack to deploy (e.g. infra, llm, monitoring, all). | -| `--deploy` / `--no-deploy` | `boolean` | `True` | Auto-deploy Kubernetes stack after cluster startup. | | `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. | --- diff --git a/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/.openspec.yaml b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/.openspec.yaml new file mode 100644 index 0000000000..7ccf7c3695 --- /dev/null +++ b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-10-25 diff --git a/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/design.md b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/design.md new file mode 100644 index 0000000000..78a86bf901 --- /dev/null +++ b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/design.md @@ -0,0 +1,19 @@ +# Design + +## Context + +The devcontainer lifecycle previously attempted to auto-deploy Kubernetes stacks during `post-start` and `bootstrap-k8s`. This failed because subprocess isolation drops the session bus environment variables required to access the OS keyring. In addition, `post-start` starts before the session bus daemon initializes, and no cluster context was passed to `deploy-stack`. + +The owner confirmed Option B: drop auto-deployment completely. Users unlock their keyring after container start and then run `devops k8s deploy-stack` manually. + +## Decisions + +- **Remove auto-deployment logic without shim**: In accordance with pre-1.0 policy, remove `--deploy/--no-deploy`, `_auto_deploy_k8s_stack`, and `DEVOPS_K8S_AUTO_DEPLOY`. +- **Print deploy command with context**: When `bootstrap-k8s` finishes, print `devops k8s deploy-stack --stack --context minikube`. +- **Define Minikube context constant**: Add `CONST_K8S_MINIKUBE_CONTEXT = "minikube"` to `constants.py` to prevent hardcoded string drift. +- **Pass clean arguments in background spawn**: `_spawn_background_k8s_bootstrap` passes `["--stack", stack]` without deployment flags. + +## Rejected Alternatives + +- **Option A: Keep auto-deploy and pass session bus environment variables**: Rejected by owner decision on issue #1368. Unattended startup cannot reliably access the keyring while the keyring remains locked by the user. Maintaining session bus pass-through and lifecycle ordering introduces fragile process coupling. +- **Keep `--deploy` as a deprecated no-op flag**: Rejected by devops-cli pre-1.0 policy. Pre-1.0 software maintains no backward compatibility or shims. diff --git a/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/proposal.md b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/proposal.md new file mode 100644 index 0000000000..5eeb6d2723 --- /dev/null +++ b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/proposal.md @@ -0,0 +1,51 @@ +# Proposal + +## Why + +Issue #1368: `devops devcontainer bootstrap-k8s` and the devcontainer post-start lifecycle cannot auto-deploy a Kubernetes stack. The child process receives an isolated environment without session bus keys, so the process cannot reach the OS keyring. The call passes no `--context` option, and post-start runs before the D-Bus session bus starts. The owner selected Option B to drop auto-deployment and print the command for manual execution. + +## What Changes + +- Remove `--deploy/--no-deploy` from `devops devcontainer bootstrap-k8s`. +- Remove `_auto_deploy_k8s_stack` and `MESSAGES.devcontainer.auto_deploy_failed` without a backward compatibility shim. +- Remove `DEVOPS_K8S_AUTO_DEPLOY` from `.devcontainer/devcontainer.json` and `src/devops_cli/templates/devcontainer.json.j2`. +- Remove `HELP.devcontainer.auto_deploy` from `src/devops_cli/lang/en/help.py`. +- Update `_spawn_background_k8s_bootstrap` to omit `--deploy` and `--no-deploy`. +- Update `bootstrap_k8s_cmd` to print `devops k8s deploy-stack --stack --context minikube` with `CONST_K8S_MINIKUBE_CONTEXT`. +- Add `CONST_K8S_MINIKUBE_CONTEXT` to `src/devops_cli/config/constants.py`. +- Update documentation in `docs/DEVCONTAINER_USAGE.md` and generate CLI documentation. +- The command options and terminal output change, so the change carries a spec delta for `k8s-bootstrap`. +- The change fits one pull request. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `k8s-bootstrap`: `devops devcontainer bootstrap-k8s` prints the deployment command and does not auto-deploy Kubernetes stacks. + +## Impact + +- `src/devops_cli/commands/devcontainer.py`: remove `--deploy/--no-deploy`, `_auto_deploy_k8s_stack`, and print the deploy command. +- `src/devops_cli/config/constants.py`: add `CONST_K8S_MINIKUBE_CONTEXT`. +- `src/devops_cli/lang/en/messages.py`: remove `auto_deploy_failed` and add `bootstrap_k8s_deploy_hint`. +- `src/devops_cli/lang/en/help.py`: remove `auto_deploy` and update `bootstrap_k8s` help. +- `.devcontainer/devcontainer.json`, `src/devops_cli/templates/devcontainer.json.j2`: remove `DEVOPS_K8S_AUTO_DEPLOY`. +- `docs/DEVCONTAINER_USAGE.md`, `docs/CLI_REFERENCE.md`, `docs/commands/devcontainer.md`: update documentation. +- `tests/test_devcontainer.py`, `tests/test_docs_source_argv_collector.py`: update unit tests to assert the printed deployment command and removed options. + +## Feasibility + +- Confirmed against `src/devops_cli/commands/devcontainer.py` at line 966: `_auto_deploy_k8s_stack` runs `["devops", "k8s", "deploy-stack", "--stack", stack]` with `isolate_env=True`. +- Confirmed against `src/devops_cli/core/process.py` lines 45-96: `DEFAULT_ALLOWED_ENV_VARS` drops `DBUS_SESSION_BUS_ADDRESS`. +- Confirmed on issue #1368 comment: the owner confirmed Option B on 2026-10-25. +- Confirmed `resolve_devops_argv(["k8s", "deploy-stack", "--stack", "infra", "--context", "minikube"])` returns `None`. + +## Existing Tool Considered + +- `devops k8s deploy-stack` already executes stack deployments, pushes secrets from the keyring, and manages Helm releases. +- We drop custom internal auto-deployment code and print the native command for the user to run. +- Internal code deleted: `_auto_deploy_k8s_stack`, `auto_deploy_failed`, and the `--deploy/--no-deploy` options. diff --git a/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/specs/k8s-bootstrap/spec.md b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/specs/k8s-bootstrap/spec.md new file mode 100644 index 0000000000..8ddcaa63f7 --- /dev/null +++ b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/specs/k8s-bootstrap/spec.md @@ -0,0 +1,10 @@ +# Spec Delta + +## ADDED Requirements + +### Requirement: Devcontainer bootstrap-k8s prints deploy command +When `devops devcontainer bootstrap-k8s` completes Minikube cluster startup, it SHALL print the command to deploy the Kubernetes stack with the target stack and Minikube context, and SHALL NOT auto-deploy any Kubernetes stack. + +#### Scenario: Bootstrap prints deploy-stack command +- **WHEN** `devops devcontainer bootstrap-k8s --stack infra` completes +- **THEN** it prints `devops k8s deploy-stack --stack infra --context minikube` diff --git a/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/tasks.md b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/tasks.md new file mode 100644 index 0000000000..d92e08376b --- /dev/null +++ b/openspec/changes/archive/2026-10-25-1368-devcontainer-k8s-autodeploy/tasks.md @@ -0,0 +1,22 @@ +# Tasks + +## 1. Failing tests + +- [x] 1.1 Add failing unit test asserting `devops devcontainer bootstrap-k8s` prints the deployment command and resolves with `resolve_devops_argv`, and verify with `uv run pytest tests/test_devcontainer.py -k test_bootstrap_k8s_autodeploy_k8s_stack -n 0` +- [x] 1.2 Update `test_post_start_autodeploy_k8s_stack` to assert spawn arguments without `--deploy`, and update `test_docs_source_argv_collector.py` for removed deploy-stack argv + +## 2. Drop auto-deploy implementation + +- [x] 2.1 Add `CONST_K8S_MINIKUBE_CONTEXT` in `src/devops_cli/config/constants.py` +- [x] 2.2 Remove `_auto_deploy_k8s_stack` and update `_run_k8s_bootstrap_worker`, `_spawn_background_k8s_bootstrap`, and `bootstrap_k8s_cmd` in `src/devops_cli/commands/devcontainer.py` +- [x] 2.3 Remove `DEVOPS_K8S_AUTO_DEPLOY` from `src/devops_cli/commands/devcontainer.py`, `.devcontainer/devcontainer.json`, and `src/devops_cli/templates/devcontainer.json.j2` +- [x] 2.4 Update messages in `src/devops_cli/lang/en/messages.py` and help strings in `src/devops_cli/lang/en/help.py` +- [x] 2.5 Verify tests pass with `uv run pytest tests/test_devcontainer.py -k "bootstrap or autodeploy" -n 0` + +## 3. Documentation and validation + +- [x] 3.1 Update `docs/DEVCONTAINER_USAGE.md` to remove auto-deploy references +- [x] 3.2 Regenerate documentation with `uv run devops docs generate --sync-readme` +- [x] 3.3 Validate OpenSpec with `uv run devops openspec check` +- [x] 3.4 Run full verification with `uv run devops ci fail-to-pass --base origin/main` +- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD). diff --git a/openspec/specs/k8s-bootstrap/spec.md b/openspec/specs/k8s-bootstrap/spec.md index aab75905e4..ffc1601e35 100644 --- a/openspec/specs/k8s-bootstrap/spec.md +++ b/openspec/specs/k8s-bootstrap/spec.md @@ -22,3 +22,10 @@ The `devops k8s bootstrap` command help documentation SHALL describe that Miniku #### Scenario: CLI help display - **WHEN** a user requests help for `devops k8s bootstrap` - **THEN** the command description specifies Calico + +### Requirement: Devcontainer bootstrap-k8s prints deploy command +When `devops devcontainer bootstrap-k8s` completes Minikube cluster startup, it SHALL print the command to deploy the Kubernetes stack with the target stack and Minikube context, and SHALL NOT auto-deploy any Kubernetes stack. + +#### Scenario: Bootstrap prints deploy-stack command +- **WHEN** `devops devcontainer bootstrap-k8s --stack infra` completes +- **THEN** it prints `devops k8s deploy-stack --stack infra --context minikube` diff --git a/src/devops_cli/commands/devcontainer.py b/src/devops_cli/commands/devcontainer.py index d6891db8a5..07e7bdefb8 100755 --- a/src/devops_cli/commands/devcontainer.py +++ b/src/devops_cli/commands/devcontainer.py @@ -27,6 +27,7 @@ CONST_DEVCONTAINER_PUBLISHED_IMAGE, CONST_GH_LOGIN_ENV_VARS, CONST_GH_TOKEN_ENV_VARS, + CONST_K8S_MINIKUBE_CONTEXT, CONST_KEYRING_PACKAGES, CONST_KEYRING_PROMPT_TIMEOUT_SECONDS, CONST_MCP_JSON_NAME, @@ -963,29 +964,10 @@ def _start_minikube_cluster(dry_run: bool) -> tuple[bool, str]: return success, msg -def _auto_deploy_k8s_stack(workspace_dir: Path, stack: str, dry_run: bool) -> str | None: - """Auto-deploy Kubernetes stack via devops k8s deploy-stack. - - It runs at post-start, possibly before the first shell unlocks the keyring, and deploy-stack - then stops before applying anything, so its warning says how to finish the deploy. - """ - if not dry_run: - res = run_subprocess( - ["devops", "k8s", "deploy-stack", "--stack", stack], - cwd=workspace_dir, - check=False, - quiet=True, - ) - if res.returncode == 0: - return f"Auto-deployed Kubernetes stack '{stack}'" - return f"Warning: {MESSAGES.devcontainer.auto_deploy_failed.format(stack=stack)}" - return f"Auto-deployed Kubernetes stack '{stack}'" - - def _run_k8s_bootstrap_worker( workspace_dir: Path, stack: str | None = None, *, dry_run: bool = False ) -> list[str]: - """Execute complete Minikube startup, context update, and optional K8s stack deployment.""" + """Execute complete Minikube startup and context update.""" actions: list[str] = [] if not shutil.which("minikube"): actions.append("Warning: Minikube binary is not available; skipping cluster start") @@ -998,11 +980,9 @@ def _run_k8s_bootstrap_worker( res = run_subprocess(["minikube", "status", "--format", "{{.Host}}"], check=False, quiet=True) is_running = res.returncode == 0 and "Running" in str(res.stdout) - minikube_healthy = is_running if not is_running: healthy, action_msg = _start_minikube_cluster(dry_run) actions.append(action_msg) - minikube_healthy = healthy if healthy and not dry_run: run_subprocess(["minikube", "update-context"], check=False, quiet=True) else: @@ -1010,18 +990,13 @@ def _run_k8s_bootstrap_worker( run_subprocess(["minikube", "update-context"], check=False, quiet=True) actions.append("Minikube cluster is already running") - if stack and (minikube_healthy or dry_run): - result = _auto_deploy_k8s_stack(workspace_dir, stack, dry_run) - if result: - actions.append(result) - return actions def _spawn_background_k8s_bootstrap( workspace_dir: Path, stack: str | None = None, *, dry_run: bool = False ) -> str: - """Spawn detached background process for Minikube startup and Kubernetes stack deployment.""" + """Spawn detached background process for Minikube cluster startup.""" log_file = Path(tempfile.gettempdir()) / "devops-k8s-bootstrap.log" cmd = [ "devops", @@ -1031,9 +1006,7 @@ def _spawn_background_k8s_bootstrap( str(workspace_dir), ] if stack: - cmd.extend(["--stack", stack, "--deploy"]) - else: - cmd.append("--no-deploy") + cmd.extend(["--stack", stack]) if dry_run: return f"Spawned background Minikube & Kubernetes bootstrap (log: {log_file})" @@ -1149,17 +1122,16 @@ def _run_post_start_lifecycle(workspace_dir: Path, *, dry_run: bool = False) -> else: actions.append(f"Scaffolded AI agent instructions (AGENTS.md) in {workspace_dir}") - # 6. Minikube autostart & K8s deploy status evaluation (background supervisor) + # 6. Minikube autostart (background supervisor) from devops_cli.commands.k8s.cluster_runtime import should_autostart_minikube auto_start = should_autostart_minikube() - auto_deploy = os.getenv("DEVOPS_K8S_AUTO_DEPLOY", "false").lower() in ("true", "1") stack = os.getenv("DEVOPS_K8S_STACK", "infra") if auto_start and shutil.which("minikube"): action_msg = _spawn_background_k8s_bootstrap( workspace_dir, - stack=stack if auto_deploy else None, + stack=stack, dry_run=dry_run, ) actions.append(action_msg) @@ -1609,18 +1581,15 @@ def bootstrap_k8s_cmd( Path, typer.Option("--workspace", "-w", help=HELP.options.workspace_dir) ] = DEFAULT_CURRENT_PATH, stack: Annotated[str, typer.Option("--stack", "-s", help=HELP.devcontainer.stack)] = "infra", - auto_deploy: Annotated[ - bool, typer.Option("--deploy/--no-deploy", help=HELP.devcontainer.auto_deploy) - ] = True, dry_run: Annotated[bool, typer.Option("--dry-run", help=HELP.options.dry_run)] = False, ) -> None: - """Execute Minikube cluster startup and Kubernetes stack deployment in the background.""" + """Execute Minikube cluster startup in the background.""" ws = workspace.resolve() if dry_run or is_dry_run(): render_dry_run_result( command="devops devcontainer bootstrap-k8s", action="bootstrap_k8s", - details={"workspace": str(ws), "stack": stack, "auto_deploy": auto_deploy}, + details={"workspace": str(ws), "stack": stack}, ) return @@ -1628,10 +1597,17 @@ def bootstrap_k8s_cmd( "devcontainer_bootstrap_k8s", attributes={"workspace": str(ws), "stack": stack} ): print_info(MESSAGES.devcontainer.bootstrap_k8s_start.format(workspace=ws), prefix=False) - actions = _run_k8s_bootstrap_worker(ws, stack=stack if auto_deploy else None, dry_run=False) + actions = _run_k8s_bootstrap_worker(ws, stack=stack, dry_run=False) for act in actions: if act.startswith("Warning:"): print_warning(act, prefix=False) else: print_info(f" [green]✓[/green] {act}", prefix=False) print_success(MESSAGES.devcontainer.bootstrap_k8s_ready, prefix=False) + if stack and not any(act.startswith("Warning:") for act in actions): + print_info( + MESSAGES.devcontainer.bootstrap_k8s_deploy_hint.format( + stack=stack, context=CONST_K8S_MINIKUBE_CONTEXT + ), + prefix=False, + ) diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py index 8464b91531..bd4a1ee421 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -2936,6 +2936,8 @@ class WebhookExposure(StrEnum): CONST_K8S_SERVICE_HOST_ENV: Final[str] = "KUBERNETES_SERVICE_HOST" # What the dashboard banner names when it connects with the pod's service account. CONST_K8S_IN_CLUSTER_CONTEXT: Final[str] = "in-cluster" +# The default local Minikube cluster context. +CONST_K8S_MINIKUBE_CONTEXT: Final[str] = "minikube" # ── Kubernetes Doctor Diagnostic Constants ─────────────────────────────────── CONST_K8S_DOCTOR_EVENT_FIELD_SELECTOR: Final[str] = "type=Warning" diff --git a/src/devops_cli/lang/en/help.py b/src/devops_cli/lang/en/help.py index 575be4ce3e..c138cf45f1 100644 --- a/src/devops_cli/lang/en/help.py +++ b/src/devops_cli/lang/en/help.py @@ -760,10 +760,7 @@ class DevcontainerCommandHelp: run_post_create: str = "Execute post-create setup tasks." run_post_start: str = "Execute post-start lifecycle tasks." run_all: str = "Execute all DevContainer lifecycle tasks." - bootstrap_k8s: str = ( - "Execute Minikube startup and Kubernetes stack deployment in the background." - ) - auto_deploy: str = "Auto-deploy Kubernetes stack after cluster startup." + bootstrap_k8s: str = "Execute Minikube startup in the background." stack: str = "Kubernetes stack to deploy (e.g. infra, llm, monitoring, all)." diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 77284c5578..4711b51508 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -1294,10 +1294,7 @@ class CIMessages: @dataclass(frozen=True) class DevcontainerMessages: already_exists: str = "devcontainer.json already exists: {path}" - auto_deploy_failed: str = ( - "Failed to auto-deploy Kubernetes stack '{stack}'. If the keyring was still locked, run " - "`devops devcontainer unlock-keyring`, then `devops k8s deploy-stack --stack {stack}`." - ) + bootstrap_k8s_deploy_hint: str = "Deploy the stack once the keyring is unlocked: devops k8s deploy-stack --stack {stack} --context {context}" created_file: str = "Created: {path}" no_manifest_found: str = "No devcontainer.json found: {path}" manifest_valid: str = "✓ DevContainer manifest is valid: {path}" diff --git a/src/devops_cli/templates/devcontainer.json.j2 b/src/devops_cli/templates/devcontainer.json.j2 index 2d44f2c256..2424f97369 100755 --- a/src/devops_cli/templates/devcontainer.json.j2 +++ b/src/devops_cli/templates/devcontainer.json.j2 @@ -43,7 +43,6 @@ ], "containerEnv": { "DEVOPS_CLI_CONFIG": "${containerWorkspaceFolder}/config.yaml", - "DEVOPS_K8S_AUTO_DEPLOY": "true", "DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus", "GIT_CONFIG_COUNT": "4", "GIT_CONFIG_KEY_0": "credential.https://githubproxy.fjygbaifeng.eu.org.helper", diff --git a/tests/test_devcontainer.py b/tests/test_devcontainer.py index 3c80162337..6df3abecae 100644 --- a/tests/test_devcontainer.py +++ b/tests/test_devcontainer.py @@ -27,7 +27,6 @@ def runner() -> CliRunner: def isolate_devcontainer_env(monkeypatch: pytest.MonkeyPatch) -> None: """Isolate devcontainer tests from spawning real background system daemons.""" monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") monkeypatch.setenv("DEVOPS_CLI_SKIP_TOOL_BOOTSTRAP", "1") @@ -185,7 +184,6 @@ def test_post_start_command_executes_successfully( fake_home.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") result = runner.invoke(app, ["post-start", "--workspace", str(tmp_path)]) assert result.exit_code == 0 @@ -200,7 +198,6 @@ def test_post_start_spawns_background_k8s_bootstrap( fake_home.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "true") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") monkeypatch.setattr("shutil.which", lambda prog: f"/usr/local/bin/{prog}") mock_proc = MagicMock() @@ -270,9 +267,7 @@ def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: monkeypatch.setattr("shutil.which", lambda prog: f"/usr/local/bin/{prog}") with docker_engine(MagicMock()): - result = runner.invoke( - app, ["bootstrap-k8s", "--workspace", str(tmp_path), "--no-deploy"] - ) + result = runner.invoke(app, ["bootstrap-k8s", "--workspace", str(tmp_path)]) assert result.exit_code == 0 assert "Started Minikube cluster (--driver=docker --cni=calico --gpus=all)" in result.output assert any(c[:2] == ["minikube", "start"] for c in calls) @@ -309,9 +304,7 @@ def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: ) with docker_engine(MagicMock()): - result = runner.invoke( - app, ["bootstrap-k8s", "--workspace", str(tmp_path), "--no-deploy"] - ) + result = runner.invoke(app, ["bootstrap-k8s", "--workspace", str(tmp_path)]) assert result.exit_code == 0 assert "Started Minikube cluster (--driver=docker --cni=calico)" in result.output assert any(c == ["minikube", "start", "--driver=docker", "--cni=calico"] for c in calls) @@ -334,7 +327,7 @@ def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: "devops_cli.commands.devcontainer._wait_for_docker_daemon", lambda timeout=45: False ) - result = runner.invoke(app, ["bootstrap-k8s", "--workspace", str(tmp_path), "--no-deploy"]) + result = runner.invoke(app, ["bootstrap-k8s", "--workspace", str(tmp_path)]) assert result.exit_code == 0 assert "Docker daemon is not running" in result.output @@ -377,7 +370,6 @@ def test_post_start_mcp_scaffolding_and_sync( fake_home.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") # Create pyproject.toml and .agents directory (tmp_path / "pyproject.toml").write_text('[project]\nname = "demo"\n', encoding="utf-8") @@ -416,7 +408,7 @@ def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: "devops_cli.commands.devcontainer._wait_for_docker_daemon", lambda timeout=45: True ) - result = runner.invoke(app, ["bootstrap-k8s", "--workspace", str(tmp_path), "--no-deploy"]) + result = runner.invoke(app, ["bootstrap-k8s", "--workspace", str(tmp_path)]) assert result.exit_code == 0 assert "Minikube cluster is already running" in result.output @@ -428,7 +420,6 @@ def test_post_start_installs_pre_commit_hooks( fake_home.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") # Scaffold .git and .pre-commit-config.yaml (tmp_path / ".git").mkdir() @@ -468,7 +459,6 @@ def test_post_start_honors_workspace_ssh_key_prefix( ssh_dir.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") ws = tmp_path / "test-local-dev" ws.mkdir() @@ -510,7 +500,6 @@ def test_post_start_does_not_adopt_foreign_prefixed_key( ssh_dir.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") ws = tmp_path / "isolated-proj" ws.mkdir() @@ -557,7 +546,6 @@ def test_post_start_signs_with_a_key_without_a_prefix_when_the_workspace_has_non ssh_dir.mkdir(parents=True) monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") ws = tmp_path / "isolated-proj" ws.mkdir() @@ -772,7 +760,6 @@ def test_run_lifecycle_command_executes_hooks( fake_home.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") result = runner.invoke(app, ["run-lifecycle", "--all", "--workspace", str(tmp_path)]) assert result.exit_code == 0 @@ -893,7 +880,6 @@ def test_post_start_never_starts_git_daemon( fake_home.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") monkeypatch.delenv("DEVOPS_GIT_DAEMON_AUTOSTART", raising=False) monkeypatch.delenv("DEVOPS_GIT_DAEMON_PATHS", raising=False) @@ -918,28 +904,52 @@ def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: def test_post_start_autodeploy_k8s_stack( self, runner: CliRunner, tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: - """devops devcontainer post-start with DEVOPS_K8S_AUTO_DEPLOY spawns bootstrap with stack.""" + """devops devcontainer post-start spawns bootstrap with stack and no deploy flag.""" fake_home = tmp_path / "home" fake_home.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "true") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "true") - monkeypatch.setenv("DEVOPS_K8S_STACK", "observability") + monkeypatch.setenv("DEVOPS_K8S_STACK", "infra") monkeypatch.setattr("shutil.which", lambda prog: f"/usr/local/bin/{prog}") mock_proc = MagicMock() mock_proc.__enter__.return_value = mock_proc mock_proc.communicate.return_value = ("", "") mock_proc.returncode = 0 - monkeypatch.setattr("subprocess.Popen", lambda *a, **kw: mock_proc) + captured_popen: list[list[str]] = [] + + def fake_popen(cmd: list[str], *a: object, **kw: object) -> MagicMock: + captured_popen.append(cmd) + return mock_proc + + monkeypatch.setattr("subprocess.Popen", fake_popen) result = runner.invoke(app, ["post-start", "--workspace", str(tmp_path)]) assert result.exit_code == 0 assert "Spawned background Minikube & Kubernetes bootstrap" in result.output + bootstrap_calls = [ + cmd + for cmd in captured_popen + if len(cmd) >= 3 and cmd[:3] == ["devops", "devcontainer", "bootstrap-k8s"] + ] + assert len(bootstrap_calls) == 1 + spawned_cmd = bootstrap_calls[0] + assert spawned_cmd == [ + "devops", + "devcontainer", + "bootstrap-k8s", + "--workspace", + str(tmp_path), + "--stack", + "infra", + ] + assert "--deploy" not in spawned_cmd + assert "--no-deploy" not in spawned_cmd def test_bootstrap_k8s_autodeploy_k8s_stack( self, runner: CliRunner, tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: - """devops devcontainer bootstrap-k8s autodeploys stack when cluster is running.""" + """devops devcontainer bootstrap-k8s prints deploy command instead of auto-deploying.""" + from devops_cli.core.command_resolver import resolve_devops_argv def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: import subprocess @@ -960,12 +970,15 @@ def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: "--workspace", str(tmp_path), "--stack", - "observability", - "--deploy", + "infra", ], ) assert result.exit_code == 0 - assert "Auto-deployed Kubernetes stack 'observability'" in result.output + assert "Auto-deployed" not in result.output + expected_cmd = "devops k8s deploy-stack --stack infra --context minikube" + assert expected_cmd in result.output + tokens = expected_cmd.split()[1:] + assert resolve_devops_argv(tokens) is None def test_devcontainer_update_and_validate_edge_cases( self, runner: CliRunner, tmp_path: Path @@ -1060,7 +1073,6 @@ def test_setup_volume_mount_permissions_and_lifecycle( fake_ssh.mkdir() monkeypatch.setenv("HOME", str(fake_home)) monkeypatch.setenv("DEVOPS_MINIKUBE_AUTOSTART", "false") - monkeypatch.setenv("DEVOPS_K8S_AUTO_DEPLOY", "false") # Test dry-run permission setup dry_actions = _setup_volume_mount_permissions(tmp_path, dry_run=True) @@ -2233,36 +2245,33 @@ def test_post_create_skip_tools_flag(tmp_path: Path, runner: CliRunner) -> None: mock_pc.assert_called_once_with(tmp_path.resolve(), dry_run=False, skip_tools=True) -def test_auto_deploy_passes_the_stack_as_an_option_and_names_the_unlock_on_failure( +def test_bootstrap_k8s_prints_deploy_stack_command( tmp_path: Path, monkeypatch: pytest.MonkeyPatch ) -> None: - """deploy-stack takes only `--stack`, and at post-start the keyring may still be locked.""" - import subprocess - - from devops_cli.commands import devcontainer + """bootstrap-k8s prints the deploy-stack command with the minikube context.""" + from devops_cli.config.constants import CONST_K8S_MINIKUBE_CONTEXT + from devops_cli.core.command_resolver import resolve_devops_argv - calls: list[list[str]] = [] - codes = iter([0, 1]) + def mock_run_subprocess(cmd: list[str], **kwargs: object) -> object: + import subprocess - def fake_run(cmd: list[str], **_: object) -> subprocess.CompletedProcess[str]: - calls.append(cmd) - return subprocess.CompletedProcess(cmd, next(codes), "", "") + if cmd[:2] == ["minikube", "status"]: + return subprocess.CompletedProcess(cmd, returncode=0, stdout="Running", stderr="") + return subprocess.CompletedProcess(cmd, returncode=0, stdout="", stderr="") - monkeypatch.setattr(devcontainer, "run_subprocess", fake_run) - deployed = devcontainer._auto_deploy_k8s_stack(tmp_path, "infra", dry_run=False) - failed = devcontainer._auto_deploy_k8s_stack(tmp_path, "infra", dry_run=False) or "" - assert ( - calls[0], - deployed, - "devops devcontainer unlock-keyring" in failed, - "devops k8s deploy-stack --stack infra" in failed, - ) == ( - ["devops", "k8s", "deploy-stack", "--stack", "infra"], - "Auto-deployed Kubernetes stack 'infra'", - True, - True, + monkeypatch.setattr("devops_cli.commands.devcontainer.run_subprocess", mock_run_subprocess) + monkeypatch.setattr("shutil.which", lambda prog: f"/usr/local/bin/{prog}") + monkeypatch.setattr( + "devops_cli.commands.devcontainer._wait_for_docker_daemon", lambda timeout=45: True ) + runner = CliRunner() + result = runner.invoke(app, ["bootstrap-k8s", "--workspace", str(tmp_path), "--stack", "llm"]) + assert result.exit_code == 0 + expected_cmd = f"devops k8s deploy-stack --stack llm --context {CONST_K8S_MINIKUBE_CONTEXT}" + assert expected_cmd in result.output + assert resolve_devops_argv(expected_cmd.split()[1:]) is None + def test_devcontainer_ollama_endpoint_matches_gateway_service_and_port() -> None: """Verify .devcontainer/devcontainer.json ollama.endpoint addresses a valid profiles Service diff --git a/tests/test_docs_source_argv_collector.py b/tests/test_docs_source_argv_collector.py index d0b7dcf444..b8aa264906 100644 --- a/tests/test_docs_source_argv_collector.py +++ b/tests/test_docs_source_argv_collector.py @@ -241,7 +241,14 @@ def test_the_collector_reads_every_module_and_both_prefixes( ("src/devops_cli/commands/ci.py", ("docs", "check")), ( "src/devops_cli/commands/devcontainer.py", - ("k8s", "deploy-stack", "--stack", _single("stack")), + ( + "devcontainer", + "bootstrap-k8s", + "--workspace", + _single("str(workspace_dir)"), + "--stack", + _single("stack"), + ), ), ("src/devops_cli/core/cli.py", (_single("cmd_name"), _spread("*args"))), ("src/devops_cli/ai/mcp/server.py", ("config", "show")),