Merge pull request #6581 from nikhiljindal/v1beta3

Moving v1beta1 kubectl examples to v1beta3
pull/6/head
Brian Grant 2015-04-08 14:01:57 -07:00
commit c4cbc9bc46
9 changed files with 39 additions and 33 deletions

View File

@ -165,7 +165,7 @@ function wait-cluster-readiness {
local timeout=50
while [[ $timeout -ne 0 ]]; do
nb_ready_minions=$("${kubectl}" get minions -o template -t "{{range.items}}{{range.status.conditions}}{{.kind}}{{end}}:{{end}}" --api-version=v1beta1 2>/dev/null | tr ':' '\n' | grep -c Ready || true)
nb_ready_minions=$("${kubectl}" get nodes -o template -t "{{range.items}}{{range.status.conditions}}{{.kind}}{{end}}:{{end}}" --api-version=v1beta3 2>/dev/null | tr ':' '\n' | grep -c Ready || true)
echo "Nb ready minions: $nb_ready_minions / $NUM_MINIONS"
if [[ "$nb_ready_minions" -eq "$NUM_MINIONS" ]]; then
return 0

View File

@ -165,7 +165,7 @@ function verify-cluster {
local count="0"
until [[ "$count" == "1" ]]; do
local minions
minions=$("${KUBE_ROOT}/cluster/kubectl.sh" get minions -o template -t '{{range.items}}{{.id}}:{{end}}' --api-version=v1beta1)
minions=$("${KUBE_ROOT}/cluster/kubectl.sh" get nodes -o template -t '{{range.items}}{{.metadata.name}}:{{end}}' --api-version=v1beta3)
count=$(echo $minions | grep -c "${MINION_IPS[i]}") || {
printf "."
sleep 2

View File

@ -29,8 +29,8 @@ $ kubectl get replicationController web
// List a single pod in JSON output format.
$ kubectl get -o json pod web-pod-13je7
// Return only the status value of the specified pod.
$ kubectl get -o template web-pod-13je7 --template={{.currentState.status}} --api-version=v1beta1
// Return only the phase value of the specified pod.
$ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-version=v1beta3
// List all replication controllers and services together in ps output format.
$ kubectl get rc,services

View File

@ -175,8 +175,8 @@ $ kubectl get replicationController web
// List a single pod in JSON output format.
$ kubectl get \-o json pod web\-pod\-13je7
// Return only the status value of the specified pod.
$ kubectl get \-o template web\-pod\-13je7 \-\-template=\{\{.currentState.status\}\} \-\-api\-version=v1beta1
// Return only the phase value of the specified pod.
$ kubectl get \-o template web\-pod\-13je7 \-\-template=\{\{.status.phase\}\} \-\-api\-version=v1beta3
// List all replication controllers and services together in ps output format.
$ kubectl get rc,services

View File

@ -58,7 +58,7 @@ until [[ ${all_running} == 1 ]]; do
echo "All pods never 'Running' in time." >&2
exit 1
fi
statuses=($(${KUBECTL} get pods --template='{{range.items}}{{.currentState.status}} {{end}}' --api-version=v1beta1))
statuses=($(${KUBECTL} get pods --template='{{range.items}}{{.status.phase}} {{end}}' --api-version=v1beta3))
# Ensure that we have enough pods.
echo "Found ${#statuses[@]} pods with statuses: ${statuses[@]}" >&2

View File

@ -151,8 +151,8 @@ function query_pods() {
local i
for i in $(seq 1 10); do
pods_unsorted=($(${KUBECTL} get pods -o template \
'--template={{range.items}}{{.id}} {{end}}' \
'--api-version=v1beta1' \
'--template={{range.items}}{{.metadata.name}} {{end}}' \
'--api-version=v1beta3' \
-l name="$1"))
found="${#pods_unsorted[*]}"
if [[ "${found}" == "$2" ]]; then
@ -186,7 +186,7 @@ function wait_for_pods() {
echo "Waiting for ${pods_needed} pods to become 'running'"
pods_needed="$2"
for id in ${pods_sorted}; do
status=$(${KUBECTL} get pods "${id}" -o template --template='{{.currentState.status}}' --api-version=v1beta1)
status=$(${KUBECTL} get pods "${id}" -o template --template='{{.status.phase}}' --api-version=v1beta3)
if [[ "${status}" == "Running" ]]; then
pods_needed=$((pods_needed-1))
fi
@ -312,9 +312,9 @@ svc1_pods=$(query_pods "${svc1_name}" "${svc1_count}")
svc2_pods=$(query_pods "${svc2_name}" "${svc2_count}")
# Get the portal IPs.
svc1_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc1_name}" --api-version=v1beta1)
svc1_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc1_name}" --api-version=v1beta3)
test -n "${svc1_ip}" || error "Service1 IP is blank"
svc2_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc2_name}" --api-version=v1beta1)
svc2_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc2_name}" --api-version=v1beta3)
test -n "${svc2_ip}" || error "Service2 IP is blank"
if [[ "${svc1_ip}" == "${svc2_ip}" ]]; then
error "Portal IPs conflict: ${svc1_ip}"
@ -384,7 +384,7 @@ wait_for_pods "${svc3_name}" "${svc3_count}"
svc3_pods=$(query_pods "${svc3_name}" "${svc3_count}")
# Get the portal IP.
svc3_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc3_name}" --api-version=v1beta1)
svc3_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc3_name}" --api-version=v1beta3)
test -n "${svc3_ip}" || error "Service3 IP is blank"
echo "Verifying the portals from the host"
@ -440,7 +440,7 @@ wait_for_pods "${svc4_name}" "${svc4_count}"
svc4_pods=$(query_pods "${svc4_name}" "${svc4_count}")
# Get the portal IP.
svc4_ip=$(${KUBECTL} get services -o template '--template={{.portalIP}}' "${svc4_name}" --api-version=v1beta1)
svc4_ip=$(${KUBECTL} get services -o template '--template={{.spec.portalIP}}' "${svc4_name}" --api-version=v1beta3)
test -n "${svc4_ip}" || error "Service4 IP is blank"
if [[ "${svc4_ip}" == "${svc2_ip}" || "${svc4_ip}" == "${svc3_ip}" ]]; then
error "Portal IPs conflict: ${svc4_ip}"

