lululau
2021-07-22 17:03:10 +08:00
一个 k9s plugin,支持在一个新打开的 TMUX window / iTerm2 Tab 中打开日志,前提是容器内有 lnav
lnav:
# Define a mnemonic to invoke the plugin
shortCut: Shift-L
# What will be shown on the K9s menu
description: Lnav the latest log file in /data/logs/*/
# Collections of views that support this shortcut. (You can use `all`)
scopes:
- po
# The command to run upon invocation. Can use Krew plugins here too!
command: sh
# Whether or not to run the command in background mode
background: false
# Defines the command arguments
args:
- -c
- |
if [ -n "${TMUX}" ]; then
tmux new-window -n 'lnav ($NAME)' "kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -c \"/usr/bin/lnav /data/logs/*/\\\$(ls -t /data/logs/*/ | grep -P '\\d{4}-\\d{2}-\\d{2}.*\\.(log|gz)' | head -1)\""
else
osascript -e '
tell app "iTerm2"
tell current window
create tab with default profile command "/usr/local/bin/kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -c '"'"'/usr/bin/lnav /data/logs/*/$(ls -t /data/logs/*/ | grep -P \"\\d{4}-\\d{2}-\\d{2}.*\\.(log|gz)\" | head -1)'"'"'"
end
end'
fi