-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkubepyrometer
More file actions
executable file
·200 lines (174 loc) · 6.25 KB
/
kubepyrometer
File metadata and controls
executable file
·200 lines (174 loc) · 6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env bash
set -uo pipefail
# Resolve the data directory containing templates, scripts, workloads, etc.
# Homebrew installs these under libexec/; repo checkout has them under lib/.
resolve_home() {
if [ -n "${KUBEPYROMETER_HOME:-}" ]; then
return 0
fi
# Follow symlinks to find the real location of this script.
local target="$0"
while [ -L "$target" ]; do
local link_dir
link_dir="$(cd "$(dirname "$target")" && pwd)"
target="$(readlink "$target")"
[[ "$target" != /* ]] && target="$link_dir/$target"
done
local self_dir
self_dir="$(cd "$(dirname "$target")" && pwd)"
# Homebrew layout: Cellar/<name>/<ver>/bin/kubepyrometer → ../libexec/kubepyrometer/
local brew_libexec="$self_dir/../libexec/kubepyrometer"
if [ -d "$brew_libexec/scripts" ]; then
KUBEPYROMETER_HOME="$(cd "$brew_libexec" && pwd)"
return 0
fi
# Repo checkout layout: kubepyrometer sits next to lib/
if [ -d "$self_dir/lib/scripts" ]; then
KUBEPYROMETER_HOME="$self_dir/lib"
return 0
fi
echo "ERROR: cannot locate KubePyrometer data directory."
echo "Set KUBEPYROMETER_HOME to the directory containing scripts/, templates/, etc."
exit 1
}
resolve_home
export KUBEPYROMETER_HOME
# VERSION lives at repo root (next to this script) or inside KUBEPYROMETER_HOME (Homebrew).
_script_dir="$(cd "$(dirname "$0")" && pwd)"
KUBEPYROMETER_VERSION="$(cat "$KUBEPYROMETER_HOME/VERSION" 2>/dev/null || cat "$_script_dir/VERSION" 2>/dev/null || echo "dev")"
unset _script_dir
# ---------------------------------------------------------------------------
# Config file search (for 'run' subcommand)
# -f flag > CONFIG_FILE env > ./kubepyrometer.yaml > ~/.kubepyrometer/config.yaml > built-in
# ---------------------------------------------------------------------------
resolve_config() {
[ -n "${CONFIG_FILE:-}" ] && return 0
if [ -f "./kubepyrometer.yaml" ]; then
export CONFIG_FILE="$(pwd)/kubepyrometer.yaml"
elif [ -f "$HOME/.kubepyrometer/config.yaml" ]; then
export CONFIG_FILE="$HOME/.kubepyrometer/config.yaml"
fi
}
# ---------------------------------------------------------------------------
# Usage
# ---------------------------------------------------------------------------
usage() {
cat <<EOF
kubepyrometer $KUBEPYROMETER_VERSION — Kubernetes control-plane load-testing harness
Usage:
kubepyrometer <command> [options]
Commands:
run Run the load-testing harness
analyze Analyze a completed run and explain results
init Generate a default config file in the current directory
summarize Generate summary CSVs from a run directory
monitor Start the cluster resource monitor
tui Launch interactive TUI (requires gum)
bundle Package run artifacts into a tarball
version Print version information
help Show this help message
Run 'kubepyrometer <command> --help' for more information on a command.
EOF
}
usage_run() {
cat <<EOF
Usage: kubepyrometer run [options]
Options:
-f CONFIG Config file path (default: ./kubepyrometer.yaml, ~/.kubepyrometer/config.yaml)
-o DIR Output directory for run artifacts (default: ./runs/<timestamp>)
-p PROFILE Load a built-in config profile (e.g., 'large')
-i Interactive mode (prompt for everything)
-c Prompt for contention mode selection
-r Prompt for image registry redirect
-h Show this help message
Config precedence: env vars > -p profile > -f config > built-in defaults
EOF
}
# ---------------------------------------------------------------------------
# Subcommands
# ---------------------------------------------------------------------------
cmd_run() {
resolve_config
exec bash "$KUBEPYROMETER_HOME/run.sh" "$@"
}
cmd_analyze() {
if [ $# -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: kubepyrometer analyze <run-dir>"
echo ""
echo "Analyze a completed run directory and produce a human-readable"
echo "breakdown of what happened, latency degradation, and failures."
[ $# -eq 0 ] && exit 1 || exit 0
fi
exec bash "$KUBEPYROMETER_HOME/scripts/analyze.sh" "$@"
}
cmd_init() {
local dest="${1:-kubepyrometer.yaml}"
if [ -f "$dest" ]; then
echo "Config file already exists: $dest"
echo "Remove it first or choose a different name."
exit 1
fi
cp "$KUBEPYROMETER_HOME/config.yaml" "$dest"
echo "Created $dest with default settings."
echo "Edit this file, then run: kubepyrometer run"
}
cmd_summarize() {
if [ $# -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: kubepyrometer summarize <run-dir>"
[ $# -eq 0 ] && exit 1 || exit 0
fi
exec bash "$KUBEPYROMETER_HOME/scripts/summarize.sh" "$@"
}
cmd_monitor() {
exec bash "$KUBEPYROMETER_HOME/scripts/cluster-monitor.sh" "$@"
}
cmd_bundle() {
if [ $# -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: kubepyrometer bundle <run-dir>"
[ $# -eq 0 ] && exit 1 || exit 0
fi
exec bash "$KUBEPYROMETER_HOME/scripts/bundle-run.sh" "$@"
}
cmd_tui() {
exec bash "$KUBEPYROMETER_HOME/scripts/v0tui.sh" "$@"
}
cmd_version() {
echo "kubepyrometer $KUBEPYROMETER_VERSION"
local kb=""
if [ -n "${KB_BIN:-}" ] && [ -x "$KB_BIN" ]; then
kb="$KB_BIN"
elif command -v kube-burner &>/dev/null; then
kb="$(command -v kube-burner)"
elif [ -x "$HOME/.kubepyrometer/bin/kube-burner" ]; then
kb="$HOME/.kubepyrometer/bin/kube-burner"
elif [ -x "$KUBEPYROMETER_HOME/bin/kube-burner" ]; then
kb="$KUBEPYROMETER_HOME/bin/kube-burner"
fi
if [ -n "$kb" ]; then
echo "kube-burner: $("$kb" version 2>&1 | head -1)"
else
echo "kube-burner: not installed (will be downloaded on first run)"
fi
}
# ---------------------------------------------------------------------------
# Dispatch
# ---------------------------------------------------------------------------
COMMAND="${1:-help}"
shift 2>/dev/null || true
case "$COMMAND" in
run) cmd_run "$@" ;;
analyze) cmd_analyze "$@" ;;
init) cmd_init "$@" ;;
summarize) cmd_summarize "$@" ;;
monitor) cmd_monitor "$@" ;;
bundle) cmd_bundle "$@" ;;
tui|-tui|--tui) cmd_tui "$@" ;;
version|-v|--version) cmd_version ;;
help|-h|--help) usage ;;
*)
echo "Unknown command: $COMMAND"
echo ""
usage
exit 1
;;
esac