Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] <repo_path>` | Add a folder to the VS Code workspace file. |
| | `devops workspace remove [OPTIONS] <repo_path>` | Remove a folder from the VS Code workspace file. |
| | `devops workspace generate [OPTIONS]` | Regenerate the workspace file from all repos in the repos directory. |
Expand Down
3 changes: 1 addition & 2 deletions docs/CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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. |

---
Expand Down
2 changes: 1 addition & 1 deletion docs/DEVCONTAINER_USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <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 <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.
Expand Down
3 changes: 1 addition & 2 deletions docs/commands/devcontainer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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. |

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-10-25
Original file line number Diff line number Diff line change
@@ -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 <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.
Original file line number Diff line number Diff line change
@@ -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 <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.
Original file line number Diff line number Diff line change
@@ -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`
Original file line number Diff line number Diff line change
@@ -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).
7 changes: 7 additions & 0 deletions openspec/specs/k8s-bootstrap/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
56 changes: 16 additions & 40 deletions src/devops_cli/commands/devcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand All @@ -998,30 +980,23 @@ 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:
if not dry_run:
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",
Expand All @@ -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})"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1609,29 +1581,33 @@ 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

with trace_span(
"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,
)
2 changes: 2 additions & 0 deletions src/devops_cli/config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 1 addition & 4 deletions src/devops_cli/lang/en/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."


Expand Down
Loading
Loading