Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make kubectl get chunk size configurable #45

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions dump-objects
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ readonly EX_PROTOCOL=76
readonly min_expected_kinds=98

default_output_dir=/data/k8s-backup
# Use kubectl --chunk-size=100 by default to reduce kubectl memory usage when
# dumping large resource kinds.
default_chunk_size=100

if ! kubectl=$(type -p kubectl); then
echo "K8s client \"kubectl\" not found in PATH" >&2
Expand All @@ -33,14 +36,16 @@ 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 (default: ${default_chunk_size})"
}

output_dir="$default_output_dir"
opt_verbose=
opt_debug=false
opt_fastretries=
opt_chunk_size="$default_chunk_size"

while getopts 'hvd:Ds' opt; do
while getopts 'hvd:Dsc:' opt; do
case "$opt" in
h)
usage
Expand All @@ -50,6 +55,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 +247,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