From 48ad89385b8bb71652af6a8bdb9ba2a65cbf4cf2 Mon Sep 17 00:00:00 2001 From: Marcus Noble Date: Fri, 26 Nov 2021 13:22:19 +0000 Subject: [PATCH] Updated kube alises Signed-off-by: Marcus Noble --- .dotfiles/1-zsh | 17 ------------- .dotfiles/kubernetes | 57 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/.dotfiles/1-zsh b/.dotfiles/1-zsh index 20f67f3..bbcab44 100644 --- a/.dotfiles/1-zsh +++ b/.dotfiles/1-zsh @@ -1,28 +1,11 @@ export ZSH="$HOME/.oh-my-zsh" -export ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20 - plugins=( aws zsh-syntax-highlighting - zsh-autosuggestions ) autoload -U compinit && compinit -# This speeds up pasting w/ autosuggest -# https://github.com/zsh-users/zsh-autosuggestions/issues/238 -pasteinit() { - OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]} - zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`? -} -pastefinish() { - zle -N self-insert $OLD_SELF_INSERT -} -zstyle :bracketed-paste-magic paste-init pasteinit -zstyle :bracketed-paste-magic paste-finish pastefinish -# https://github.com/zsh-users/zsh-autosuggestions/issues/351 -ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste accept-line) - DISABLE_UNTRACKED_FILES_DIRTY="true" SHOW_AWS_PROMPT=false diff --git a/.dotfiles/kubernetes b/.dotfiles/kubernetes index 1b17de6..7eab300 100644 --- a/.dotfiles/kubernetes +++ b/.dotfiles/kubernetes @@ -1,11 +1,6 @@ alias k='kubectl ' -alias kgs='kubectl-gs ' alias kshell='kubectl run -it shell --image bash --restart Never --rm -- sh' -kiam () { - kubectl run -it shell --image docker-tiocoreeng-apps-virtual.bts.artifactory.tio.systems/aws-cli:latest --env=AWS_DEFAULT_REGION=eu-west-1 --overrides="{ \"metadata\": { \"annotations\": { \"iam.amazonaws.com/role\": \"$1\" } } }" --command bash --restart Never --rm -} - kube-ssh() { sh -c "$(curl -sSL https://raw.githubusercontent.com/AverageMarcus/kube-ssh/master/ssh.sh)" } @@ -90,8 +85,56 @@ kl () { } ## Display everything -kall () { - kubectl get all --all-namespaces +kall() { + NAMESPACE="" + LABEL="" + ALL_NAMESPACES=false + while test $# -gt 0; do + case "$1" in + -n|--namespace) + shift + NAMESPACE=$1 + shift + ;; + -l|--selector) + shift + LABEL=$1 + shift + ;; + -A|--all-namespaces) + ALL_NAMESPACES=true + shift + ;; + -h|--help) + echo "kall - get all Kubernetes resources matching a given label selector" + echo " " + echo "kall [options]" + echo " " + echo "Options:" + echo "-h, --help show this help text" + echo "-n, --namespace the namespace to check against" + echo "-l, --selector the label selector to match on" + echo "-A, --all-namespaces search all namespaces" + return 0 + ;; + *) + break + ;; + esac + done + + if [[ "${LABEL}" == "" ]]; then + echo "Please provide a label selector to match on" + return 1 + fi + + NAMES="$(kubectl api-resources --namespaced --verbs list -o name | tr '\n' ,)" + + if [ $ALL_NAMESPACES ]; then + kubectl get "${NAMES:0:-1}" --show-kind --ignore-not-found -l ${LABEL} -A + else + kubectl get "${NAMES:0:-1}" --show-kind --ignore-not-found -l ${LABEL} -n ${NAMESPACE} + fi } k-version-test() {