Initial commit
This commit is contained in:
53
functions/kex.fish
Normal file
53
functions/kex.fish
Normal file
@@ -0,0 +1,53 @@
|
||||
function kex
|
||||
set -l context (kubectl config current-context)
|
||||
set -l namespace apps
|
||||
set -l pod ""
|
||||
set -l command ""
|
||||
set -l debug false
|
||||
|
||||
getopts $argv | while read -l key value
|
||||
switch $key
|
||||
case c
|
||||
set context $value
|
||||
case n
|
||||
set namespace $value
|
||||
case d
|
||||
set debug $value
|
||||
case _
|
||||
if test -z "$pod"
|
||||
set pod $value
|
||||
|
||||
continue
|
||||
end
|
||||
|
||||
if test -n "$command"
|
||||
set command "$command "
|
||||
end
|
||||
|
||||
set command "$command$value"
|
||||
end
|
||||
end
|
||||
|
||||
if $debug == true
|
||||
echo "Context : $context"
|
||||
echo "Namespace : $namespace"
|
||||
echo "Pod basename: $pod"
|
||||
echo "Command : '$command'"
|
||||
end
|
||||
|
||||
set podname (kubectl --context="$context" --namespace="$namespace" get pod -l app="$pod",instance=app -o name | shuf | head -1 | sed 's/^pod\///')
|
||||
|
||||
if test -z "$podname"
|
||||
echo "Pod $pod not found in cluster $context’s $namespace namespace" >/dev/stderr
|
||||
|
||||
return 1
|
||||
end
|
||||
|
||||
echo "Pod found : $podname"
|
||||
|
||||
if test -z "$command"
|
||||
kubectl --context="$context" --namespace="$namespace" exec -ti "$podname" -- bash
|
||||
else
|
||||
kubectl --context="$context" --namespace="$namespace" exec -ti "$podname" -- bash -c "$command"
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user