-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
fix shellcheck failures in cluster/restore-from-backup.sh #79410
fix shellcheck failures in cluster/restore-from-backup.sh #79410
Conversation
@@ -76,9 +76,9 @@ wait_for_etcd_up() { | |||
# {"health": "true"} on /health endpoint in healthy case. | |||
# However, we should come with a regex for it to avoid future break. | |||
health_ok="{\"health\": \"true\"}" | |||
for i in $(seq 120); do | |||
for _ in $(seq 120); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these i
loop variables are unused placeholders to accomplish the seq loop, _
is clearer that we intend to ignore them and makes shellcheck happy.
apiserver=$(docker ps | grep apiserver | wc -l) | ||
for _ in $(seq 120); do | ||
etcd=$(docker ps | grep -c etcd-server) | ||
apiserver=$(docker ps | grep -c apiserver) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equivilant. more explicit & efficient
# TODO: Theoretically it is possible, that apiserver and or etcd | ||
# are currently down, but Kubelet is now restarting them and they | ||
# will reappear again. We should avoid it. | ||
if [ "${etcd}" -eq "0" -a "${apiserver}" -eq "0" ]; then | ||
if [ "${etcd}" -eq "0" ] && [ "${apiserver}" -eq "0" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test command is unspecified in POSIX with > 4 arguments. it's probably fine (?) in practice in bash even though we're using the posix test. but this is better & functionally equivilant.
this is the minimally equivalent-yet-more-correct form
@@ -153,16 +153,15 @@ if [ "${ETCD_API}" == "etcd2" ]; then | |||
mkdir -p "${BACKUP_DIR}/member/snap" | |||
mkdir -p "${BACKUP_DIR}/member/wal" | |||
# If the cluster is relatively new, there can be no .snap file. | |||
mv *.snap "${BACKUP_DIR}/member/snap/" || true | |||
mv *.wal "${BACKUP_DIR}/member/wal/" | |||
mv ./*.snap "${BACKUP_DIR}/member/snap/" || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*.snap
could become an argument if you had say -.snap
on disk. unprefixed globs are bad practice.
the leading ./
shouldn't be considered an argument by anything.
|
||
# TODO(jsz): This won't work with HA setups (e.g. do we need to set --name flag)? | ||
echo "Starting etcd ${ETCD_VERSION} to restore data" | ||
image=$(docker run -d -v ${BACKUP_DIR}:/var/etcd/data \ | ||
if ! image=$(docker run -d -v ${BACKUP_DIR}:/var/etcd/data \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
functionally equivalent, but avoids the pitfalls of trying to check $?
and potentially having it overwritten by something before you get to reading it.
@@ -54,8 +54,8 @@ if [ ! -f "${VERSION_FILE}" ]; then | |||
echo "2.2.1/etcd2" > "${VERSION_FILE}" | |||
fi | |||
VERSION_CONTENTS="$(cat ${VERSION_FILE})" | |||
ETCD_VERSION="$(echo $VERSION_CONTENTS | cut -d '/' -f 1)" | |||
ETCD_API="$(echo $VERSION_CONTENTS | cut -d '/' -f 2)" | |||
ETCD_VERSION="$(echo "$VERSION_CONTENTS" | cut -d '/' -f 1)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quote to avoid globbing/splitting/ per the comments above this should be a string of the form "binary-version/api-mode" like "2.2.1/etcd2" so we shouldn't have been wanting splitting / globbing here.
/assign @spiffxp |
/priority important-longterm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: BenTheElder, spiffxp The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind cleanup
What this PR does / why we need it: fixes shellcheck failures in
cluster/restore-from-backup.sh
Which issue(s) this PR fixes:
Part of #72956
Special notes for your reviewer:
Does this PR introduce a user-facing change?: