Skip to content

Commit a139fa3

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 3c307ea commit a139fa3

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

builder/bin/boot

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ done
2626
sleep $(($ETCD_TTL+1))
2727

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

3238
etcd_safe_mkdir $ETCD_PATH/users

controller/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}

database/bin/boot

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ done
3131
sleep $(($ETCD_TTL+1))
3232

3333
function etcd_set_default {
34-
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
34+
set +e
35+
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
36+
if [[ $? -ne 0 && $? -ne 4 ]]; then
37+
echo "etcd_set_default: an etcd error occurred. aborting..."
38+
exit 1
39+
fi
40+
set -e
3541
}
3642

3743
etcd_set_default engine postgresql_psycopg2

registry/bin/boot

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ done
3030
sleep $(($ETCD_TTL+1))
3131

3232
function etcd_set_default {
33-
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
33+
set +e
34+
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
35+
if [[ $? -ne 0 && $? -ne 4 ]]; then
36+
echo "etcd_set_default: an etcd error occurred. aborting..."
37+
exit 1
38+
fi
39+
set -e
3440
}
3541

3642
# seed initial service configuration if necessary

store/monitor/bin/boot

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ PG_NUM=${PG_NUM:-128} # default for 3 OSDs
1111
HOSTNAME=`hostname`
1212

1313
function etcd_set_default {
14-
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1 || true
14+
set +e
15+
etcdctl --no-sync -C $ETCD mk $ETCD_PATH/$1 $2 >/dev/null 2>&1
16+
if [[ $? -ne 0 && $? -ne 4 ]]; then
17+
echo "etcd_set_default: an etcd error occurred. aborting..."
18+
exit 1
19+
fi
20+
set -e
1521
}
1622

1723
if ! etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/monSetupComplete >/dev/null 2>&1 ; then

0 commit comments

Comments
 (0)