Skip to content

Commit

Permalink
Make kubectl get chunk size configurable
Browse files Browse the repository at this point in the history
Also reduce chunk size to 100 (from 500) by default to reduce `kubectl`
memory usage when dumping resource kinds with large individual
resources.
  • Loading branch information
simu committed Aug 5, 2024
1 parent 57261cf commit ad62e8b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions dump-objects
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ usage() {
echo " -d Destination directory (default: ${default_output_dir})"
echo ' -s Short delays in case of failures'
echo ' -D enable Debug log'
echo ' -c kubectl chunk size'
}

output_dir="$default_output_dir"
opt_verbose=
opt_debug=false
opt_fastretries=
# Reduce default kubectl --chunk-size to 100 to reduce kubectl memory usage when
# dumping large resource kinds.
opt_chunk_size=100

while getopts 'hvd:Ds' opt; do
while getopts 'hvd:Dsc:' opt; do
case "$opt" in
h)
usage
Expand All @@ -50,6 +54,7 @@ while getopts 'hvd:Ds' opt; do
d) output_dir="$OPTARG" ;;
s) opt_fastretries=yes ;;
D) opt_debug=true ;;
c) opt_chunk_size="$OPTARG" ;;
*)
usage >&2
exit 1
Expand Down Expand Up @@ -241,7 +246,7 @@ fetch_objects() {
local error=

# Capture stderr
if error=$(run_kubectl get --all-namespaces --output=json "$kind" 2>&1 >"$destfile" | tee -a /dev/stderr); then
if error=$(run_kubectl get --all-namespaces --chunk-size="$opt_chunk_size" --output=json "$kind" 2>&1 >"$destfile" | tee -a /dev/stderr); then
if objcount=$(jq --raw-output '.items | length' < "$destfile"); then
log "Received ${objcount} ${kind} objects"
return 0
Expand Down

0 comments on commit ad62e8b

Please sign in to comment.