Skip to content

Commit

Permalink
Add a flag IS_DRY_RUN which will be used in Jenkins CI (CentaurusInfr…
Browse files Browse the repository at this point in the history
…a#372)

* Add a flag IS_DRY_RUN which is be used in Jenkins CI

* (Address comments) Add a flag IS_DRY_RUN which is be used in Jenkins CI

* Change a little wording
  • Loading branch information
Hong-Chang authored Jun 17, 2020
1 parent 5457cf7 commit fbb69df
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 20 deletions.
1 change: 1 addition & 0 deletions aws_kube_params.inc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export NUM_WINDOWS_NODES=0
export AWS_SSH_KEY=$HOME/.ssh/id_rsa

export PRESET_INSTANCES_ENABLED=false
export IS_PRESET_INSTANCES_DRY_RUN=false # In Preset instance, if it's dry run, then it only generates script but does not deploy.
export PRESET_KUBE_MASTER_IP=172.31.6.63
export PRESET_KUBE_MINION1_IP=172.31.11.206
# Uncomment next line and set minion2 ip to enable deploy 2-nodes cluster
Expand Down
57 changes: 37 additions & 20 deletions cluster/aws/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ fi
if [[ -z ${PRESET_INSTANCES_ENABLED:-} ]]; then
PRESET_INSTANCES_ENABLED=$FALSE
fi
if [[ -z ${IS_PRESET_INSTANCES_DRY_RUN:-} ]]; then
IS_PRESET_INSTANCES_DRY_RUN=$FALSE
fi
if [[ $PRESET_INSTANCES_ENABLED == $TRUE ]]; then
KUBE_MASTER_IP=$PRESET_KUBE_MASTER_IP
MASTER_INTERNAL_IP=$PRESET_KUBE_MASTER_IP
Expand Down Expand Up @@ -733,11 +736,13 @@ function upload-server-tars() {
SERVER_BINARY_TAR_URL=$PRESET_SERVER_BINARY_TAR_URL
BOOTSTRAP_SCRIPT_URL=$PRESET_BOOTSTRAP_SCRIPT_URL

scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${SERVER_BINARY_TAR} ${BOOTSTRAP_SCRIPT} ${SSH_USER}@${KUBE_MASTER_IP}:/tmp
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${SERVER_BINARY_TAR} ${BOOTSTRAP_SCRIPT} ${SSH_USER}@${KUBE_MINION1_IP}:/tmp
if [[ -n ${KUBE_MINION2_IP:-} ]]; then
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${SERVER_BINARY_TAR} ${BOOTSTRAP_SCRIPT} ${SSH_USER}@${KUBE_MINION2_IP}:/tmp
fi
if [[ $IS_PRESET_INSTANCES_DRY_RUN == $FALSE ]]; then
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${SERVER_BINARY_TAR} ${BOOTSTRAP_SCRIPT} ${SSH_USER}@${KUBE_MASTER_IP}:/tmp
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${SERVER_BINARY_TAR} ${BOOTSTRAP_SCRIPT} ${SSH_USER}@${KUBE_MINION1_IP}:/tmp
if [[ -n ${KUBE_MINION2_IP:-} ]]; then
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${SERVER_BINARY_TAR} ${BOOTSTRAP_SCRIPT} ${SSH_USER}@${KUBE_MINION2_IP}:/tmp
fi
fi
fi

echo "Uploaded server tars:"
Expand Down Expand Up @@ -1134,6 +1139,10 @@ function kube-up {
if [[ "${KUBE_CREATE_NODES}" == "true" ]]; then
# Start minions. The kube bootstrap script will be executed during minions starting.
start-minions

if [[ $PRESET_INSTANCES_ENABLED == $TRUE && $IS_PRESET_INSTANCES_DRY_RUN == $TRUE ]]; then
return
fi
if [[ $PRESET_INSTANCES_ENABLED != $TRUE ]]; then
wait-minions
fi
Expand Down Expand Up @@ -1273,6 +1282,8 @@ function start-master() {
echo "/etc/kubernetes/bootstrap > /tmp/bootstrap.log"
fi
) > "${KUBE_TEMP}/master-user-data"

cp ${KUBE_TEMP}/master-user-data /tmp/master-user-data

if [[ $PRESET_INSTANCES_ENABLED != $TRUE ]]; then
# Compress the data to fit under the 16KB limit (cloud-init accepts compressed data)
Expand Down Expand Up @@ -1334,11 +1345,13 @@ function start-master() {
echo "Started master: public_ip= $ip"
done
else
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${KUBE_TEMP}/master-user-data ${SSH_USER}@${KUBE_MASTER_IP}:/tmp
execute-ssh ${KUBE_MASTER_IP} "sudo mkdir -p /mnt/master-pd && chmod 755 /tmp/master-user-data && sudo /tmp/master-user-data"
execute-ssh ${KUBE_MASTER_IP} "sudo /etc/kubernetes/bootstrap &>/tmp/bootstrap.log & disown"
if [[ $IS_PRESET_INSTANCES_DRY_RUN == $FALSE ]]; then
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${KUBE_TEMP}/master-user-data ${SSH_USER}@${KUBE_MASTER_IP}:/tmp
execute-ssh ${KUBE_MASTER_IP} "sudo mkdir -p /mnt/master-pd && chmod 755 /tmp/master-user-data && sudo /tmp/master-user-data"
execute-ssh ${KUBE_MASTER_IP} "sudo /etc/kubernetes/bootstrap &>/tmp/bootstrap.log & disown"

echo "Master is running: public_ip= $KUBE_MASTER_IP"
echo "Master is running: public_ip= $KUBE_MASTER_IP"
fi
fi
}

Expand Down Expand Up @@ -1384,6 +1397,8 @@ function start-minions() {
fi
) > "${KUBE_TEMP}/node-user-data"

cp ${KUBE_TEMP}/node-user-data /tmp/node-user-data

if [[ $PRESET_INSTANCES_ENABLED != $TRUE ]]; then
# Compress the data to fit under the 16KB limit (cloud-init accepts compressed data)
gzip "${KUBE_TEMP}/node-user-data"
Expand Down Expand Up @@ -1423,17 +1438,19 @@ function start-minions() {
ResourceId=${ASG_NAME},ResourceType=auto-scaling-group,Key=Role,Value=${NODE_TAG} \
ResourceId=${ASG_NAME},ResourceType=auto-scaling-group,Key=KubernetesCluster,Value=${CLUSTER_ID}
else
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${KUBE_TEMP}/node-user-data ${SSH_USER}@${KUBE_MINION1_IP}:/tmp
execute-ssh ${KUBE_MINION1_IP} "chmod 755 /tmp/node-user-data && sudo /tmp/node-user-data"
execute-ssh ${KUBE_MINION1_IP} "sudo /etc/kubernetes/bootstrap"
echo "Minion1 is running"

if [[ -n ${KUBE_MINION2_IP:-} ]]; then
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${KUBE_TEMP}/node-user-data ${SSH_USER}@${KUBE_MINION2_IP}:/tmp
execute-ssh ${KUBE_MINION2_IP} "chmod 755 /tmp/node-user-data && sudo /tmp/node-user-data"
execute-ssh ${KUBE_MINION2_IP} "sudo /etc/kubernetes/bootstrap"
echo "Minion2 is running"
fi
if [[ $IS_PRESET_INSTANCES_DRY_RUN == $FALSE ]]; then
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${KUBE_TEMP}/node-user-data ${SSH_USER}@${KUBE_MINION1_IP}:/tmp
execute-ssh ${KUBE_MINION1_IP} "chmod 755 /tmp/node-user-data && sudo /tmp/node-user-data"
execute-ssh ${KUBE_MINION1_IP} "sudo /etc/kubernetes/bootstrap"
echo "Minion1 is running"

if [[ -n ${KUBE_MINION2_IP:-} ]]; then
scp -o 'StrictHostKeyChecking no' -i ${ACCESS_FILE} ${KUBE_TEMP}/node-user-data ${SSH_USER}@${KUBE_MINION2_IP}:/tmp
execute-ssh ${KUBE_MINION2_IP} "chmod 755 /tmp/node-user-data && sudo /tmp/node-user-data"
execute-ssh ${KUBE_MINION2_IP} "sudo /etc/kubernetes/bootstrap"
echo "Minion2 is running"
fi
fi
fi
}

Expand Down
5 changes: 5 additions & 0 deletions cluster/kube-up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ verify-release-tars
echo "... calling kube-up" >&2
kube-up

if [[ "${PRESET_INSTANCES_ENABLED:-}" == $TRUE && "${IS_PRESET_INSTANCES_DRY_RUN:-}" == $TRUE ]]; then
echo "Dry run of kube-up completed"
exit 0
fi

echo "... calling validate-cluster" >&2
# Override errexit
(validate-cluster) && validate_result="$?" || validate_result="$?"
Expand Down

0 comments on commit fbb69df

Please sign in to comment.