Skip to content

Commit

Permalink
refactor(zsh): updates img commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpyoung committed Dec 10, 2023
1 parent efcd3fe commit 80e4849
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions zsh/.oh-my-zsh/custom/plugins/img/img.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}

0 comments on commit 80e4849

Please sign in to comment.