From c912b831ce6546e6a3a1d84080014ae700e4ce3b Mon Sep 17 00:00:00 2001 From: Jeff Lowdermlk Date: Fri, 16 Jan 2015 13:22:55 -0800 Subject: [PATCH] Update update-demo example and e2e test to use kubectl --- examples/examples_test.go | 4 ++++ examples/update-demo/1-run-web-proxy.sh | 5 ++++- .../2-create-replication-controller.sh | 8 ++++--- examples/update-demo/3-scale.sh | 4 ++-- examples/update-demo/4-rolling-update.sh | 12 ++++++----- examples/update-demo/5-down.sh | 9 ++++---- examples/update-demo/README.md | 12 +++++------ examples/update-demo/kitten-rc.yaml | 20 ++++++++++++++++++ examples/update-demo/local/script.js | 14 ++++++++++--- examples/update-demo/nautilus-rc.yaml | 21 +++++++++++++++++++ hack/e2e-suite/update.sh | 16 +++++++------- 11 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 examples/update-demo/kitten-rc.yaml create mode 100644 examples/update-demo/nautilus-rc.yaml diff --git a/examples/examples_test.go b/examples/examples_test.go index f659517007f..1068056fb2a 100644 --- a/examples/examples_test.go +++ b/examples/examples_test.go @@ -123,6 +123,10 @@ func TestExampleObjectSchemas(t *testing.T) { "service": &api.Service{}, "replication-controller": &api.ReplicationController{}, }, + "../examples/update-demo": { + "kitten-rc": &api.ReplicationController{}, + "nautilus-rc": &api.ReplicationController{}, + }, } for path, expected := range cases { diff --git a/examples/update-demo/1-run-web-proxy.sh b/examples/update-demo/1-run-web-proxy.sh index f51295c84f3..d92ab8ba485 100755 --- a/examples/update-demo/1-run-web-proxy.sh +++ b/examples/update-demo/1-run-web-proxy.sh @@ -24,6 +24,9 @@ echo echo " http://localhost:8001/static/" echo +export KUBE_ROOT=$(dirname $0)/../.. +export KUBECTL=${KUBE_REPO_ROOT}/cluster/kubectl.sh + set -x -../../cluster/kubecfg.sh -proxy -www local/ +$KUBECTL proxy --www=local/ diff --git a/examples/update-demo/2-create-replication-controller.sh b/examples/update-demo/2-create-replication-controller.sh index 7b032d8cd5b..77e27005a99 100755 --- a/examples/update-demo/2-create-replication-controller.sh +++ b/examples/update-demo/2-create-replication-controller.sh @@ -23,9 +23,11 @@ if [[ "${DOCKER_HUB_USER+set}" != "set" ]] ; then exit 1 fi -export KUBE_REPO_ROOT=${KUBE_REPO_ROOT-$(dirname $0)/../..} -export KUBECFG=${KUBECFG-$KUBE_REPO_ROOT/cluster/kubecfg.sh} +export KUBE_ROOT=$(dirname $0)/../.. +export KUBECTL=${KUBE_REPO_ROOT}/cluster/kubectl.sh set -x -$KUBECFG -p 8080:80 run $DOCKER_HUB_USER/update-demo:nautilus 2 update-demo +SCHEMA=${KUBE_REPO_ROOT}/examples/update-demo/nautilus-rc.yaml + +cat ${SCHEMA} | sed "s/DOCKER_HUB_USER/${DOCKER_HUB_USER}/" | ${KUBECTL} create -f - diff --git a/examples/update-demo/3-scale.sh b/examples/update-demo/3-scale.sh index e7cc5ae6f24..6c2aa65e65b 100755 --- a/examples/update-demo/3-scale.sh +++ b/examples/update-demo/3-scale.sh @@ -21,8 +21,8 @@ set -o pipefail NEW_SIZE=${1:-4} export KUBE_REPO_ROOT=${KUBE_REPO_ROOT-$(dirname $0)/../..} -export KUBECFG=${KUBECFG-$KUBE_REPO_ROOT/cluster/kubecfg.sh} +export KUBECTL=${KUBECTL-$KUBE_REPO_ROOT/cluster/kubectl.sh} set -x -$KUBECFG resize update-demo $NEW_SIZE +$KUBECTL resize rc update-demo-nautilus --replicas=$NEW_SIZE diff --git a/examples/update-demo/4-rolling-update.sh b/examples/update-demo/4-rolling-update.sh index 03c5e75c54d..e4dcff47a2a 100755 --- a/examples/update-demo/4-rolling-update.sh +++ b/examples/update-demo/4-rolling-update.sh @@ -23,11 +23,13 @@ if [[ "${DOCKER_HUB_USER+set}" != "set" ]] ; then exit 1 fi -NEW_IMAGE=${1:-kitten} -TIMING=${2:-10s} -export KUBE_REPO_ROOT=${KUBE_REPO_ROOT-$(dirname $0)/../..} -export KUBECFG=${KUBECFG-$KUBE_REPO_ROOT/cluster/kubecfg.sh} +export KUBE_ROOT=$(dirname $0)/../.. +export KUBECTL=${KUBE_ROOT}/cluster/kubectl.sh set -x -$KUBECFG -image $DOCKER_HUB_USER/update-demo:$NEW_IMAGE -u $TIMING rollingupdate update-demo +NEW_IMAGE=${1:-kitten} +TIMING=${2:-10s} +SCHEMA=${KUBE_ROOT}/examples/update-demo/kitten-rc.yaml + +cat ${SCHEMA} | sed "s/DOCKER_HUB_USER/${DOCKER_HUB_USER}/" | ${KUBECTL} rollingupdate update-demo-nautilus -f - --update-period=10s diff --git a/examples/update-demo/5-down.sh b/examples/update-demo/5-down.sh index 0167bce3f1c..92fb27586e5 100755 --- a/examples/update-demo/5-down.sh +++ b/examples/update-demo/5-down.sh @@ -18,10 +18,11 @@ set -o errexit set -o nounset set -o pipefail -export KUBE_REPO_ROOT=${KUBE_REPO_ROOT-$(dirname $0)/../..} -export KUBECFG=${KUBECFG-$KUBE_REPO_ROOT/cluster/kubecfg.sh} +export KUBE_ROOT=$(dirname $0)/../.. +export KUBECTL=${KUBE_ROOT}/cluster/kubectl.sh set -x -$KUBECFG stop update-demo -$KUBECFG rm update-demo +rc="update-demo-kitten" + +$KUBECTL stop rc ${rc} diff --git a/examples/update-demo/README.md b/examples/update-demo/README.md index 6ee896db8f3..a3607113160 100644 --- a/examples/update-demo/README.md +++ b/examples/update-demo/README.md @@ -61,8 +61,8 @@ separate terminal or run it in the background. http://localhost:8001/static/ -+ ../../cluster/kubecfg.sh -proxy -www local/ -I0922 11:43:54.886018 15659 kubecfg.go:209] Starting to serve on localhost:8001 ++ ../../cluster/kubectl.sh proxy --www=local/ +I0115 16:50:15.959551 19790 proxy.go:34] Starting to serve on localhost:8001 ``` Now visit the the [demo website](http://localhost:8001/static). You won't see anything much quite yet. @@ -92,12 +92,12 @@ We will now update the docker image to serve a different image by doing a rollin ```bash $ ./4-rolling-update.sh ``` -The rollingUpdate command in kubecfg will do 2 things: +The rollingUpdate command in kubectl will do 2 things: -1. Update the template in the replication controller to the new image (`$DOCKER_HUB_USER/update-demo:kitten`) -2. Kill each of the pods one by one. It'll let the replication controller create new pods to replace those that were killed. +1. Create a new replication controller with a pod template that uses the new image (`$DOCKER_HUB_USER/update-demo:kitten`) +2. Resize the old and new replication controllers until the new controller replaces the old. This will kill the current pods one at a time, spinnning up new ones to replace them. -Watch the UX, it will update one pod every 10 seconds until all of the pods have the new image. +Watch the [demo website](http://localhost:8001/static/index.html), it will update one pod every 10 seconds until all of the pods have the new image. ### Step Five: Bring down the pods diff --git a/examples/update-demo/kitten-rc.yaml b/examples/update-demo/kitten-rc.yaml new file mode 100644 index 00000000000..d6078c570fa --- /dev/null +++ b/examples/update-demo/kitten-rc.yaml @@ -0,0 +1,20 @@ +kind: ReplicationController +id: update-demo-kitten +apiVersion: v1beta1 +desiredState: + replicaSelector: + name: update-demo + version: kitten + podTemplate: + desiredState: + manifest: + containers: + - name: update-demo + image: DOCKER_HUB_USER/update-demo:kitten + ports: + - hostPort: 8080 + containerPort: 80 + protocol: TCP + labels: + name: update-demo + version: kitten diff --git a/examples/update-demo/local/script.js b/examples/update-demo/local/script.js index 0724ac011bd..79493b6e5a8 100644 --- a/examples/update-demo/local/script.js +++ b/examples/update-demo/local/script.js @@ -46,7 +46,7 @@ var updateServer = function($http, server) { }; var updateData = function($scope, $http) { - var servers = $scope.servers + var servers = $scope.servers; for (var i = 0; i < servers.length; ++i) { var server = servers[i]; updateServer($http, server); @@ -69,6 +69,10 @@ var getServer = function($scope, id) { return null; }; +var isUpdateDemoPod = function(pod) { + return pod.labels && pod.labels.name == "update-demo"; +}; + var update = function($scope, $http) { if (!$http) { console.log("No HTTP!"); @@ -79,9 +83,13 @@ var update = function($scope, $http) { console.log(data); var newServers = []; for (var i = 0; i < data.items.length; ++i) { - var server = getServer($scope, data.items[i].id); + var pod = data.items[i]; + if (!isUpdateDemoPod(pod)) { + continue; + } + var server = getServer($scope, pod.id); if (server == null) { - server = { "id": data.items[i].id }; + server = { "id": pod.id }; } newServers.push(server); } diff --git a/examples/update-demo/nautilus-rc.yaml b/examples/update-demo/nautilus-rc.yaml new file mode 100644 index 00000000000..967906a9ba8 --- /dev/null +++ b/examples/update-demo/nautilus-rc.yaml @@ -0,0 +1,21 @@ +kind: ReplicationController +id: update-demo-nautilus +apiVersion: v1beta1 +desiredState: + replicas: 2 + replicaSelector: + name: update-demo + version: nautilus + podTemplate: + desiredState: + manifest: + containers: + - name: update-demo + image: DOCKER_HUB_USER/update-demo:nautilus + ports: + - hostPort: 8080 + containerPort: 80 + protocol: TCP + labels: + name: update-demo + version: nautilus diff --git a/hack/e2e-suite/update.sh b/hack/e2e-suite/update.sh index 138832fc234..d6708505c2e 100755 --- a/hack/e2e-suite/update.sh +++ b/hack/e2e-suite/update.sh @@ -38,7 +38,7 @@ function validate() { sleep 2 local pod_id_list - pod_id_list=($($KUBECFG -template='{{range.items}}{{.id}} {{end}}' -l name="${CONTROLLER_NAME}" list pods)) + pod_id_list=($($KUBECTL get pods -o template --template='{{range.items}}{{.id}} {{end}}' -l name="${CONTROLLER_NAME}")) echo " ${#pod_id_list[@]} out of ${num_replicas} created" @@ -54,19 +54,19 @@ function validate() { # NB: kubectl & kubecfg add the "exists" function to the standard template functions. # This lets us check to see if the "running" entry exists for each of the containers # we care about. Exists will never return an error and it's safe to check a chain of - # things, any one of which may not exist. In the below template, all of info, + # things, any one of which may not exist. In the below template, all of info, # containername, and running might be nil, so the normal index function isn't very # helpful. # This template is unit-tested in kubec{tl|fg}, so if you change it, update the unit test. # # You can read about the syntax here: http://golang.org/pkg/text/template/ - template_string="{{and (exists . \"currentState\" \"info\" \"${CONTROLLER_NAME}\" \"state\" \"running\") (exists . \"currentState\" \"info\" \"POD\" \"state\" \"running\")}}" - current_status=$($KUBECFG -template="${template_string}" get "pods/$id") || { + template_string="{{and (exists . \"currentState\" \"info\" \"${CONTROLLER_NAME}\" \"state\" \"running\") (exists . \"currentState\" \"info\" \"net\" \"state\" \"running\")}}" + current_status=$($KUBECTL get pods "$id" -o template --template="${template_string}") || { if [[ $current_status =~ "pod \"${id}\" not found" ]]; then echo " $id no longer exists" continue else - echo " kubecfg failed with error:" + echo " kubectl failed with error:" echo $current_status exit -1 fi @@ -79,14 +79,14 @@ function validate() { echo " $id is created and both POD and update-demo containers are running: $current_status" template_string="{{(index .currentState.info \"${CONTROLLER_NAME}\").image}}" - current_image=$($KUBECFG -template="${template_string}" get "pods/$id") || true + current_image=$($KUBECTL get pods "$id" -o template --template="${template_string}") || true if [[ "$current_image" != "${DOCKER_HUB_USER}/update-demo:${container_image_version}" ]]; then echo " ${id} is created but running wrong image" continue fi - host_ip=$($KUBECFG -template='{{.currentState.hostIP}}' get pods/$id) + host_ip=$($KUBECTL get pods "$id" -o template --template='{{.currentState.hostIP}}') curl -s --max-time 5 --fail http://${host_ip}:8080/data.json \ | grep -q ${container_image_version} || { echo " ${id} is running the right image but curl to contents failed or returned wrong info" @@ -102,7 +102,7 @@ function validate() { return 0 } -export DOCKER_HUB_USER=davidopp +export DOCKER_HUB_USER=jlowdermilk # Launch a container ${KUBE_ROOT}/examples/update-demo/2-create-replication-controller.sh