Skip to content

Commit dea780f

Browse files
committed
feat(session): move local state to home and refine docs
1 parent 2358550 commit dea780f

14 files changed

Lines changed: 856 additions & 92 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
/bin/
22
*.test
33
.DS_Store
4+
5+
.stignore
6+
.okdev.yaml

docs/command-reference.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22

33
## Global Flags
44

5-
- `-c, --config`: config file path
6-
- `--session`: session name override
7-
- `--owner`: owner identity override (default: `OKDEV_OWNER` or local `USER`)
5+
- `-c, --config`: configuration file path
6+
- `--session`: explicit session identifier
7+
- `--owner`: owner label override (default: `OKDEV_OWNER` or local `USER`)
88
- `-n, --namespace`: namespace override
9-
- `--context`: kube context override
10-
- `--output text|json`: output format for list/status
11-
- `--verbose`: enable debug logging
9+
- `--context`: kubeconfig context override
10+
- `--output text|json`: output format (`list`, `status`)
11+
- `--verbose`: debug logging
1212

1313
## Commands
1414

1515
- `okdev version`
1616
- `okdev init [--template basic|gpu|llm-stack] [--force]`
1717
- `okdev validate`
1818
- `okdev up [--wait-timeout 3m] [--dry-run]`
19-
- prepares pod/workspace, SSH config, managed SSH+port-forwards, and background sync (when enabled), then exits
20-
- `spec.ports` are applied via managed SSH `LocalForward` rules
19+
- Reconciles Pod/PVC resources, updates SSH config, initializes managed forwarding/sync, then exits.
20+
- `spec.ports` is materialized as SSH `LocalForward`.
2121
- `okdev down [--delete-pvc] [--dry-run]`
2222
- `okdev status [--all] [--all-users]`
2323
- `okdev list [--all-namespaces] [--all-users]`
2424
- `okdev use <session>`
2525
- `okdev connect [--shell /bin/bash] [--cmd "..."] [--no-tty]`
2626
- `okdev ssh [--setup-key] [--user root] [--cmd "..."]`
27-
- SSH always targets the merged `okdev-sidecar` container (`sshd` + syncthing).
28-
- `okdev` writes managed host aliases to `~/.ssh/config` as `okdev-<session>`.
27+
- Targets merged `okdev-sidecar` (`sshd` + Syncthing).
28+
- Maintains managed host alias in `~/.ssh/config` as `okdev-<session>`.
2929
- `okdev ports`
3030
- `okdev sync [--mode up|down|bi] [--background] [--dry-run]`
3131
- `okdev prune [--ttl-hours 72] [--all-namespaces] [--all-users] [--include-pvc] [--dry-run]`

docs/index.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# okdev
22

3-
Lightweight Kubernetes-native dev environments for AI infra engineering.
3+
`okdev` is a CRD-less CLI for Kubernetes development sessions.
4+
It provisions and operates dev environments from `.okdev.yaml` using standard Pod/PVC resources.
45

5-
## What You Get
6+
## Core Capabilities
67

7-
- PodSpec-first config via `.okdev.yaml`
8-
- Multi-session support per repo/branch/user
9-
- Shell/SSH access, sync, and port forwarding
10-
- Cross-machine reattach with cluster-native session identity
11-
- Syncthing-based sync engine
8+
- PodSpec-driven environment definition
9+
- Multi-session workflow per repo/branch/user
10+
- Session setup via `okdev up` (SSH config, managed forwards, sync bootstrap)
11+
- Syncthing-based workspace synchronization
12+
- Reattach from any machine with kube access
1213

13-
## Read the Docs
14+
## Documentation
1415

1516
- [Quickstart](quickstart.md)
1617
- [Command Reference](command-reference.md)
18+
- [Troubleshooting](troubleshooting.md)
1719
- [Design](okdev-design.md)
1820
- [Implementation Plan](okdev-implementation-plan.md)
1921
- [Release & Versioning](release.md)
20-
- [Troubleshooting](troubleshooting.md)

docs/okdev-design.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
## 1. Overview
44

5-
`okdev` is a lightweight, Kubernetes-native development environment tool for AI/LLM infra engineers.
5+
`okdev` is a Kubernetes-native CLI for development session orchestration, designed for AI/LLM infrastructure workflows.
66

77
It intentionally avoids:
8-
- Okteto-style platform coupling and heavy cloud assumptions
9-
- DevPod-style UI dependency and single-machine-bound workflows
8+
- platform-coupled hosted control planes
9+
- UI-dependent workflows
10+
- machine-local session state as source of truth
1011

11-
It centers on one idea:
12-
- **A Kubernetes PodSpec (with minimal okdev metadata) defines the full dev environment**
12+
Core model:
13+
- **A PodSpec plus minimal `okdev` metadata defines the development environment.**
1314

1415
Design goals:
15-
- Simple CLI + Kubernetes API integration
16-
- Shareable dev sessions across machines and teammates
17-
- Works with existing clusters, namespaces, RBAC, and admission policies
18-
- Reproducible LLM infra dev stacks (GPU, model caches, large datasets, sidecars)
16+
- deterministic CLI behavior over Kubernetes APIs
17+
- cross-machine session reattachment
18+
- compatibility with existing namespace/RBAC/admission policy constraints
19+
- reproducible AI infra stacks (GPU, cache volumes, large data paths, sidecars)
1920

