Skip to content

Commit ab6feeb

Browse files
author
Hien Vu
committed
fix(claude): pin dev-container skills to the minikube context
Address review comments on PR #2741: - Name the kube context explicitly in every cluster command (kubectl --context minikube, helm --kube-context minikube) and warn in `status` when the active context is not minikube, so a stray `kubectl config use-context` cannot redirect a deploy at a real cluster. - Route the chart-level `helm upgrade` through $DEVC like every other deploy command instead of leaving it to run on the host. - Run the protoc-header spot-check through $DEVC: in codespace mode a bare grep reads the host clone and can falsely validate a stale file. - Refuse to guess between multiple available Bucketeer codespaces; exit 2 with the list and honour an explicit BUCKETEER_CODESPACE override.
1 parent a6ce77a commit ab6feeb

4 files changed

Lines changed: 59 additions & 15 deletions

File tree

.claude/skills/devcontainer-deploy/SKILL.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,32 @@ For a code change to one service (e.g. backend):
5858

5959
```bash
6060
$DEVC 'make build-go-embed && TAG=localenv make build-docker-images && TAG=localenv make minikube-load-images'
61-
$DEVC 'kubectl rollout restart deployment <name> && kubectl rollout status deployment <name>'
61+
$DEVC 'kubectl --context minikube rollout restart deployment <name> && kubectl --context minikube rollout status deployment <name>'
6262
```
6363

6464
The Bucketeer deployments are `api`, `web`, `batch-server`, and `subscriber`
65-
(confirm with `$DEVC 'kubectl get deployments'`). Chart-level
66-
changes instead: `helm upgrade bucketeer manifests/bucketeer/ --values
67-
manifests/bucketeer/values.dev.yaml`.
65+
(confirm with `$DEVC 'kubectl --context minikube get deployments'`). Chart-level
66+
changes instead:
67+
68+
```bash
69+
$DEVC 'helm upgrade bucketeer manifests/bucketeer/ --kube-context minikube --values manifests/bucketeer/values.dev.yaml'
70+
```
71+
72+
Always go through `$DEVC` and always name the context: a bare `helm`/`kubectl`
73+
runs against whatever context is currently active, which on the host is often a
74+
real cluster. `$DEVC status` warns when the active context is not `minikube`.
6875

6976
## 4. Verify
7077

7178
```bash
72-
$DEVC 'kubectl get pods' # everything Running/Completed, restarts not climbing
79+
$DEVC 'kubectl --context minikube get pods' # everything Running/Completed, restarts not climbing
7380
$DEVC 'curl -sk https://api-gateway.bucketeer.io/health' # must run INSIDE the container
7481
```
7582

7683
The `*.bucketeer.io` hosts entries live in the container's `/etc/hosts`
7784
(pointed at `minikube ip`) — curl from the host proves nothing. For a failing
78-
pod: `$DEVC 'kubectl logs deploy/<name> --tail=100'` and
79-
`$DEVC 'kubectl describe pod <pod>'`.
85+
pod: `$DEVC 'kubectl --context minikube logs deploy/<name> --tail=100'` and
86+
`$DEVC 'kubectl --context minikube describe pod <pod>'`.
8087

8188
## Related dev-cluster chores
8289

.claude/skills/devcontainer-generate/SKILL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ error; don't force it without flagging the compatibility break to the user.
5252
outputs. **A diff touching every `.pb.go` in the repo means a wrong protoc
5353
version — abort and check `$DEVC 'protoc --version'`.**
5454
- Spot-check one regenerated file's header still says `protoc v4.23.4`:
55-
`grep -m1 "protoc " proto/<domain>/<file>.pb.go`
55+
`$DEVC 'grep -m1 "protoc " proto/<domain>/<file>.pb.go'` — run it through
56+
`$DEVC`, not bare: in codespace mode the host clone is a *different* checkout,
57+
so a bare `grep` would validate a stale file that was never regenerated.
5658
- Build still compiles: `$DEVC 'make build-go'` (or the affected
5759
`make build-<service>`), and `$DEVC 'make gofmt'` after any Go changes.
5860

.claude/skills/devcontainer-run/SKILL.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ Detection order (the script handles all of this):
4242
2. Local devcontainer → `docker ps` filtered by label `devcontainer.local_folder=<repo root>`, exec via `docker exec`.
4343
3. GitHub Codespace → `gh codespace list` (needs the `codespace` auth scope), exec via `gh codespace ssh`.
4444

