Skip to content

Commit

Permalink
Merge pull request #127 from kubernetes-simulator/run-once
Browse files Browse the repository at this point in the history
add locking to ensure perturb only run once
  • Loading branch information
jondkent authored Dec 2, 2019
2 parents 2e8864d + 35e85aa commit b48feba
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions simulation-scripts/perturb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ is_special_scenario() {
run_scenario() {
local SCENARIO_DIR="${1}"

if previously_perturbed ;then
error "Perturbed has been previously run on this cluster"
fi

warning "Instructions in scenario:"
ls -lasp "${SCENARIO_DIR}"

Expand All @@ -127,6 +131,8 @@ run_scenario() {
get_pods

copy_challenge_and_tasks "${SCENARIO_DIR}"

lock_perturb
}

get_pods() {
Expand Down Expand Up @@ -212,6 +218,24 @@ template_challenge() {
fi
}

previously_perturbed() {
ssh \
-F "${SSH_CONFIG_FILE}" \
-o "StrictHostKeyChecking=no" \
-o "UserKnownHostsFile=/dev/null" \
-o "ConnectTimeout 3" \
root@${MASTER_HOST} "[ -f /tmp/perturbed.lock ] && true || false"
}

lock_perturb() {
ssh \
-F "${SSH_CONFIG_FILE}" \
-o "StrictHostKeyChecking=no" \
-o "UserKnownHostsFile=/dev/null" \
-o "ConnectTimeout 3" \
root@${MASTER_HOST} "touch /tmp/perturbed.lock"
}

validate_instructions() {
local SCENARIO_DIR="${1}"

Expand Down

0 comments on commit b48feba

Please sign in to comment.