Skip to content

Commit 7db37c5

Browse files
author
Tom Barnes
committed
more instrumenation, plus use file instead of stdin for replace -f call
1 parent 40ce950 commit 7db37c5

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

src/integration-tests/bash/lease.sh

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,41 @@ EOF
287287
fi
288288
}
289289

290+
function makeLocalLeaseAndReplaceRemote {
291+
# TODO remote set +x/-x
292+
set +x
293+
makeLocalLease
294+
if [ $? -ne 0 ]; then
295+
traceError "failed - could not generate a new local lease"
296+
return 1
297+
fi
298+
299+
local tempcf=${LOCAL_ROOT}/tempcf.yaml
300+
301+
# next, try replace remote lease with the candidate lease
302+
kubectl create configmap ${CONFIGMAP_NAME} --from-file ${LOCAL_ROOT}/${LOCAL_FILE} -o yaml -n default --dry-run > tempcf.yaml
303+
if [ $? -ne 0 ]; then
304+
traceError "failed - could not generate config map yaml"
305+
return 1
306+
fi
307+
308+
kubectl replace -f $tempcf
309+
if [ $? -ne 0 ]; then
310+
traceError "failed - could not get replace remote lease"
311+
return 1
312+
fi
313+
314+
# finally, check if we now actually own the lease (someone could have been replacing at the same time)
315+
checkLease
316+
if [ $? -eq 0 ]; then
317+
return 0
318+
else
319+
traceError "failed - replaced remote lease, but we somehow lost a race or can no longer communicate with kubernetes"
320+
return 1
321+
fi
322+
set -x
323+
}
324+
290325
function getRemoteLease {
291326
#
292327
# first, if the remote lease configmap doesn't exist
@@ -397,25 +432,11 @@ function obtainLease {
397432
# so assume it can be replaced and we can try takeover the lease
398433

399434
# first make a local candidate lease
400-
makeLocalLease
401-
if [ $? -ne 0 ]; then
402-
traceError "failed - could not generate a new local lease"
403-
return 1
404-
fi
405-
406-
# next, try replace remote lease with the candidate lease
407-
kubectl create configmap ${CONFIGMAP_NAME} --from-file ${LOCAL_ROOT}/${LOCAL_FILE} -o yaml -n default --dry-run | kubectl replace -f -
408-
if [ $? -ne 0 ]; then
409-
traceError "failed - could not replace remote lease"
410-
return 1
411-
fi
412-
413-
# finally, check if we now actually own the lease (someone could have been replacing at the same time)
414-
checkLease
435+
makeLocalLeaseAndReplaceRemote
415436
if [ $? -eq 0 ]; then
416437
return 0
417438
else
418-
traceError "failed - replaced remote lease, but kubernetes is not responding or we lost a race and another potential owner replaced it too, will keep retrying up to the timeout"
439+
traceError "failed to replace remote lease, will keep retrying up to the timeout"
419440
fi
420441
fi
421442
local mnow=`date +%s`
@@ -449,26 +470,12 @@ function renewLease {
449470
fi
450471

451472
# now make a new local candidate lease
452-
makeLocalLease
453-
if [ $? -ne 0 ]; then
454-
traceError "failed - could not generate a new local lease"
455-
return 1
456-
fi
457-
458-
# next, try replace remote lease with the candidate lease
459-
kubectl create configmap ${CONFIGMAP_NAME} --from-file ${LOCAL_ROOT}/${LOCAL_FILE} -o yaml -n default --dry-run | kubectl replace -f -
473+
makeLocalLeaseAndReplaceRemote
460474
if [ $? -ne 0 ]; then
461-
traceError "failed - could not get replace remote lease"
475+
traceError "failed to replace remote lease"
462476
return 1
463-
fi
464-
465-
# finally, check if we now actually own the lease (someone could have been replacing at the same time)
466-
checkLease
467-
if [ $? -eq 0 ]; then
468-
return 0
469477
else
470-
traceError "failed - replaced remote lease, but we somehow lost a race or can no longer communicate with kubernetes"
471-
return 1
478+
return 0
472479
fi
473480
}
474481

wercker.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ integration-test:
141141
# - finally, run.sh will periodically try renew the lease as it runs (using $LEASE_ID)
142142
# - if run.sh fails when it tries to renew the lease (as something else took it, etc), it will exit early
143143
# - when run.sh exits, it will try release the lease if it's still the owner...
144-
set -x
145144
export LEASE_ID="${WERCKER_STEP_ID}-pid$$"
146145
echo @@
147146
echo @@ "Obtaining lease!"
@@ -158,7 +157,6 @@ integration-test:
158157
echo @@ "About to try obtain lease:"
159158
$WERCKER_SOURCE_DIR/src/integration-tests/bash/lease.sh -o "$LEASE_ID" -t $((100 * 60))
160159
echo @@
161-
set +x
162160
163161
# create pull secrets
164162
echo @@ "Creating pull secrets"

0 commit comments

Comments
 (0)