45-
Exit code 2 means no container was found; the script prints how to start one.
45+
If more than one available Bucketeer codespace matches (a fork is also named
46+
`bucketeer`, or you keep several), the script refuses to guess and exits 2 with
47+
the list — pick one with `export BUCKETEER_CODESPACE=<name>`.
48+
49+
Exit code 2 means no container was found (or the codespace was ambiguous); the
50+
script prints how to start one.
4651
Don't fall back to running the command on the host in that case — tell the user
4752
and let them choose, because host tool versions (especially protoc) may differ.
4853

.claude/skills/devcontainer-run/scripts/exec.sh

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,36 @@ detect() {
3535
return
3636
fi
3737

38-
# Case 3: GitHub Codespace (requires `gh` with the codespace scope)
39-
CODESPACE="$(gh codespace list --json name,repository,state \
38+
# Case 3: GitHub Codespace (requires `gh` with the codespace scope).
39+
# Never silently pick one: a fork named `bucketeer`, or several codespaces on
40+
# this repo, would otherwise run commands in the wrong clone/branch/cluster.
41+
local candidates
42+
candidates="$(gh codespace list --json name,repository,state \
4043
-q '.[] | select((.repository | endswith("/bucketeer")) and .state == "Available") | .name' 2>/dev/null \
41-
| head -1 || true)"
42-
if [ -n "$CODESPACE" ]; then
44+
|| true)"
45+
if [ -n "${BUCKETEER_CODESPACE:-}" ]; then
46+
if ! echo "$candidates" | grep -qx -- "$BUCKETEER_CODESPACE"; then
47+
echo "BUCKETEER_CODESPACE='$BUCKETEER_CODESPACE' is not an available Bucketeer codespace." >&2
48+
echo "Available:" >&2
49+
echo "$candidates" | sed 's/^/ - /' >&2
50+
exit 2
51+
fi
52+
CODESPACE="$BUCKETEER_CODESPACE"
53+
MODE=codespace
54+
return
55+
fi
56+
local count
57+
count="$(echo "$candidates" | grep -c . || true)"
58+
if [ "$count" -gt 1 ]; then
59+
echo "Multiple available Bucketeer codespaces found — refusing to guess:" >&2
60+
echo "$candidates" | sed 's/^/ - /' >&2
61+
echo "" >&2
62+
echo "Pick one explicitly:" >&2
63+
echo " export BUCKETEER_CODESPACE=<name>" >&2
64+
exit 2
65+
fi
66+
if [ "$count" -eq 1 ]; then
67+
CODESPACE="$candidates"
4368
MODE=codespace
4469
return
4570
fi
@@ -93,15 +118,20 @@ status_report() {
93118
command -v mockgen >/dev/null && echo "go-tools: OK" || echo "go-tools: MISSING (run bash .devcontainer/setup.sh)"
94119
docker info >/dev/null 2>&1 && echo "dockerd: running" || echo "dockerd: NOT running (start with: nohup sudo dockerd > /tmp/dockerd.log 2>&1 &)"
95120
if minikube status >/dev/null 2>&1; then
121+
# Always query the minikube context explicitly: the active context may point
122+
# somewhere else entirely (a real GKE cluster), and reporting its pods here
123+
# would be exactly the confusion this wrapper exists to prevent.
124+
ctx=$(kubectl config current-context 2>/dev/null || echo unknown)
125+
[ "$ctx" != "minikube" ] && echo "kube-context: WARNING active context is \"$ctx\", not minikube — bare kubectl/helm commands would hit that cluster; pass --context minikube / --kube-context minikube"
96126
# Ignore transient states (Pending/ContainerCreating/Init) — batch CronJobs
97127
# constantly spawn short-lived pods and would make the count flap.
98-
if pods=$(kubectl get pods --no-headers 2>/dev/null); then
128+
if pods=$(kubectl --context minikube get pods --no-headers 2>/dev/null); then
99129
total=$(echo "$pods" | grep -c . || true)
100130
failing=$(echo "$pods" | grep -cE "CrashLoopBackOff|ImagePull|ErrImage|Error|OOMKilled|Evicted" || true)
101131
echo "minikube: running ($total pods, $failing failing)"
102132
[ "$failing" -gt 0 ] && echo "$pods" | grep -E "CrashLoopBackOff|ImagePull|ErrImage|Error|OOMKilled|Evicted"
103133
else
104-
echo "minikube: running, but kubectl failed to list pods — check kubectl config (kubectl config current-context)"
134+
echo "minikube: running, but kubectl failed to list pods in the minikube context — check kubectl config (kubectl config get-contexts)"
105135
fi
106136
else
107137
echo "minikube: NOT running (start with: make start-minikube — never minikube start)"

0 commit comments

Comments
 (0)