Last active
July 26, 2021 12:59
-
-
Save navarrothiago/6f54deeb583694b550f89b2c400491c5 to your computer and use it in GitHub Desktop.
Tmux Session for Cilium Development Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ============================================== | |
# Author: Thiago Navarro | |
# email: navarro.ime@gmail.com | |
# | |
# Create a grid (panes) | |
# Login left pane on k8s1 | |
# Login right pane on k8s2 (if its running) | |
# | |
# Dependencies: tmux, cilium, vagrant | |
# | |
# TODO: | |
#============================================= | |
CMD_LOGIN_K8s1="ssh vagrant@127.0.0.1 -p 2222" | |
CMD_LOGIN_K8s2="ssh vagrant@127.0.0.1 -p 2200" | |
CMD_BPFTOOL_PROG_TRACE="sudo bpftool prog trace" | |
CMD_RESTART_CILIUM_SERVICES="sudo systemctl restart cilium-operator.service cilium.service cilium-consul.service cilium-docker.service" | |
CMD_START_CILIUM_MONITOR="sleep 20; cilium monitor --verbose" | |
CMD_TAIL_CILIUM_MONITOR_K8s1="sleep 20; cilium monitor --verbose | tee tmp/logs/cilium/k8s1-monitor.txt" | |
CMD_TAIL_CILIUM_MONITOR_K8s2="sleep 20; cilium monitor --verbose | tee tmp/logs/cilium/k8s2-monitor.txt" | |
CMD_TAIL_CILIUM_SYSLOG_K8s1="tail -f /var/log/syslog | tee tmp/logs/cilium/k8s1-syslog.txt" | |
CMD_TAIL_CILIUM_SYSLOG_K8s2="tail -f /var/log/syslog | tee tmp/logs/cilium/k8s2-syslog.txt" | |
CMD_TAIL_CILIUM_ENVOY_K8s1="tail -f tmp/envoy/k8s1-logs.txt" | |
CMD_TAIL_CILIUM_ENVOY_K8s2="tail -f tmp/envoy/k8s2-logs.txt" | |
CMD_TAT_CILIUM_ENVOY_K8s1="wine /work/TextAnalysisTool.NET/TextAnalysisTool.NET.exe /Filters:/work/TextAnalysisTool.NET/cilium-envoy.tat /work/accuknox/cilium/tmp/envoy/k8s1-logs.txt" | |
CMD_TAT_CILIUM_ENVOY_K8s2="wine /work/TextAnalysisTool.NET/TextAnalysisTool.NET.exe /Filters:/work/TextAnalysisTool.NET/cilium-envoy.tat /work/accuknox/cilium/tmp/envoy/k8s2-logs.txt" | |
CMD_TAT_CILIUM_SYSLOG_K8s1="wine /work/TextAnalysisTool.NET/TextAnalysisTool.NET.exe /Filters:/work/TextAnalysisTool.NET/cilium-spire.tat /work/accuknox/cilium/tmp/logs/cilium/k8s1-syslog.txt" | |
CMD_TAT_CILIUM_SYSLOG_K8s2="wine /work/TextAnalysisTool.NET/TextAnalysisTool.NET.exe /Filters:/work/TextAnalysisTool.NET/cilium-spire.tat /work/accuknox/cilium/tmp/logs/cilium/k8s2-syslog.txt" | |
CMD_TAT_CILIUM_MONITOR_K8s1="sleep 21; wine /work/TextAnalysisTool.NET/TextAnalysisTool.NET.exe /Filters:/work/TextAnalysisTool.NET/cilium-monitor.tat /work/accuknox/cilium/tmp/logs/cilium/k8s1-monitor.txt" | |
CMD_TAT_CILIUM_MONITOR_K8s2="sleep 21; wine /work/TextAnalysisTool.NET/TextAnalysisTool.NET.exe /Filters:/work/TextAnalysisTool.NET/cilium-monitor.tat /work/accuknox/cilium/tmp/logs/cilium/k8s2-monitor.txt" | |
CMD_REMOVE_CILIUM_ENVOY_K8s1="rm tmp/envoy/k8s1-logs.txt" | |
CMD_REMOVE_CILIUM_ENVOY_K8s2="rm tmp/envoy/k8s2-logs.txt" | |
get_vagrant_vm_status() { | |
local name=$1 | |
local ret=$(vagrant status | grep "${name}" | awk '{print $2}') | |
echo ""${ret}"" | |
} | |
#Create remote session with panes | |
initialize() { | |
echo "Initializing on session "${session_name}"..." | |
# Initialize windowns and panes | |
tmux kill-session -t $session_name -n testbed 2>/dev/null | |
# Create window 0 | |
tmux -2 new-session -d -s $session_name | |
tmux rename-window -t 0 'k8s' | |
# Create window 1 | |
tmux new-window -d -t $session_name -n 'Local' | |
# Create window 2 | |
tmux new-window -d -t $session_name -n 'TextAnalisysTool' | |
# Create window 3 | |
tmux new-window -d -t $session_name -n 'Demo' | |
# Configure layout | |
tmux split-window -t $session_name:0.0 -v \; selectl tiled | |
tmux split-window -t $session_name:0.1 -v \; selectl tiled | |
tmux split-window -t $session_name:0.2 -v \; selectl tiled | |
tmux split-window -t $session_name:0.3 -v \; selectl tiled | |
tmux split-window -t $session_name:2.0 -v \; selectl tiled | |
tmux split-window -t $session_name:2.1 -v \; selectl tiled | |
tmux select-layout -t $session_name even-vertical | |
tmux split-window -t $session_name:3.0 -v | |
local k8s1_pane=(0 1 2 3 4) | |
local k8s2_pane=(1 3 5 7 9) | |
local k8s2_status=$(get_vagrant_vm_status k8s2+) | |
if [ "${k8s2_status}" == "running" ]; then | |
tmux split-window -t $session_name:0.0 -h | |
tmux split-window -t $session_name:0.2 -h | |
tmux split-window -t $session_name:0.4 -h | |
tmux split-window -t $session_name:0.6 -h | |
tmux split-window -t $session_name:0.8 -h | |
k8s1_pane=(0 2 4 6 8) | |
# create logs panes | |
tmux split-window -t $session_name:2.1 -v \; selectl tiled | |
tmux split-window -t $session_name:2.2 -v \; selectl tiled | |
tmux split-window -t $session_name:2.3 -v \; selectl tiled | |
fi | |
# Select window 0 pane 2 | |
tmux select-pane -t "$session_name":0.2 | |
# Login K8s1 | |
for value in "${k8s1_pane[@]}"; do | |
tmux send-keys -t $session_name:0."${value}" "${CMD_LOGIN_K8s1}" C-m | |
done | |
tmux send-keys -t $session_name:3.0 "${CMD_LOGIN_K8s1}" C-m | |
# Login K8s2 | |
if [ "${k8s2_status}" == "running" ]; then | |
for value in "${k8s2_pane[@]}"; do | |
tmux send-keys -t $session_name:0."${value}" "${CMD_LOGIN_K8s2}" C-m | |
done | |
fi | |
tmux send-keys -t $session_name:3.1 "${CMD_LOGIN_K8s2}" C-m | |
# Run commands k8s1 | |
tmux send-keys -t $session_name:0.${k8s1_pane[1]} "${CMD_RESTART_CILIUM_SERVICES}" C-m | |
tmux send-keys -t $session_name:0.${k8s1_pane[2]} "${CMD_TAIL_CILIUM_MONITOR_K8s1}" C-m | |
tmux send-keys -t $session_name:0.${k8s1_pane[3]} "${CMD_TAIL_CILIUM_ENVOY_K8s1}" C-m | |
tmux send-keys -t $session_name:0.${k8s1_pane[4]} "${CMD_TAIL_CILIUM_SYSLOG_K8s1}" C-m | |
tmux send-keys -t $session_name:2.0 "${CMD_TAT_CILIUM_SYSLOG_K8s1}" C-m | |
tmux send-keys -t $session_name:2.1 "${CMD_TAT_CILIUM_ENVOY_K8s1}" C-m | |
tmux send-keys -t $session_name:2.2 "${CMD_TAT_CILIUM_MONITOR_K8s1}" C-m | |
if [ "${k8s2_status}" == "running" ]; then | |
# Run commands k8s2 | |
tmux send-keys -t $session_name:0.${k8s2_pane[1]} "${CMD_RESTART_CILIUM_SERVICES}" C-m | |
tmux send-keys -t $session_name:0.${k8s2_pane[2]} "${CMD_TAIL_CILIUM_MONITOR_K8s2}" C-m | |
tmux send-keys -t $session_name:0.${k8s2_pane[3]} "${CMD_TAIL_CILIUM_ENVOY_K8s2}" C-m | |
tmux send-keys -t $session_name:0.${k8s2_pane[4]} "${CMD_TAIL_CILIUM_SYSLOG_K8s2}" C-m | |
tmux send-keys -t $session_name:2.3 "${CMD_TAT_CILIUM_SYSLOG_K8s2}" C-m | |
tmux send-keys -t $session_name:2.4 "${CMD_TAT_CILIUM_ENVOY_K8s2}" C-m | |
tmux send-keys -t $session_name:2.5 "${CMD_TAT_CILIUM_MONITOR_K8s2}" C-m | |
fi | |
} | |
attach() { | |
echo "Attaching on session "${session_name}"..." | |
tmux select-pane -t $session_name:0.0 | |
tmux -2 attach-session -t $session_name | |
} | |
stop() { | |
echo "Stopping on session "${session_name}"..." | |
# Clean envoy logs | |
tmux send-keys -t $session_name:2.1 "${CMD_REMOVE_CILIUM_ENVOY_K8s1}" C-m | |
tmux send-keys -t $session_name:2.3 "${CMD_REMOVE_CILIUM_ENVOY_K8s2}" C-m | |
} | |
force_kill() { | |
echo "Killing on session "${session_name}"..." | |
#sleep 1 | |
tmux kill-session -t $session_name 2>/dev/null | |
} | |
main() { | |
# set -o errexit | |
set -o pipefail | |
set -o nounset | |
# set -x | |
local -r dirname="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
local -r filename="${dirname}/$(basename "${BASH_SOURCE[0]}")" | |
local -r session_name="cilium" | |
# Enable nested tmux session. | |
unset TMUX | |
initialize | |
attach | |
stop | |
force_kill | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment