forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·131 lines (104 loc) · 4.41 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·131 lines (104 loc) · 4.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# Copyright 2014 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 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).
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
source "${KUBE_ROOT}/cluster/kube-env.sh"
source "${KUBE_ROOT}/cluster/$KUBERNETES_PROVIDER/util.sh"
CONTROLLER_NAME=update-demo
function validate() {
local num_replicas=$1
local container_image_version=$2
# Container turn up on a clean cluster can take a while for the docker image pull.
local num_running=0
while [[ $num_running -ne $num_replicas ]]; do
echo "Waiting for all containers in pod to come up. Currently: ${num_running}/${num_replicas}"
sleep 2
local pod_id_list
pod_id_list=($($KUBECFG -template='{{range.items}}{{.id}} {{end}}' -l name="${CONTROLLER_NAME}" list pods))
echo " ${#pod_id_list[@]} out of ${num_replicas} created"
local id
num_running=0
if [[ ${#pod_id_list[@]} -ne $num_replicas ]]; then
echo "Too few or too many replicas."
continue
fi
for id in "${pod_id_list[@]+${pod_id_list[@]}}"; do
local template_string current_status current_image host_ip
# 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,
# 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\" \"net\" \"state\" \"running\")}}"
current_status=$($KUBECFG -template="${template_string}" get "pods/$id") || {
if [[ $current_status =~ "pod \"${id}\" not found" ]]; then
echo " $id no longer exists"
continue
else
echo " kubecfg failed with error:"
echo $current_status
exit -1
fi
}
if [[ "$current_status" == "false" ]]; then
echo " $id is created but not running."
continue
fi
echo " $id is created and both net 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
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)
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"
continue
}
echo " ${id} is verified up and running"
((num_running++)) || true
done
done
return 0
}
export DOCKER_HUB_USER=davidopp
# Launch a container
${KUBE_ROOT}/examples/update-demo/2-create-replication-controller.sh
function teardown() {
echo "Cleaning up test artifacts"
${KUBE_ROOT}/examples/update-demo/5-down.sh
}
trap "teardown" EXIT
validate 2 nautilus
${KUBE_ROOT}/examples/update-demo/3-scale.sh 1
sleep 2
validate 1 nautilus
${KUBE_ROOT}/examples/update-demo/3-scale.sh 2
sleep 2
validate 2 nautilus
${KUBE_ROOT}/examples/update-demo/4-rolling-update.sh kitten 1s
sleep 2
validate 2 kitten
exit 0