Merge pull request #1142 from jbeda/tweak-demo

Improve update demo, support rolling template update
This commit is contained in:
Daniel Smith
2014-09-05 10:07:58 -07:00
35 changed files with 541 additions and 205 deletions

View File

@@ -24,7 +24,7 @@ source "${KUBE_REPO_ROOT}/cluster/kube-env.sh"
source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
# Launch a container
$CLOUDCFG -p 8080:80 run dockerfile/nginx 2 myNginx
$KUBECFG -p 8080:80 run dockerfile/nginx 2 myNginx
function remove-quotes() {
local in=$1
@@ -35,13 +35,13 @@ function remove-quotes() {
function teardown() {
echo "Cleaning up test artifacts"
$CLOUDCFG stop myNginx
$CLOUDCFG rm myNginx
$KUBECFG stop myNginx
$KUBECFG rm myNginx
}
trap "teardown" EXIT
POD_ID_LIST=$($CLOUDCFG '-template={{range.Items}}{{.ID}} {{end}}' -l name=myNginx list pods)
POD_ID_LIST=$($KUBECFG '-template={{range.Items}}{{.ID}} {{end}}' -l name=myNginx list pods)
# Container turn up on a clean cluster can take a while for the docker image pull.
ALL_RUNNING=0
while [ $ALL_RUNNING -ne 1 ]; do
@@ -49,7 +49,7 @@ while [ $ALL_RUNNING -ne 1 ]; do
sleep 5
ALL_RUNNING=1
for id in $POD_ID_LIST; do
CURRENT_STATUS=$($CLOUDCFG -template '{{and .CurrentState.Info.mynginx.State.Running .CurrentState.Info.net.State.Running}}' get pods/$id)
CURRENT_STATUS=$($KUBECFG -template '{{and .CurrentState.Info.mynginx.State.Running .CurrentState.Info.net.State.Running}}' get pods/$id)
if [ "$CURRENT_STATUS" != "true" ]; then
ALL_RUNNING=0
fi

View File

@@ -26,23 +26,23 @@ source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
GUESTBOOK="${KUBE_REPO_ROOT}/examples/guestbook"
# Launch the guestbook example
$CLOUDCFG -c "${GUESTBOOK}/redis-master.json" create /pods
$CLOUDCFG -c "${GUESTBOOK}/redis-master-service.json" create /services
$CLOUDCFG -c "${GUESTBOOK}/redis-slave-controller.json" create /replicationControllers
$KUBECFG -c "${GUESTBOOK}/redis-master.json" create /pods
$KUBECFG -c "${GUESTBOOK}/redis-master-service.json" create /services
$KUBECFG -c "${GUESTBOOK}/redis-slave-controller.json" create /replicationControllers
sleep 5
POD_LIST_1=$($CLOUDCFG '-template={{range.Items}}{{.ID}} {{end}}' list pods)
POD_LIST_1=$($KUBECFG '-template={{range.Items}}{{.ID}} {{end}}' list pods)
echo "Pods running: ${POD_LIST_1}"
$CLOUDCFG stop redisSlaveController
$KUBECFG stop redisSlaveController
# Needed until issue #103 gets fixed
sleep 25
$CLOUDCFG rm redisSlaveController
$CLOUDCFG delete services/redismaster
$CLOUDCFG delete pods/redis-master-2
$KUBECFG rm redisSlaveController
$KUBECFG delete services/redismaster
$KUBECFG delete pods/redis-master-2
POD_LIST_2=$($CLOUDCFG '-template={{range.Items}}{{.ID}} {{end}}' list pods)
POD_LIST_2=$($KUBECFG '-template={{range.Items}}{{.ID}} {{end}}' list pods)
echo "Pods running after shutdown: ${POD_LIST_2}"
exit 0

View File

@@ -16,65 +16,72 @@
# Launches an nginx container and verifies it can be reached. Assumes that
# we're being called by hack/e2e-test.sh (we use some env vars it sets up).
# Exit on error
set -e
set -o errexit
set -o nounset
set -o pipefail
set -x
source "${KUBE_REPO_ROOT}/cluster/kube-env.sh"
source "${KUBE_REPO_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
function validate() {
POD_ID_LIST=$($CLOUDCFG '-template={{range.Items}}{{.ID}} {{end}}' -l name=$controller list pods)
# Container turn up on a clean cluster can take a while for the docker image pull.
ALL_RUNNING=0
while [ $ALL_RUNNING -ne 1 ]; do
echo "Waiting for all containers in pod to come up."
sleep 5
ALL_RUNNING=1
for id in $POD_ID_LIST; do
CURRENT_STATUS=$($CLOUDCFG -template '{{and .CurrentState.Info.datacontroller.State.Running .CurrentState.Info.net.State.Running}}' get pods/$id)
if [ "$CURRENT_STATUS" != "true" ]; then
ALL_RUNNING=0
fi
done
done
ids=($POD_ID_LIST)
if [ ${#ids[@]} -ne $1 ]; then
echo "Unexpected number of pods: ${#ids[@]}. Expected $1"
exit 1
fi
CONTROLLER_NAME=update-demo
function validate() {
NUM_REPLICAS=$1
CONTAINER_IMAGE_VERSION=$2
POD_ID_LIST=$($KUBECFG '-template={{range.Items}}{{.ID}} {{end}}' -l replicationController=${CONTROLLER_NAME} list pods)
# Container turn up on a clean cluster can take a while for the docker image pull.
ALL_RUNNING=0
while [ $ALL_RUNNING -ne 1 ]; do
echo "Waiting for all containers in pod to come up."
sleep 5
ALL_RUNNING=1
for id in $POD_ID_LIST; do
TEMPLATE_STRING="{{and ((index .CurrentState.Info \"${CONTROLLER_NAME}\").State.Running) .CurrentState.Info.net.State.Running}}"
CURRENT_STATUS=$($KUBECFG -template "${TEMPLATE_STRING}" get pods/$id)
if [ "$CURRENT_STATUS" != "true" ]; then
ALL_RUNNING=0
fi
CURRENT_IMAGE=$($KUBECFG -template "{{(index .CurrentState.Info \"${CONTROLLER_NAME}\").Config.Image}}" get pods/$id)
if [ "$CURRENT_IMAGE" != "${DOCKER_HUB_USER}/update-demo:${CONTAINER_IMAGE_VERSION}" ]; then
ALL_RUNNING=0
fi
done
done
ids=($POD_ID_LIST)
if [ ${#ids[@]} -ne $NUM_REPLICAS ]; then
echo "Unexpected number of pods: ${#ids[@]}. Expected $NUM_REPLICAS"
exit 1
fi
}
controller=dataController
DOCKER_HUB_USER=jbeda
# Launch a container
$CLOUDCFG -p 8080:80 run brendanburns/data 2 $controller
${KUBE_REPO_ROOT}/examples/update-demo/1-create-replication-controller.sh
function teardown() {
echo "Cleaning up test artifacts"
$CLOUDCFG stop $controller
$CLOUDCFG rm $controller
${KUBE_REPO_ROOT}/examples/update-demo/4-down.sh
}
trap "teardown" EXIT
validate 2
validate 2 nautilus
$CLOUDCFG resize $controller 1
${KUBE_REPO_ROOT}/examples/update-demo/2-scale.sh 1
sleep 2
validate 1
validate 1 nautilus
$CLOUDCFG resize $controller 2
${KUBE_REPO_ROOT}/examples/update-demo/2-scale.sh 2
sleep 2
validate 2
validate 2 nautilus
# TODO: test rolling update here, but to do so, we need to make the update blocking
# $CLOUDCFG -u=20s rollingupdate $controller
#
# Wait for the replica controller to recreate
# sleep 10
#
# validate 2
${KUBE_REPO_ROOT}/examples/update-demo/3-rolling-update.sh kitten 1s
sleep 2
validate 2 kitten
exit 0

View File

@@ -32,7 +32,7 @@ set -e
# Use testing config
export KUBE_CONFIG_FILE="config-test.sh"
export KUBE_REPO_ROOT="$(dirname $0)/.."
export CLOUDCFG="${KUBE_REPO_ROOT}/cluster/kubecfg.sh -expect_version_match"
export KUBECFG="${KUBE_REPO_ROOT}/cluster/kubecfg.sh -expect_version_match"
if [[ $TEAR_DOWN -ne 0 ]]; then
detect-project