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

adapt error handling #40

Merged
merged 2 commits into from
May 15, 2019
Merged
Changes from 1 commit
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
15 changes: 11 additions & 4 deletions image/tools/lib/component/resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function check_resource {
# was returned but no actual results. That would be at
# least two lines: one for the header and one for each
# resource found
if [ "$result" -eq "1" ]; then
if [[ "$result" -eq "1" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you had to change it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My IDE suggests this, no immediate reason though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous way (one []) is posix standard which enables people with non linux machines to run those scripts locally (such as macs) - could you please revert it to the old way?

echo "==> No $type in $ns to back up"
return 1
else
Expand All @@ -26,11 +26,16 @@ function backup_resource {
local type=$1
local ns=$2
local dest=$3
local loop=$4
local loop=${4-default}

# Disable extended error checks. The check_resource function relies on a non-zero
# return code, which is interpreted as a failed command and causes the script to be
# terminated with the '-e' option
set +eo pipefail
odra marked this conversation as resolved.
Show resolved Hide resolved
check_resource ${type} ${ns}
if [ "$?" -eq "0" ]; then
if [[ "$?" -eq "0" ]]; then
echo "==> backing up $type in $ns"
if [[ "$loop" ]]; then
if [[ "$loop" == "y" ]]; then
echo '---' > /tmp/${type}.yaml
for obj in $(oc get ${type} -n ${ns} | tr -s ' ' | cut -d ' ' -f 1 | tail -n +2); do
echo '-' >> /tmp/${type}.yaml
Expand All @@ -42,6 +47,8 @@ function backup_resource {
oc get ${type} -n ${ns} -o yaml --export | gzip > ${dest}/archives/${ns}-${type}.yaml.gz
fi
fi
# Re-enable extended error checks
set -eo pipefail
}

# Backs up a namespace
Expand Down