Skip to content

Commit

Permalink
Merge pull request #17 from projectsyn/fix-16
Browse files Browse the repository at this point in the history
Don't write output if nothing goes wrong
  • Loading branch information
TheBigLee authored Jun 21, 2021
2 parents 45d748b + 365f594 commit f7803a7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ useridentitymappings
validations
```

To enable informative logging output for non-error cases, set `$DEBUG` to a non-empty value.

## Contributing and license

This library is licensed under [BSD-3-Clause](LICENSE).
Expand Down
22 changes: 13 additions & 9 deletions dump-objects
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ fi
# Remove old files
find "$output_dir" -mindepth 1 -maxdepth 1 -type f -delete

log() {
test -n "$DEBUG" && echo "$@" >&2
}

delay_attempt() {
local attempt="$1"
local msg="$2"
Expand All @@ -74,7 +78,7 @@ delay_attempt() {
else
delay=$(( 1 + ( (1 + attempt) ** 5) ))
fi
echo "Pausing for ${delay} seconds: ${msg}" >&2
log "Pausing for ${delay} seconds: ${msg}" >&2
sleep "$delay" || :
}

Expand Down Expand Up @@ -231,7 +235,7 @@ fetch_objects() {
# Capture stderr
if error=$(run_kubectl get --all-namespaces --output=json "$kind" 2>&1 >"$destfile" | tee -a /dev/stderr); then
if objcount=$(jq --raw-output '.items | length' < "$destfile"); then
echo "Received ${objcount} ${kind} objects" >&2
log "Received ${objcount} ${kind} objects"
return 0
fi
else
Expand All @@ -240,7 +244,7 @@ fetch_objects() {
local errprefix=

if verbose; then
echo "Kubernetes client failed with status ${status}" >&2
log "Kubernetes client failed with status ${status}"
errprefix='[^]]+ *[-_a-z0-9]+\.go:[0-9]+] *'
fi

Expand Down Expand Up @@ -306,7 +310,7 @@ split_objects() {
# Remove old files
find "$splitdir" -mindepth 1 -type f -name '*.json' -delete

echo "Splitting ${#} JSON files" >&2
log "Splitting ${#} JSON files"

if krossa "$splitdir" "$@"; then
# Remove empty directories
Expand Down Expand Up @@ -366,7 +370,7 @@ if ! validate_kinds "${kinds[@]}"; then
let ++errors
fi

echo "Fetching resources for ${#kinds[@]} distinct kinds: ${kinds[*]}" >&2
log "Fetching resources for ${#kinds[@]} distinct kinds: ${kinds[*]}"

declare -i idx=0
declare -a object_files=()
Expand All @@ -376,12 +380,12 @@ for i in "${kinds[@]}"; do

if [[ "$i" == */* ]]; then
if verbose; then
echo "${prefix}Skipping subresource" >&2
log "${prefix}Skipping subresource"
fi
continue
fi

echo "${prefix}Downloading" >&2
log "${prefix}Downloading"

if retrievable_kind "$i"; then
retrievable=yes
Expand All @@ -404,7 +408,7 @@ for i in "${kinds[@]}"; do
echo "Download failed with status ${status} when resource kind \"${i}\" is expected to be retrievable" >&2
status=1
else
echo "Ignoring error about unretrievable resource kind" >&2
log "Ignoring error about unretrievable resource kind"
status=0
fi
elif [[ -z "$retrievable" ]]; then
Expand Down Expand Up @@ -437,7 +441,7 @@ if (( errors > 0 )); then
exit 1
fi

echo 'K8s backup finished without errors' >&2
log 'K8s backup finished without errors'

exit 0

Expand Down

0 comments on commit f7803a7

Please sign in to comment.