View File

@ -47,8 +47,8 @@ $ kubectl get replicationController web
// List a single pod in JSON output format.
$ kubectl get -o json pod web-pod-13je7
// Return only the status value of the specified pod.
$ kubectl get -o template web-pod-13je7 --template={{.currentState.status}} --api-version=v1beta1
// Return only the phase value of the specified pod.
$ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-version=v1beta3
// List all replication controllers and services together in ps output format.
$ kubectl get rc,services

View File

@ -367,7 +367,7 @@ func TestTemplateStrings(t *testing.T) {
},
"false",
},
"oneValid": {
"barValid": {
api.Pod{
Status: api.PodStatus{
ContainerStatuses: []api.ContainerStatus{
@ -413,26 +413,28 @@ func TestTemplateStrings(t *testing.T) {
"true",
},
}
// The point of this test is to verify that the below template works. If you change this
// template, you need to update hack/e2e-suite/update.sh.
tmpl :=
`{{and (exists . "currentState" "info" "foo" "state" "running") (exists . "currentState" "info" "bar" "state" "running")}}`
useThisToDebug := `
tmpl := ``
if api.PreV1Beta3(testapi.Version()) {
tmpl = `{{exists . "currentState" "info" "foo" "state" "running"}}`
useThisToDebug := `
a: {{exists . "currentState"}}
b: {{exists . "currentState" "info"}}
c: {{exists . "currentState" "info" "foo"}}
d: {{exists . "currentState" "info" "foo" "state"}}
e: {{exists . "currentState" "info" "foo" "state" "running"}}
f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
_ = useThisToDebug // don't complain about unused var
_ = useThisToDebug // don't complain about unused var
} else {
tmpl = `{{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if (and (eq .name "foo") (exists . "state" "running"))}}true{{end}}{{end}}{{end}}`
}
p, err := NewTemplatePrinter([]byte(tmpl))
if err != nil {
t.Fatalf("tmpl fail: %v", err)
}
printer := NewVersionedPrinter(p, api.Scheme, "v1beta1")
printer := NewVersionedPrinter(p, api.Scheme, testapi.Version())
for name, item := range table {
buffer := &bytes.Buffer{}
@ -441,8 +443,12 @@ f: {{exists . "currentState" "info" "foo" "state" "running" "startedAt"}}`
t.Errorf("%v: unexpected err: %v", name, err)
continue
}
if e, a := item.expect, buffer.String(); e != a {
t.Errorf("%v: expected %v, got %v", name, e, a)
actual := buffer.String()
if len(actual) == 0 {
actual = "false"
}
if e := item.expect; e != actual {
t.Errorf("%v: expected %v, got %v", name, e, actual)
}
}
}

View File

@ -216,7 +216,7 @@ type validatorFn func(c *client.Client, podID string) error
// "testname": which gets bubbled up to the logging/failure messages if errors happen.
// "validator" function: This function is given a podID and a client, and it can do some specific validations that way.
func validateController(c *client.Client, containerImage string, replicas int, containername string, testname string, validator validatorFn) {
getPodsTemplate := "--template={{range.items}}{{.id}} {{end}}"
getPodsTemplate := "--template={{range.items}}{{.metadata.name}} {{end}}"
// NB: kubectl adds 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
@ -225,13 +225,13 @@ func validateController(c *client.Client, containerImage string, replicas int, c
// helpful.
// This template is unit-tested in kubectl, so if you change it, update the unit test.
// You can read about the syntax here: http://golang.org/pkg/text/template/.
getContainerStateTemplate := fmt.Sprintf(`--template={{and (exists . "currentState" "info" "%s" "state" "running")}}`, containername)
getContainerStateTemplate := fmt.Sprintf(`--template={{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if (and (eq .name "%s") (exists . "state" "running"))}}true{{end}}{{end}}{{end}}`, containername)
getImageTemplate := fmt.Sprintf(`--template={{(index .currentState.info "%s").image}}`, containername)
getImageTemplate := fmt.Sprintf(`--template={{if (exists . "status" "containerStatuses")}}{{range .status.containerStatuses}}{{if eq .name "%s"}}{{.image}}{{end}}{{end}}{{end}}`, containername)
By(fmt.Sprintf("waiting for all containers in %s pods to come up.", testname)) //testname should be selector
for start := time.Now(); time.Since(start) < podStartTimeout; time.Sleep(5 * time.Second) {
getPodsOutput := runKubectl("get", "pods", "-o", "template", getPodsTemplate, "--api-version=v1beta1", "-l", testname)
getPodsOutput := runKubectl("get", "pods", "-o", "template", getPodsTemplate, "--api-version=v1beta3", "-l", testname)
pods := strings.Fields(getPodsOutput)
if numPods := len(pods); numPods != replicas {
By(fmt.Sprintf("Replicas for %s: expected=%d actual=%d", testname, replicas, numPods))
@ -239,13 +239,13 @@ func validateController(c *client.Client, containerImage string, replicas int, c
}
var runningPods []string
for _, podID := range pods {
running := runKubectl("get", "pods", podID, "-o", "template", getContainerStateTemplate, "--api-version=v1beta1")
if running == "false" {
running := runKubectl("get", "pods", podID, "-o", "template", getContainerStateTemplate, "--api-version=v1beta3")
if running != "true" {
Logf("%s is created but not running", podID)
continue
}
currentImage := runKubectl("get", "pods", podID, "-o", "template", getImageTemplate, "--api-version=v1beta1")
currentImage := runKubectl("get", "pods", podID, "-o", "template", getImageTemplate, "--api-version=v1beta3")
if currentImage != containerImage {
Logf("%s is created but running wrong image; expected: %s, actual: %s", podID, containerImage, currentImage)
continue