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

ARTESCA-9658 Fix retry ETCd backup #4197

Merged
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Remove `nodes-darwin` MacOS related grafana dashboard
(PR[4178](https://github.com/scality/metalk8s/pull/4178))

### Bug fixes

- Fix a bug in retry logic for ETCd backup
(PR[4197](https://github.com/scality/metalk8s/pull/4197))

## Release 125.0.6

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion scripts/backup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ replicate_archives() {

run "Backing up MetalK8s configurations" backup_metalk8s_conf
run "Backing up CAs certificates and keys" backup_cas
run_with_retry 12 5 "Backing up etcd data" backup_etcd
run "Backing up etcd data" with_retry 20 15 backup_etcd # try for 5 minutes (every 15 seconds, 20 times)
run "Creating backup archive '$BACKUP_ARCHIVE'" create_archive

if (( REPLICATION )); then
Expand Down
27 changes: 16 additions & 11 deletions scripts/common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -218,24 +218,29 @@ run() {
fi
}

run_with_retry() {
local retries=$1
local delay=$2
with_retry() {
local retries=$1 delay=$2
shift 2

local -i i=0
while true; do
if [[ $(( ++i )) -gt $retries ]]; then
die "Failed to run '$*' after ${retries} retries."
fi
for ((i = 1; i <= retries; i++)); do
echo "> Attempt ${i}/${retries}"

echo -n "> ${i}/${retries} "
if run "${@}"; then
break
local rctemp rc
rctemp=$(mktemp)
echo "$(set +e; "${@}"; echo -n $? > "$rctemp")"
rc=$(cat "$rctemp")
rm -f "$rctemp"

if [ "$rc" -eq 0 ]; then
echo "Succeed"
return 0
fi

echo "Failed"
sleep "${delay}"
done

die "Failed to run '$*' after ${retries} retries."
}

check_package_manager_yum() {
Expand Down
Loading