From fe60be3179de8f66d063d74d8cb885490c8b058a Mon Sep 17 00:00:00 2001 From: nikhiljindal Date: Wed, 8 Apr 2015 10:22:33 -0700 Subject: [PATCH] Moving v1beta1 kubectl examples to v1beta3 --- cluster/libvirt-coreos/util.sh | 2 +- cluster/vagrant/util.sh | 2 +- docs/kubectl-get.md | 4 ++-- docs/man/man1/kubectl-get.1 | 4 ++-- hack/e2e-internal/e2e-status.sh | 2 +- hack/e2e-suite/services.sh | 14 +++++++------- pkg/kubectl/cmd/get.go | 4 ++-- pkg/kubectl/resource_printer_test.go | 26 ++++++++++++++++---------- test/e2e/util.go | 14 +++++++------- 9 files changed, 39 insertions(+), 33 deletions(-) diff --git a/cluster/libvirt-coreos/util.sh b/cluster/libvirt-coreos/util.sh index 31837e0aeab..e93798594a8 100644 --- a/cluster/libvirt-coreos/util.sh +++ b/cluster/libvirt-coreos/util.sh @@ -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 diff --git a/cluster/vagrant/util.sh b/cluster/vagrant/util.sh index be88d322732..54e0c6e3aa9 100644 --- a/cluster/vagrant/util.sh +++ b/cluster/vagrant/util.sh @@ -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 diff --git a/docs/kubectl-get.md b/docs/kubectl-get.md index 9bad34f7899..34062025a7a 100644 --- a/docs/kubectl-get.md +++ b/docs/kubectl-get.md @@ -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 diff --git a/docs/man/man1/kubectl-get.1 b/docs/man/man1/kubectl-get.1 index a0d2f44989f..e7378419b95 100644 --- a/docs/man/man1/kubectl-get.1 +++ b/docs/man/man1/kubectl-get.1 @@ -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 diff --git a/hack/e2e-internal/e2e-status.sh b/hack/e2e-internal/e2e-status.sh index 28aa83d6ecf..f260620d2c1 100755 --- a/hack/e2e-internal/e2e-status.sh +++ b/hack/e2e-internal/e2e-status.sh @@ -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 diff --git a/hack/e2e-suite/services.sh b/hack/e2e-suite/services.sh index 1976d05a4b2..115600bc4e5 100755 --- a/hack/e2e-suite/services.sh +++ b/hack/e2e-suite/services.sh @@ -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}" diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index 7cf2e749b0b..8abd7880d9a 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -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 diff --git a/pkg/kubectl/resource_printer_test.go b/pkg/kubectl/resource_printer_test.go index 291a63036d7..f34e17cdffb 100644 --- a/pkg/kubectl/resource_printer_test.go +++ b/pkg/kubectl/resource_printer_test.go @@ -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) } } } diff --git a/test/e2e/util.go b/test/e2e/util.go index 6ff9e5d7981..a8da2b2d2a7 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -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