From 821c42650263fac127add0f560d5b89a486be9d7 Mon Sep 17 00:00:00 2001 From: sanchpet Date: Tue, 18 Aug 2026 16:55:05 +0400 Subject: [PATCH] feat(kube): join the managed fleet config and notice when it moves MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The fleet arrives as a generated file rather than as edits to ~/.kube/config, so it is joined through KUBECONFIG with the personal config first: a duplicate key resolves to the earlier file, which leaves hand-made entries behaving exactly as before. The drift check talks to a git remote, so it runs detached and the shell prints the previous run's answer. A slow or unreachable registry then costs a stale notice rather than a delayed prompt — the failure mode that would otherwise get the whole thing deleted from the profile. It reports and never applies: adding or removing a context silently changes where the next command lands. Assisted-By: Claude Signed-off-by: sanchpet --- README.md | 1 + dot_zshrc.tmpl | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/README.md b/README.md index f981b7f..7d1a4ce 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,7 @@ The prompt is [Starship](https://starship.rs) (`dot_config/starship.toml` — th |--------|--------|---------| | git | built-in | Git aliases (`gst`, `gco`, `gp`, …) | | kubectl | built-in | `k*` aliases + completion (`kgp`, `kgaa`, `kdp`, …) | +| kubectl fleet | `dot_zshrc.tmpl` | Joins a generated `~/.kube/tv-fleet.yaml` onto `KUBECONFIG` when it exists, personal config first, and prints a once-a-day notice when the fleet has moved. The check runs detached, so the prompt shows the previous run's answer rather than waiting for a git remote; it never edits contexts by itself | | helm | built-in | Helm completion | | terraform | built-in | `tf*` aliases + completion + workspace | | aws | built-in | `asp`/`acp` profile switch + completion | diff --git a/dot_zshrc.tmpl b/dot_zshrc.tmpl index e21ed63..45c3f44 100644 --- a/dot_zshrc.tmpl +++ b/dot_zshrc.tmpl @@ -19,6 +19,33 @@ if [ -d "$HOME/.krew/bin" ]; then export PATH="$HOME/.krew/bin:$PATH" fi +# The managed fleet is a generated file, joined here rather than merged into ~/.kube/config. +# Personal config first: on a duplicate key the earlier file wins, so hand-made entries keep +# their behaviour and the fleet only adds what they do not already define. +if [ -f "$HOME/.kube/tv-fleet.yaml" ]; then + export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}:$HOME/.kube/tv-fleet.yaml" +fi + +# Tell me when the cluster fleet has moved, without ever making me wait for it. The check talks +# to a git remote, so it runs detached and what the shell prints is the *previous* run's answer; +# a slow or unreachable registry costs a stale notice, never a delayed prompt. It reports only — +# adding or removing a context silently would change where the next command lands. +_tv_fleet_notice() { + local dir="${XDG_CACHE_HOME:-$HOME/.cache}/tv" + local stamp="$dir/fleet-check.stamp" msg="$dir/fleet-check.msg" + [ -s "$msg" ] && cat "$msg" + command -v kubectl-tv >/dev/null 2>&1 || return 0 + mkdir -p "$dir" 2>/dev/null || return 0 + # Re-check once a day. -mtime +0 is "last modified more than 24h ago"; a missing stamp is the + # first run and checks immediately. + if [ ! -e "$stamp" ] || [ -n "$(find "$stamp" -mtime +0 -print 2>/dev/null)" ]; then + ( kubectl-tv clusters check --quiet >"$msg.new" 2>/dev/null \ + && mv -f "$msg.new" "$msg" || rm -f "$msg.new" + : >"$stamp" ) &! + fi +} +_tv_fleet_notice + {{ if .bitwarden.agent -}} # --- SSH agent: Bitwarden --- # Route SSH auth + git commit signing through the Bitwarden desktop app's SSH agent, whose