Skip to content

Commit 99696a6

Browse files
committed
fix(*): etcd_set_default and etcd_safe_mkdir raise some errors
Currently, both `etcd_set_default` and `etcd_safe_mkdir` in the /bin/boot scripts never fail due to `|| true`. This is usually desired because if the key already exists, we don't want to overwrite it. However, if there is an underlying error connecting to etcd, we swallow that as well. This commit exploits the fact that `etcdctl` has different exit codes for key errors and etcd errors to swallow only the errors we wish to.
1 parent 51d4d03 commit 99696a6

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

bin/boot

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,23 @@ done
2525
sleep $(($ETCD_TTL+1))
2626

2727
function etcd_set_default {
28-
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
28+
set +e
29+
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
30+
if [[ $? -ne 0 && $? -ne 4 ]]; then
31+
echo "etcd_set_default: an etcd error occurred. aborting..."
32+
exit 1
33+
fi
34+
set -e
2935
}
3036

3137
function etcd_safe_mkdir {
32-
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1 || true
38+
set +e
39+
etcdctl --no-sync -C $ETCD mkdir $1 >/dev/null 2>&1
40+
if [[ $? -ne 0 && $? -ne 4 ]]; then
41+
echo "etcd_safe_mkdir: an etcd error occurred. aborting..."
42+
exit 1
43+
fi
44+
set -e
3345
}
3446

3547
etcd_set_default protocol ${DEIS_PROTOCOL:-http}

0 commit comments

Comments
 (0)