2021
---
2122

@@ -57,22 +58,22 @@ Needs:
5758
## 4. Product Principles
5859

5960
1. **PodSpec-first**: no custom DSL required for core environment definition.
60-
2. **Stateless client**: source of truth lives in Git + cluster objects, not local hidden state.
61+
2. **Stateless control path**: source of truth is Git + cluster objects, not a proprietary control plane.
6162
3. **Kubernetes-native identity**: contexts, kubeconfig, namespaces, service accounts.
6263
4. **Explicit over implicit**: predictable commands and clear object ownership.
63-
5. **Low cognitive load**: a small command set that covers 80% of daily dev.
64+
5. **Operational simplicity**: small command surface with clear failure modes.
6465

6566
---
6667

6768
## 5. UX Summary
6869

69-
Core flow:
70+
Execution flow:
7071
1. Developer adds `.okdev.yaml` to repo, embedding or referencing PodSpec.
7172
2. `okdev up` creates/resumes a dev session in a namespace.
72-
3. `okdev connect` opens terminal/SSH and optionally starts port forwards.
73+
3. `okdev up` configures SSH aliasing, managed forwards, and sync bootstrap.
7374
4. `okdev sync` mirrors local repo <-> pod workspace.
74-
5. Developer can leave and later reconnect from another machine via `okdev up`.
75-
6. `okdev down` stops session (or deletes, based on policy).
75+
5. Developer reconnects later from any machine with kube access via `okdev up` / `okdev ssh`.
76+
6. `okdev down` tears down runtime resources; PVC cleanup is explicit.
7677

7778
---
7879

@@ -192,8 +193,8 @@ Notes:
192193

193194
Avoiding a custom operator keeps setup simple and portable:
194195
- lower operational overhead
195-
- easier to adopt in locked-down enterprise clusters
196-
- fewer cluster-wide permissions
196+
- easier adoption in restricted enterprise clusters
197+
- avoids cluster-wide CRD/controller requirements
197198

198199
A controller/operator can be added later for advanced fleet features.
199200

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Tmux Persistent Shell Sessions
2+
3+
## Problem
4+
5+
SSH sessions die on network drops (kube port-forward instability, WiFi blips). The SSH protocol cannot resume a session on a new TCP connection. Users lose their shell state and must restart their work.
6+
7+
## Solution
8+
9+
Wrap interactive SSH sessions in tmux on the server side. On reconnect, users automatically reattach to their existing shell session. Controlled by config and CLI flag, off by default.
10+
11+
## Design
12+
13+
### Activation
14+
15+
- Config field: `spec.ssh.persistentSession` (bool pointer, default false)
16+
- CLI flag: `okdev up --tmux` (overrides config)
17+
- Per-connection opt-out: `okdev ssh --no-tmux` (sends `OKDEV_NO_TMUX=1` env var via SSH)
18+
19+
### Implementation
20+
21+
The change is server-side in the sidecar's `nsenter-dev.sh` ForceCommand handler. No changes to Go SSH client code.
22+
23+
1. `okdev up --tmux` sets env var `OKDEV_TMUX=1` on the sidecar container in the pod manifest
24+
2. `nsenter-dev.sh` checks `OKDEV_TMUX=1`, `OKDEV_NO_TMUX!=1`, and whether the session has a TTY
25+
3. If all conditions met: `exec nsenter ... tmux new-session -A -s okdev`
26+
4. Otherwise: bare shell or command as today
27+
28+
### Interactive vs Non-Interactive Detection
29+
30+
```bash
31+
if [ "$OKDEV_TMUX" = "1" ] && [ "$OKDEV_NO_TMUX" != "1" ] && [ -t 0 ]; then
32+
exec nsenter ... tmux new-session -A -s okdev
33+
else
34+
exec nsenter ... "$@"
35+
fi
36+
```
37+
38+
### Session Naming
39+
40+
Single `okdev` tmux session with multiple windows. `tmux new-session -A -s okdev` creates if missing, attaches if exists. New connections become new windows in the same session.
41+
42+
### tmux Availability
43+
44+
tmux must be installed in the sidecar image. If missing at runtime, fall back to bare shell with a warning to stderr.
45+
46+
### Toggling
47+
48+
Requires pod restart. `okdev up --tmux` enables, `okdev up` (without flag) disables. Consistent with other pod-level settings.
49+
50+
## Components Modified
51+
52+
- `internal/config/config.go` — add `PersistentSession *bool` to `SSHSpec`, wire defaults
53+
- `internal/cli/up.go` — add `--tmux` flag, merge with config value
54+
- Pod builder (wherever sidecar env vars are set) — set `OKDEV_TMUX=1` on sidecar container
55+
- `internal/cli/ssh.go` — add `--no-tmux` flag, send `OKDEV_NO_TMUX=1` env var
56+
- `infra/sidecar/entrypoint.sh` / `nsenter-dev.sh` — check env vars + TTY, wrap with tmux
57+
- Sidecar Dockerfile — install tmux
58+
59+
## Out of Scope
60+
61+
- Auto-reconnect for port forwards (separate feature)
62+
- Client-side changes to `OpenShell()`
63+
- Multi-user session isolation

0 commit comments

Comments
 (0)