v5.0.0
===================================================================== Excited to bring V5 to life. This includes some BREAKING CHANGES to several aspects of ZSH-type scwrypts. Please refer to the readme for upgrade details (specifically docs/upgrade/v4-to-v5.md) --- New Features ------------------------- - ZSH testing library with basic mock capabilities - new scwrypts environment file format includes metadata and more advanced features like optional parent env overrides, selection inheritence, and improved structurual flexibility - speedup cache for non-CI runs of ZSH-type scwrypts - ${scwryptsmodule} syntax now allows a consistent unique-naming scheme for functions in ZSH-type scwrypts while providing better insight into origin of API calls in other modules - reusable, case-statement-driven argument parsers in ZSH-type scwrypts --- Changes ------------------------------ - several utility function renames in ZSH-type scwrypts to improve consistency - documentation comments included in ZSH libraries - ZSH-type scwrypts now allow library modules to live alongside executables (zsh/lib still supported; autodetection determines default) --- Bug Fixes ---------------------------- - hardened environment checking for REQUIRED_ENV variables; this removes the ability to overwrite variables in local function contexts
This commit is contained in:
18
plugins/kube/kubectl/cli.module.zsh
Normal file
18
plugins/kube/kubectl/cli.module.zsh
Normal file
@@ -0,0 +1,18 @@
|
||||
#####################################################################
|
||||
|
||||
DEPENDENCIES+=(kubectl)
|
||||
|
||||
use redis --group kube
|
||||
|
||||
#####################################################################
|
||||
|
||||
kube.cli() {
|
||||
local NAMESPACE="$(kube.redis get --prefix "current:namespace")"
|
||||
local CONTEXT="$(kube.kubectl.context.get)"
|
||||
|
||||
local ARGS=()
|
||||
[ "${NAMESPACE}" ] && ARGS+=(--namespace "${NAMESPACE}")
|
||||
[ "${CONTEXT}" ] && ARGS+=(--context "${CONTEXT}")
|
||||
|
||||
kubectl ${ARGS[@]} $@
|
||||
}
|
56
plugins/kube/kubectl/context.module.zsh
Normal file
56
plugins/kube/kubectl/context.module.zsh
Normal file
@@ -0,0 +1,56 @@
|
||||
#####################################################################
|
||||
|
||||
use --group kube kubectl/cli
|
||||
use --group kube kubectl/namespace
|
||||
use --group kube redis
|
||||
|
||||
#####################################################################
|
||||
|
||||
${scwryptsmodule}.get() { kube.redis get --prefix "current:context"; }
|
||||
|
||||
${scwryptsmodule}.set() {
|
||||
local CONTEXT=$1
|
||||
[ ! "${CONTEXT}" ] && return 1
|
||||
|
||||
[[ "${CONTEXT}" =~ reset ]] && {
|
||||
: \
|
||||
&& kube.redis del --prefix "current:context" \
|
||||
&& kube.kubectl.namespace.set reset \
|
||||
;
|
||||
return $?
|
||||
}
|
||||
|
||||
: \
|
||||
&& kube.redis set --prefix "current:context" "${CONTEXT}" \
|
||||
&& kube.kubectl.namespace.set reset \
|
||||
;
|
||||
}
|
||||
|
||||
${scwryptsmodule}.select() {
|
||||
case "$(kube.kubectl.context.list | grep -v '^reset$' | wc -l)" in
|
||||
( 0 )
|
||||
echo.error "no contexts available"
|
||||
return 1
|
||||
;;
|
||||
( 1 )
|
||||
kube.kubectl.context.list | tail -n1
|
||||
;;
|
||||
( * )
|
||||
kube.kubectl.context.list | utils.fzf 'select a context'
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
${scwryptsmodule}.list() {
|
||||
echo reset
|
||||
local ALL_CONTEXTS="$(kube.cli config get-contexts -o name | sort -u)"
|
||||
|
||||
echo "${ALL_CONTEXTS}" | grep -v '^arn:aws:eks'
|
||||
|
||||
[[ "${AWS_ACCOUNT}" ]] && {
|
||||
echo "${ALL_CONTEXTS}" | grep "^arn:aws:eks:.*:${AWS_ACCOUNT}"
|
||||
true
|
||||
} || {
|
||||
echo "${ALL_CONTEXTS}" | grep '^arn:aws:eks'
|
||||
}
|
||||
}
|
17
plugins/kube/kubectl/kubectl.module.zsh
Normal file
17
plugins/kube/kubectl/kubectl.module.zsh
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# combines kubectl with redis to both facilitate use of kubectl
|
||||
# between varying contexts/namespaces AND grant persistence between
|
||||
# terminal sessions
|
||||
#
|
||||
|
||||
# redis wrapper for kubectl
|
||||
use --group kube kubectl/cli
|
||||
|
||||
# simplify commands for kubecontexts
|
||||
use --group kube kubectl/context
|
||||
|
||||
# simplify commands for namespaces
|
||||
use --group kube kubectl/namespace
|
||||
|
||||
# local redirect commands for remote kubernetes services
|
||||
use --group kube kubectl/service
|
23
plugins/kube/kubectl/namespace.module.zsh
Normal file
23
plugins/kube/kubectl/namespace.module.zsh
Normal file
@@ -0,0 +1,23 @@
|
||||
${scwryptsmodule}.get() { kube.redis get --prefix "current:namespace"; }
|
||||
|
||||
${scwryptsmodule}.set() {
|
||||
local NAMESPACE=$1
|
||||
[ ! "${NAMESPACE}" ] && return 1
|
||||
|
||||
[[ "${NAMESPACE}" =~ reset ]] && {
|
||||
kube.redis del --prefix "current:namespace"
|
||||
return $?
|
||||
}
|
||||
|
||||
kube.redis set --prefix "current:namespace" "${NAMESPACE}"
|
||||
}
|
||||
|
||||
${scwryptsmodule}.select() {
|
||||
kube.kubectl.namespace.list | utils.fzf 'select a namespace'
|
||||
}
|
||||
|
||||
${scwryptsmodule}.list() {
|
||||
echo reset
|
||||
echo default
|
||||
kube.cli get namespaces -o name | sed 's/^namespace\///' | sort | grep -v '^default$'
|
||||
}
|
77
plugins/kube/kubectl/service.module.zsh
Normal file
77
plugins/kube/kubectl/service.module.zsh
Normal file
@@ -0,0 +1,77 @@
|
||||
#####################################################################
|
||||
|
||||
use --group kube kubectl/cli
|
||||
use --group kube kubectl/context
|
||||
use --group kube kubectl/namespace
|
||||
|
||||
#####################################################################
|
||||
|
||||
${scwryptsmodule}.serve() {
|
||||
[ "${CONTEXT}" ] || local CONTEXT="$(kube.kubectl.context.get)"
|
||||
[ "${CONTEXT}" ] || echo.error 'must configure a context in which to serve'
|
||||
|
||||
[ "${NAMESPACE}" ] || local NAMESPACE="$(kube.kubectl.namespace.get)"
|
||||
[ "${NAMESPACE}" ] || echo.error 'must configure a namespace in which to serve'
|
||||
|
||||
utils.check-errors --no-usage || return 1
|
||||
|
||||
[ "${SERVICE}" ] && SERVICE="$(kube.kubectl.service.list | jq -c "select (.service == \"${SERVICE}\")" || echo ${SERVICE})"
|
||||
[ "${SERVICE}" ] || local SERVICE="$(kube.kubectl.service.select)"
|
||||
[ "${SERVICE}" ] || echo.error 'must provide or select a service'
|
||||
|
||||
kube.kubectl.service.list | grep -q "^${SERVICE}$"\
|
||||
|| echo.error "no service '${SERVICE}' in '${CONFIG}/${NAMESPACE}'"
|
||||
|
||||
utils.check-errors --no-usage || return 1
|
||||
|
||||
##########################################
|
||||
|
||||
SERVICE_PASSWORD="$(kube.kubectl.service.get-password)"
|
||||
kube.kubectl.service.parse
|
||||
|
||||
echo.reminder "attempting to serve ${NAMESPACE}/${SERVICE_NAME}:${SERVICE_PORT}"
|
||||
[ "${SERVICE_PASSWORD}" ] && echo.reminder "password : ${SERVICE_PASSWORD}"
|
||||
|
||||
kube.cli port-forward "service/${SERVICE_NAME}" "${SERVICE_PORT}"
|
||||
}
|
||||
|
||||
#####################################################################
|
||||
|
||||
${scwryptsmodule}.select() {
|
||||
[ "${NAMESPACE}" ] || local NAMESPACE="$(kube.kubectl.namespace.get)"
|
||||
[ "${NAMESPACE}" ] || return 1
|
||||
|
||||
local SERVICES="$(kube.kubectl.service.list)"
|
||||
local SELECTED="$({
|
||||
echo "namespace service port"
|
||||
echo ${SERVICES} \
|
||||
| jq -r '.service + " " + .port' \
|
||||
| sed "s/^/${NAMESPACE} /" \
|
||||
;
|
||||
} \
|
||||
| column -t \
|
||||
| utils.fzf 'select a service' --header-lines=1 \
|
||||
| awk '{print $2;}' \
|
||||
)"
|
||||
|
||||
echo "${SERVICES}" | jq -c "select (.service == \"${SELECTED}\")"
|
||||
}
|
||||
|
||||
${scwryptsmodule}.list() {
|
||||
kube.cli get service --no-headers\
|
||||
| awk '{print "{\"service\":\""$1"\",\"ip\":\""$3"\",\"port\":\""$5"\"}"}' \
|
||||
| jq -c 'select (.ip != "None")' \
|
||||
;
|
||||
}
|
||||
|
||||
${scwryptsmodule}.get-password() {
|
||||
[ "${PASSWORD_SECRET}" ] && [ "${PASSWORD_KEY}" ] || return 0
|
||||
|
||||
kube.cli get secret "${PASSWORD_SECRET}" -o jsonpath="{.data.${PASSWORD_KEY}}" \
|
||||
| base64 --decode
|
||||
}
|
||||
|
||||
${scwryptsmodule}.parse() {
|
||||
SERVICE_NAME="$(echo "${SERVICE}" | jq -r .service)"
|
||||
SERVICE_PORT="$(echo "${SERVICE}" | jq -r .port | sed 's|/.*$||')"
|
||||
}
|
Reference in New Issue
Block a user