From 80e4849b776ab43c7099f30002b1d4ee258b0497 Mon Sep 17 00:00:00 2001 From: Alex Young Date: Sun, 10 Dec 2023 14:53:58 -0500 Subject: [PATCH] refactor(zsh): updates img commands --- .../custom/plugins/img/img.plugin.zsh | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/zsh/.oh-my-zsh/custom/plugins/img/img.plugin.zsh b/zsh/.oh-my-zsh/custom/plugins/img/img.plugin.zsh index 878c504..579448b 100755 --- a/zsh/.oh-my-zsh/custom/plugins/img/img.plugin.zsh +++ b/zsh/.oh-my-zsh/custom/plugins/img/img.plugin.zsh @@ -2,7 +2,7 @@ set +euo pipefail -# authenticate +# authenticate and choose environment k8a() { AWS_PROFILE=ptc-gbl-identity aws sso login ENVS=("dev" "staging" "prod") @@ -21,33 +21,57 @@ k8a() { kubens "team-athlete" } -# choose a pod via fzf +# choose a pod k8p() { - kubectl get pods | fzf --tac | awk '{print $1}' + kubectl get pods | fzf --tac -1 | awk '{print $1}' } -# choose a container from a pod via fzf +# choose a container from a pod k8c() { if [[ -z $1 ]]; then local -r POD=$(k8p) else local -r POD=$1 fi - kubectl get pod "$POD" -o jsonpath="{range .spec['containers','initContainers']}{[*].name}{\"\n\"}{end}" | fzf + kubectl get pod "$POD" -o jsonpath="{range .spec['containers','initContainers']}{[*].name}{\"\n\"}{end}" | fzf -1 } +# choose an image from all containers +k8i() { + if [[ -z $1 ]]; then + local -r POD=$(k8p) + else + local -r POD=$1 + fi + kubectl get pod "$POD" -o jsonpath="{range .spec['containers','initContainers']}{[*].image}{\"\n\"}{end}" | uniq | fzf -1 +} + +# create an interactive shell +k8sh() { + if [[ -z $1 ]]; then + local -r POD=$(k8p) + else + local -r POD=$1 + fi + local -r IMAGE=$(k8i "$POD") + kubectl debug "$POD" -it --image="$IMAGE" -- sh +} + +# describe k8d() { k8p | xargs -I _ kubectl describe pods/_ } +# follow logs k8lf() { - POD=$(k8p) - CONTAINER=$(k8c "$POD") + local -r POD=$(k8p) + local -r CONTAINER=$(k8c "$POD") kubectl logs -f -c "$CONTAINER" "$POD" } -k8lp() { - POD=$(k8p) - CONTAINER=$(k8c "$POD") - kubectl logs -p -c "$CONTAINER" "$POD" +# previous logs +k8lc() { + local -r POD=$(k8p) + local -r CONTAINER=$(k8c "$POD") + kubectl logs "$POD" -c "$CONTAINER" -p }