fix(kube): use current-context for kubectl auth; fix SelectValue label display #81

Merged
sarman merged 1 commits from fix/kube-select-label-and-context into master 2026-06-08 00:56:20 +00:00
Owner

Problems

1. kubectl credentials still failing

Both extract_context() (kube.rs) and upload_kubeconfig() (shell.rs) ignored the kubeconfig's current-context field and always picked contexts[0] from the contexts array. If a kubeconfig has multiple contexts and current-context points to entry N>0, the wrong context was silently used — one that may have empty or expired credentials — causing the 401 "the server has asked for the client to provide credentials" error.

Fixes:

  • extract_context() — reads current-context field first; falls back to contexts[0] only when absent or empty
  • extract_current_context_name() — new helper in kubeconfig.rs using the same line-scanner approach
  • upload_kubeconfig() — uses current-context to select the matching context when storing to DB

Action required after deploy: Re-upload your kubeconfig files via Settings → Kubeconfig. Existing DB rows have the old (wrong) context stored.

2. Cluster dropdown still showing UUID

SelectValue rendered ctx.value (the raw UUID) instead of the display label (SelectItem children). The custom Select component had no mechanism to mirror a selected item's children into the trigger.

Fix: Select now builds a value → label Map by walking the children tree via collectLabels(). The map is memoised on children. SelectValue reads the display label from the map and falls back to the raw value if not found.

Test plan

  • Re-upload kubeconfig after deploying
  • Cluster dropdown shows friendly name (e.g. devops1-mgmt), not UUID
  • Kubernetes resources load without credential error
  • npm run test:run — 268 pass
  • cargo test — 343 pass
  • cargo fmt --check, cargo clippy -- -D warnings, npx tsc --noEmit, npx eslint . --max-warnings 0 — all clean
## Problems ### 1. kubectl credentials still failing Both `extract_context()` (kube.rs) and `upload_kubeconfig()` (shell.rs) ignored the kubeconfig's `current-context` field and always picked `contexts[0]` from the contexts array. If a kubeconfig has multiple contexts and `current-context` points to entry N>0, the wrong context was silently used — one that may have empty or expired credentials — causing the 401 *"the server has asked for the client to provide credentials"* error. **Fixes:** - `extract_context()` — reads `current-context` field first; falls back to `contexts[0]` only when absent or empty - `extract_current_context_name()` — new helper in `kubeconfig.rs` using the same line-scanner approach - `upload_kubeconfig()` — uses `current-context` to select the matching context when storing to DB > **Action required after deploy:** Re-upload your kubeconfig files via Settings → Kubeconfig. Existing DB rows have the old (wrong) context stored. ### 2. Cluster dropdown still showing UUID `SelectValue` rendered `ctx.value` (the raw UUID) instead of the display label (`SelectItem` children). The custom Select component had no mechanism to mirror a selected item's children into the trigger. **Fix:** `Select` now builds a `value → label` Map by walking the children tree via `collectLabels()`. The map is memoised on `children`. `SelectValue` reads the display label from the map and falls back to the raw value if not found. ## Test plan - [ ] Re-upload kubeconfig after deploying - [ ] Cluster dropdown shows friendly name (e.g. `devops1-mgmt`), not UUID - [ ] Kubernetes resources load without credential error - [ ] `npm run test:run` — 268 pass - [ ] `cargo test` — 343 pass - [ ] `cargo fmt --check`, `cargo clippy -- -D warnings`, `npx tsc --noEmit`, `npx eslint . --max-warnings 0` — all clean
sarman added 1 commit 2026-06-08 00:41:13 +00:00
fix(kube): use current-context for kubectl auth; fix SelectValue label display
Some checks failed
Test / rust-tests (pull_request) Successful in 14m31s
PR Review Automation / review (pull_request) Has been cancelled
Test / frontend-typecheck (pull_request) Successful in 1m35s
Test / frontend-tests (pull_request) Successful in 1m40s
Test / rust-fmt-check (pull_request) Successful in 11m1s
Test / rust-clippy (pull_request) Successful in 12m39s
a2cff014e9
## kubectl credentials still failing after --context fix

Root cause: both extract_context() (kube.rs) and upload_kubeconfig() (shell.rs)
ignored the kubeconfig's current-context field and always picked contexts[0] from
the contexts array. If a kubeconfig has multiple contexts and current-context
points to entry N>0, we silently used the wrong context — one that may have empty
or expired credentials — causing the 401 "the server has asked for the client to
provide credentials" error on every kubectl call.

Fixes:
- extract_context(): read current-context field first; fall back to contexts[0]
  only when current-context is absent or empty.
- extract_current_context_name(): new helper in kubeconfig.rs using the same
  line-scanner approach as parse_kubeconfig_contexts (no extra dependencies).
- upload_kubeconfig(): use current-context to select the matching context entry
  when storing context name in kubeconfig_files; falls back to first entry.

NOTE: existing kubeconfig rows in the database have the old (wrong) context
stored. Re-uploading kubeconfig files after deploying this build will fix them.

## Cluster dropdown still showing UUID

Root cause: SelectValue rendered ctx.value (the raw UUID passed to SelectItem's
value prop) instead of the display label (SelectItem's children). The custom
Select component had no mechanism to mirror a selected item's children into the
trigger area.

Fix: Select now builds a value→label Map by walking the children tree at render
time (collectLabels). The map is memoised on children. SelectValue reads the
display label from the map; if found, shows the label; otherwise falls back to
the raw value so existing behaviour is preserved for callers that don't need it.
sarman merged commit 7ba927e1a7 into master 2026-06-08 00:56:20 +00:00
sarman deleted branch fix/kube-select-label-and-context 2026-06-08 00:56:21 +00:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sarman/tftsr-devops_investigation#81
No description provided.