Commit b14618f
fix(cli): correct mcp secrets sync apply behavior and thread cobra ctx (#1814)
## summary
three issues in `mcp secrets sync`:
- `SyncSecretsMcp` and `applySecretToCluster` passed `context.TODO()` to
every clientset Get/Create/Update call. ctrl-c during a slow apply
(remote cluster, hung api-server connection) silently fell through to
whatever the kubernetes client default did rather than honoring
cancellation. fix: thread `cmd.Context()` from the cobra `RunE` through
`SyncSecretsMcp` and `applySecretToCluster`. matches the existing kagent
cli convention used by `InstallCmd`, `UninstallCmd`, `InvokeCmd`,
`DashboardCmd`, and `DeployCmd`, which all take `ctx` as the first
argument and are wired from `cmd.Context()` at the top level in
`cmd/kagent/main.go`.
- the Get error path was treated as "secret does not exist" without
inspecting the error, so RBAC forbidden, network errors, and
ctx-cancellation all surfaced as confusing `"failed to create secret"`
messages instead of the real cause. fix: branch on
`apierrors.IsNotFound(err)` so only true-NotFound triggers Create; any
other Get error returns a wrapped message immediately.
- the update path discarded the Get result, so the Secret being sent to
Update had no `metadata.resourceVersion`. kubernetes Update requires
`resourceVersion` and rejects optimistic-concurrency-violating writes,
so updates against a populated cluster would fail with a validation
error. fix: capture the live object from Get and copy its
`resourceVersion` onto the secret built from `.env` before calling
Update.
the second and third items were flagged by copilot on the initial
revision of this PR; addressed in the follow-up commit `cf8b5efd`.
## ai model disclosure
used claude code (claude opus 4.7) to triage the `context.TODO()` call
sites and draft the diff. self-reviewed against
`go/core/cli/internal/cli/agent/deploy.go` to confirm the `apierrors`
import alias and the ctx-as-first-arg pattern, and against
`cmd/kagent/main.go` to confirm `cmd.Context()` is the established
wiring point. verified locally via:
```bash
go vet ./core/cli/...
./bin/golangci-lint run ./core/cli/internal/cli/mcp/... # 0 issues
go build ./core/cli/...
go test -race -count=1 ./core/cli/internal/cli/mcp/... # ok
```
---------
Signed-off-by: SarthakB11 <sarthak.bhardwaj21b@iiitg.ac.in>
Co-authored-by: Eitan Yarmush <eitan.yarmush@solo.io>1 parent 7fe81f3 commit b14618f
2 files changed
Lines changed: 21 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
396 | | - | |
397 | | - | |
| 396 | + | |
| 397 | + | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
112 | | - | |
| 113 | + | |
113 | 114 | | |
114 | 115 | | |
115 | | - | |
| 116 | + | |
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| |||
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
133 | 137 | | |
134 | 138 | | |
135 | 139 | | |
136 | 140 | | |
137 | | - | |
138 | | - | |
139 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
140 | 148 | | |
141 | 149 | | |
142 | 150 | | |
| |||
0 commit comments