From 2e2ef3e8309f7c46ab75147b27daa72294eafe4c Mon Sep 17 00:00:00 2001 From: Dai Zuozhuo Date: Fri, 21 Aug 2015 21:09:41 +0800 Subject: [PATCH] change -o template to -o go-template=... --- cluster/libvirt-coreos/util.sh | 2 +- .../salt/kube-addons/kube-addon-update.sh | 2 +- .../saltbase/salt/kube-addons/kube-addons.sh | 2 +- cluster/update-storage-objects.sh | 4 +-- cluster/vagrant/util.sh | 2 +- docs/man/man1/kubectl-config-view.1 | 9 ++++--- docs/man/man1/kubectl-expose.1 | 9 ++++--- docs/man/man1/kubectl-get.1 | 9 ++++--- docs/man/man1/kubectl-label.1 | 9 ++++--- docs/man/man1/kubectl-rolling-update.1 | 9 ++++--- docs/man/man1/kubectl-run.1 | 9 ++++--- docs/user-guide/compute-resources.md | 4 +-- docs/user-guide/kubectl/kubectl_annotate.md | 2 +- .../user-guide/kubectl/kubectl_config_view.md | 6 ++--- docs/user-guide/kubectl/kubectl_expose.md | 6 ++--- docs/user-guide/kubectl/kubectl_get.md | 8 +++--- docs/user-guide/kubectl/kubectl_label.md | 6 ++--- .../kubectl/kubectl_rolling-update.md | 6 ++--- docs/user-guide/kubectl/kubectl_run.md | 6 ++--- docs/user-guide/production-pods.md | 4 +-- docs/user-guide/walkthrough/README.md | 2 +- docs/user-guide/walkthrough/k8s201.md | 4 +-- examples/k8petstore/k8petstore-nodeport.sh | 8 +++--- hack/lib/test.sh | 4 +-- hack/test-cmd.sh | 4 +-- pkg/kubectl/cmd/get.go | 2 +- pkg/kubectl/cmd/util/printing.go | 13 +++++++-- pkg/kubectl/resource_printer.go | 18 ++++++++++--- pkg/util/jsonpath/jsonpath_test.go | 27 +++++++++++++++++-- test/e2e/util.go | 2 +- 30 files changed, 124 insertions(+), 74 deletions(-) diff --git a/cluster/libvirt-coreos/util.sh b/cluster/libvirt-coreos/util.sh index 3a520b346f7..fec9bdab667 100644 --- a/cluster/libvirt-coreos/util.sh +++ b/cluster/libvirt-coreos/util.sh @@ -195,7 +195,7 @@ function wait-cluster-readiness { local timeout=120 while [[ $timeout -ne 0 ]]; do - nb_ready_minions=$("${kubectl}" get nodes -o template -t "{{range.items}}{{range.status.conditions}}{{.type}}{{end}}:{{end}}" --api-version=v1 2>/dev/null | tr ':' '\n' | grep -c Ready || true) + nb_ready_minions=$("${kubectl}" get nodes -o go-template="{{range.items}}{{range.status.conditions}}{{.type}}{{end}}:{{end}}" --api-version=v1 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/saltbase/salt/kube-addons/kube-addon-update.sh b/cluster/saltbase/salt/kube-addons/kube-addon-update.sh index 0caa4c0a8b8..6b61b9ad11f 100755 --- a/cluster/saltbase/salt/kube-addons/kube-addon-update.sh +++ b/cluster/saltbase/salt/kube-addons/kube-addon-update.sh @@ -198,7 +198,7 @@ function run-until-success() { # returns a list of / pairs (nsnames) function get-addon-nsnames-from-server() { local -r obj_type=$1 - "${KUBECTL}" get "${obj_type}" --all-namespaces -o template -t "{{range.items}}{{.metadata.namespace}}/{{.metadata.name}} {{end}}" --api-version=v1 -l kubernetes.io/cluster-service=true + "${KUBECTL}" get "${obj_type}" --all-namespaces -o go-template="{{range.items}}{{.metadata.namespace}}/{{.metadata.name}} {{end}}" --api-version=v1 -l kubernetes.io/cluster-service=true } # returns the characters after the last separator (including) diff --git a/cluster/saltbase/salt/kube-addons/kube-addons.sh b/cluster/saltbase/salt/kube-addons/kube-addons.sh index 45b1ee42b2a..c9fd9a0ea90 100644 --- a/cluster/saltbase/salt/kube-addons/kube-addons.sh +++ b/cluster/saltbase/salt/kube-addons/kube-addons.sh @@ -174,7 +174,7 @@ start_addon /etc/kubernetes/addons/namespace.yaml 100 10 "" & token_found="" while [ -z "${token_found}" ]; do sleep .5 - token_found=$(${KUBECTL} get --namespace="${SYSTEM_NAMESPACE}" serviceaccount default -o template -t "{{with index .secrets 0}}{{.name}}{{end}}" || true) + token_found=$(${KUBECTL} get --namespace="${SYSTEM_NAMESPACE}" serviceaccount default -o go-template="{{with index .secrets 0}}{{.name}}{{end}}" || true) done echo "== default service account in the ${SYSTEM_NAMESPACE} namespace has token ${token_found} ==" diff --git a/cluster/update-storage-objects.sh b/cluster/update-storage-objects.sh index e4c0c830452..d6789929bea 100755 --- a/cluster/update-storage-objects.sh +++ b/cluster/update-storage-objects.sh @@ -49,7 +49,7 @@ declare -a resources=( ) # Find all the namespaces. -namespaces=( $("${KUBECTL}" get namespaces -o template -t "{{range.items}}{{.metadata.name}} {{end}}")) +namespaces=( $("${KUBECTL}" get namespaces -o go-template="{{range.items}}{{.metadata.name}} {{end}}")) if [ -z "${namespaces:-}" ] then echo "Unexpected: No namespace found. Nothing to do." @@ -59,7 +59,7 @@ for resource in "${resources[@]}" do for namespace in "${namespaces[@]}" do - instances=( $("${KUBECTL}" get "${resource}" --namespace="${namespace}" -o template -t "{{range.items}}{{.metadata.name}} {{end}}")) + instances=( $("${KUBECTL}" get "${resource}" --namespace="${namespace}" -o go-template="{{range.items}}{{.metadata.name}} {{end}}")) # Nothing to do if there is no instance of that resource. if [[ -z "${instances:-}" ]] then diff --git a/cluster/vagrant/util.sh b/cluster/vagrant/util.sh index f0803411d37..f02097912e4 100644 --- a/cluster/vagrant/util.sh +++ b/cluster/vagrant/util.sh @@ -238,7 +238,7 @@ function verify-cluster { local count="0" until [[ "$count" == "1" ]]; do local minions - minions=$("${KUBE_ROOT}/cluster/kubectl.sh" get nodes -o template --template '{{range.items}}{{.metadata.name}}:{{end}}' --api-version=v1) + minions=$("${KUBE_ROOT}/cluster/kubectl.sh" get nodes -o go-template='{{range.items}}{{.metadata.name}}:{{end}}' --api-version=v1) count=$(echo $minions | grep -c "${MINION_IPS[i]}") || { printf "." sleep 2 diff --git a/docs/man/man1/kubectl-config-view.1 b/docs/man/man1/kubectl-config-view.1 index 25ab0462cac..5ada9c8bb33 100644 --- a/docs/man/man1/kubectl-config-view.1 +++ b/docs/man/man1/kubectl-config-view.1 @@ -38,7 +38,9 @@ You can use \-\-output=template \-\-template=TEMPLATE to extract specific values .PP \fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]] and jsonpath template [ +\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]]. .PP \fB\-\-output\-version\fP="" @@ -58,9 +60,8 @@ You can use \-\-output=template \-\-template=TEMPLATE to extract specific values .PP \fB\-t\fP, \fB\-\-template\fP="" - Template string or path to template file to use when \-o=template, \-o=templatefile or \-o=jsonpath. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. The jsonpath template is composed of jsonpath expressions enclosed by {} [ -\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]] + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. .SH OPTIONS INHERITED FROM PARENT COMMANDS diff --git a/docs/man/man1/kubectl-expose.1 b/docs/man/man1/kubectl-expose.1 index d148ffcaf0d..513310db4f2 100644 --- a/docs/man/man1/kubectl-expose.1 +++ b/docs/man/man1/kubectl-expose.1 @@ -60,7 +60,9 @@ re\-use the labels from the resource it exposes. .PP \fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]] and jsonpath template [ +\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]]. .PP \fB\-\-output\-version\fP="" @@ -100,9 +102,8 @@ re\-use the labels from the resource it exposes. .PP \fB\-t\fP, \fB\-\-template\fP="" - Template string or path to template file to use when \-o=template, \-o=templatefile or \-o=jsonpath. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. The jsonpath template is composed of jsonpath expressions enclosed by {} [ -\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]] + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. .PP \fB\-\-type\fP="" diff --git a/docs/man/man1/kubectl-get.1 b/docs/man/man1/kubectl-get.1 index 3c94adeb246..63ecbb104d6 100644 --- a/docs/man/man1/kubectl-get.1 +++ b/docs/man/man1/kubectl-get.1 @@ -45,7 +45,9 @@ of the \-\-template flag, you can filter the attributes of the fetched resource( .PP \fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]] and jsonpath template [ +\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]]. .PP \fB\-\-output\-version\fP="" @@ -65,9 +67,8 @@ of the \-\-template flag, you can filter the attributes of the fetched resource( .PP \fB\-t\fP, \fB\-\-template\fP="" - Template string or path to template file to use when \-o=template, \-o=templatefile or \-o=jsonpath. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. The jsonpath template is composed of jsonpath expressions enclosed by {} [ -\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]] + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. .PP \fB\-w\fP, \fB\-\-watch\fP=false diff --git a/docs/man/man1/kubectl-label.1 b/docs/man/man1/kubectl-label.1 index 98cf53ae948..56fadc3670a 100644 --- a/docs/man/man1/kubectl-label.1 +++ b/docs/man/man1/kubectl-label.1 @@ -40,7 +40,9 @@ If \-\-resource\-version is specified, then updates will use this resource versi .PP \fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]] and jsonpath template [ +\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]]. .PP \fB\-\-output\-version\fP="" @@ -68,9 +70,8 @@ If \-\-resource\-version is specified, then updates will use this resource versi .PP \fB\-t\fP, \fB\-\-template\fP="" - Template string or path to template file to use when \-o=template, \-o=templatefile or \-o=jsonpath. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. The jsonpath template is composed of jsonpath expressions enclosed by {} [ -\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]] + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. .SH OPTIONS INHERITED FROM PARENT COMMANDS diff --git a/docs/man/man1/kubectl-rolling-update.1 b/docs/man/man1/kubectl-rolling-update.1 index 32ae729db93..03cf264dc5e 100644 --- a/docs/man/man1/kubectl-rolling-update.1 +++ b/docs/man/man1/kubectl-rolling-update.1 @@ -44,7 +44,9 @@ existing replication controller and overwrite at least one (common) label in its .PP \fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]] and jsonpath template [ +\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]]. .PP \fB\-\-output\-version\fP="" @@ -68,9 +70,8 @@ existing replication controller and overwrite at least one (common) label in its .PP \fB\-t\fP, \fB\-\-template\fP="" - Template string or path to template file to use when \-o=template, \-o=templatefile or \-o=jsonpath. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. The jsonpath template is composed of jsonpath expressions enclosed by {} [ -\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]] + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. .PP \fB\-\-timeout\fP=5m0s diff --git a/docs/man/man1/kubectl-run.1 b/docs/man/man1/kubectl-run.1 index 5df0bb6c189..c332c0adfd0 100644 --- a/docs/man/man1/kubectl-run.1 +++ b/docs/man/man1/kubectl-run.1 @@ -52,7 +52,9 @@ Creates a replication controller to manage the created container(s). .PP \fB\-o\fP, \fB\-\-output\fP="" - Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + Output format. One of: json|yaml|wide|name|go\-template=...|go\-template\-file=...|jsonpath=...|jsonpath\-file=... See golang template [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]] and jsonpath template [ +\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]]. .PP \fB\-\-output\-version\fP="" @@ -88,9 +90,8 @@ Creates a replication controller to manage the created container(s). .PP \fB\-t\fP, \fB\-\-template\fP="" - Template string or path to template file to use when \-o=template, \-o=templatefile or \-o=jsonpath. The template format is golang templates [ -\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. The jsonpath template is composed of jsonpath expressions enclosed by {} [ -\[la]http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md\[ra]] + Template string or path to template file to use when \-o=go\-template, \-o=go\-template\-file. The template format is golang templates [ +\[la]http://golang.org/pkg/text/template/#pkg-overview\[ra]]. .PP \fB\-\-tty\fP=false diff --git a/docs/user-guide/compute-resources.md b/docs/user-guide/compute-resources.md index 0ff1442daa4..7ee8a730730 100644 --- a/docs/user-guide/compute-resources.md +++ b/docs/user-guide/compute-resources.md @@ -250,10 +250,10 @@ Events: The `Restart Count: 5` indicates that the `simmemleak` container in this pod was terminated and restarted 5 times. -You can call `get pod` with the `-o template -t ...` option to fetch the status of previously terminated containers: +You can call `get pod` with the `-o go-template=...` option to fetch the status of previously terminated containers: ```console -[13:59:01] $ ./cluster/kubectl.sh get pod -o template -t '{{range.status.containerStatuses}}{{"Container Name: "}}{{.name}}{{"\r\nLastState: "}}{{.lastState}}{{end}}' simmemleak-60xbc +[13:59:01] $ ./cluster/kubectl.sh get pod -o go-template='{{range.status.containerStatuses}}{{"Container Name: "}}{{.name}}{{"\r\nLastState: "}}{{.lastState}}{{end}}' simmemleak-60xbc Container Name: simmemleak LastState: map[terminated:map[exitCode:137 reason:OOM Killed startedAt:2015-07-07T20:58:43Z finishedAt:2015-07-07T20:58:43Z containerID:docker://0e4095bba1feccdfe7ef9fb6ebffe972b4b14285d5acdec6f0d3ae8a22fad8b2]][13:59:03] clusterScaleDoc ~/go/src/github.com/kubernetes/kubernetes $ ``` diff --git a/docs/user-guide/kubectl/kubectl_annotate.md b/docs/user-guide/kubectl/kubectl_annotate.md index b185ff2c5e5..21909136b72 100644 --- a/docs/user-guide/kubectl/kubectl_annotate.md +++ b/docs/user-guide/kubectl/kubectl_annotate.md @@ -119,7 +119,7 @@ $ kubectl annotate pods foo description- * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-09-03 21:06:22.474197531 +0000 UTC +###### Auto generated by spf13/cobra at 2015-09-02 06:24:17.720533039 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_annotate.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_config_view.md b/docs/user-guide/kubectl/kubectl_config_view.md index d92a26f1646..bbfadeb2d91 100644 --- a/docs/user-guide/kubectl/kubectl_config_view.md +++ b/docs/user-guide/kubectl/kubectl_config_view.md @@ -63,12 +63,12 @@ $ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2 --merge=true: merge together the full hierarchy of kubeconfig files --minify[=false]: remove all information not used by current-context from the output --no-headers[=false]: When using the default output, don't print headers. - -o, --output="": Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --raw[=false]: display raw byte data -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. - --template="": Template string or path to template file to use when -o=template, -o=templatefile or -o=jsonpath. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. The jsonpath template is composed of jsonpath expressions enclosed by {} [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md] + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. ``` ### Options inherited from parent commands @@ -103,7 +103,7 @@ $ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2 * [kubectl config](kubectl_config.md) - config modifies kubeconfig files -###### Auto generated by spf13/cobra at 2015-09-03 21:06:22.474467216 +0000 UTC +###### Auto generated by spf13/cobra at 2015-08-29 13:01:26.775349034 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_config_view.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_expose.md b/docs/user-guide/kubectl/kubectl_expose.md index 2d0531dada0..397de0db7a2 100644 --- a/docs/user-guide/kubectl/kubectl_expose.md +++ b/docs/user-guide/kubectl/kubectl_expose.md @@ -75,7 +75,7 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream -l, --labels="": Labels to apply to the service created by this call. --name="": The name for the newly created object. --no-headers[=false]: When using the default output, don't print headers. - -o, --output="": Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --overrides="": An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field. --port=-1: The port that the service should serve on. Copied from the resource being exposed, if unspecified @@ -85,7 +85,7 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. --target-port="": Name or number for the port on the container that the service should direct traffic to. Optional. - --template="": Template string or path to template file to use when -o=template, -o=templatefile or -o=jsonpath. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. The jsonpath template is composed of jsonpath expressions enclosed by {} [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md] + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --type="": Type for this service: ClusterIP, NodePort, or LoadBalancer. Default is 'ClusterIP'. ``` @@ -121,7 +121,7 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-09-03 21:06:22.473647619 +0000 UTC +###### Auto generated by spf13/cobra at 2015-09-03 09:05:42.928698484 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_expose.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_get.md b/docs/user-guide/kubectl/kubectl_get.md index c9eed590858..659f6ce7b78 100644 --- a/docs/user-guide/kubectl/kubectl_get.md +++ b/docs/user-guide/kubectl/kubectl_get.md @@ -49,7 +49,7 @@ By specifying the output as 'template' and providing a Go template as the value of the --template flag, you can filter the attributes of the fetched resource(s). ``` -kubectl get [(-o|--output=)json|yaml|template|templatefile|wide|jsonpath|...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags] +kubectl get [(-o|--output=)json|yaml|wide|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags] ``` ### Examples @@ -90,12 +90,12 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7 -f, --filename=[]: Filename, directory, or URL to a file identifying the resource to get from a server. -L, --label-columns=[]: Accepts a comma separated list of labels that are going to be presented as columns. Names are case-sensitive. You can also use multiple flag statements like -L label1 -L label2... --no-headers[=false]: When using the default output, don't print headers. - -o, --output="": Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). -l, --selector="": Selector (label query) to filter on -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. - --template="": Template string or path to template file to use when -o=template, -o=templatefile or -o=jsonpath. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. The jsonpath template is composed of jsonpath expressions enclosed by {} [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md] + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. -w, --watch[=false]: After listing/getting the requested object, watch for changes. --watch-only[=false]: Watch for changes to the requested object(s), without listing/getting first. ``` @@ -132,7 +132,7 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7 * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-09-03 21:06:22.469014739 +0000 UTC +###### Auto generated by spf13/cobra at 2015-08-29 13:01:26.761418557 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_get.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_label.md b/docs/user-guide/kubectl/kubectl_label.md index d521ae3e3b4..1b0ee3119bc 100644 --- a/docs/user-guide/kubectl/kubectl_label.md +++ b/docs/user-guide/kubectl/kubectl_label.md @@ -78,14 +78,14 @@ $ kubectl label pods foo bar- --dry-run[=false]: If true, only print the object that would be sent, without sending it. -f, --filename=[]: Filename, directory, or URL to a file identifying the resource to update the labels --no-headers[=false]: When using the default output, don't print headers. - -o, --output="": Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --overwrite[=false]: If true, allow labels to be overwritten, otherwise reject label updates that overwrite existing labels. --resource-version="": If non-empty, the labels update will only succeed if this is the current resource-version for the object. Only valid when specifying a single resource. -l, --selector="": Selector (label query) to filter on -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. - --template="": Template string or path to template file to use when -o=template, -o=templatefile or -o=jsonpath. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. The jsonpath template is composed of jsonpath expressions enclosed by {} [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md] + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. ``` ### Options inherited from parent commands @@ -120,7 +120,7 @@ $ kubectl label pods foo bar- * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-09-04 23:19:55.649428669 +0000 UTC +###### Auto generated by spf13/cobra at 2015-08-29 13:01:26.773776248 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_label.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_rolling-update.md b/docs/user-guide/kubectl/kubectl_rolling-update.md index 4d8e38bd48d..26aea54d971 100644 --- a/docs/user-guide/kubectl/kubectl_rolling-update.md +++ b/docs/user-guide/kubectl/kubectl_rolling-update.md @@ -74,13 +74,13 @@ $ kubectl rolling-update frontend --image=image:v2 -f, --filename=[]: Filename or URL to file to use to create the new replication controller. --image="": Image to use for upgrading the replication controller. Can not be used with --filename/-f --no-headers[=false]: When using the default output, don't print headers. - -o, --output="": Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --poll-interval=3s: Time delay between polling for replication controller status after the update. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". --rollback[=false]: If true, this is a request to abort an existing rollout that is partially rolled out. It effectively reverses current and next and runs a rollout -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. - --template="": Template string or path to template file to use when -o=template, -o=templatefile or -o=jsonpath. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. The jsonpath template is composed of jsonpath expressions enclosed by {} [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md] + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --timeout=5m0s: Max time to wait for a replication controller to update before giving up. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". --update-period=1m0s: Time to wait between updating pods. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". --validate[=true]: If true, use a schema to validate the input before sending it @@ -118,7 +118,7 @@ $ kubectl rolling-update frontend --image=image:v2 * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-09-03 21:06:22.470878033 +0000 UTC +###### Auto generated by spf13/cobra at 2015-08-29 13:01:26.768458355 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_rolling-update.md?pixel)]() diff --git a/docs/user-guide/kubectl/kubectl_run.md b/docs/user-guide/kubectl/kubectl_run.md index ecfdcea2812..b9a664dd750 100644 --- a/docs/user-guide/kubectl/kubectl_run.md +++ b/docs/user-guide/kubectl/kubectl_run.md @@ -81,7 +81,7 @@ $ kubectl run nginx --image=nginx --command -- ... --image="": The image for the container to run. -l, --labels="": Labels to apply to the pod(s). --no-headers[=false]: When using the default output, don't print headers. - -o, --output="": Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name. + -o, --output="": Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]. --output-version="": Output the formatted object with the given version (default api-version). --overrides="": An inline JSON override for the generated object. If this is non-empty, it is used to override the generated object. Requires that the object supply a valid apiVersion field. --port=-1: The port that this container exposes. @@ -90,7 +90,7 @@ $ kubectl run nginx --image=nginx --command -- ... -a, --show-all[=false]: When printing, show all resources (default hide terminated pods.) --sort-by="": If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string. -i, --stdin[=false]: Keep stdin open on the container(s) in the pod, even if nothing is attached. - --template="": Template string or path to template file to use when -o=template, -o=templatefile or -o=jsonpath. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. The jsonpath template is composed of jsonpath expressions enclosed by {} [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md] + --template="": Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. --tty[=false]: Allocated a TTY for each container in the pod. Because -t is currently shorthand for --template, -t is not supported for --tty. This shorthand is deprecated and we expect to adopt -t for --tty soon. ``` @@ -126,7 +126,7 @@ $ kubectl run nginx --image=nginx --command -- ... * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager -###### Auto generated by spf13/cobra at 2015-09-03 21:06:22.472292491 +0000 UTC +###### Auto generated by spf13/cobra at 2015-08-29 13:01:26.772003236 +0000 UTC [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/user-guide/kubectl/kubectl_run.md?pixel)]() diff --git a/docs/user-guide/production-pods.md b/docs/user-guide/production-pods.md index 1e7c0219bf6..75bf31edd35 100644 --- a/docs/user-guide/production-pods.md +++ b/docs/user-guide/production-pods.md @@ -371,9 +371,9 @@ The message is recorded along with the other state of the last (i.e., most recen $ kubectl create -f ./pod.yaml pods/pod-w-message $ sleep 70 -$ kubectl get pods/pod-w-message -o template -t "{{range .status.containerStatuses}}{{.lastState.terminated.message}}{{end}}" +$ kubectl get pods/pod-w-message -o go-template="{{range .status.containerStatuses}}{{.lastState.terminated.message}}{{end}}" Sleep expired -$ kubectl get pods/pod-w-message -o template -t "{{range .status.containerStatuses}}{{.lastState.terminated.exitCode}}{{end}}" +$ kubectl get pods/pod-w-message -o go-template="{{range .status.containerStatuses}}{{.lastState.terminated.exitCode}}{{end}}" 0 ``` diff --git a/docs/user-guide/walkthrough/README.md b/docs/user-guide/walkthrough/README.md index fd5e5f92f01..0740e1674f2 100644 --- a/docs/user-guide/walkthrough/README.md +++ b/docs/user-guide/walkthrough/README.md @@ -108,7 +108,7 @@ On most providers, the pod IPs are not externally accessible. The easiest way to Provided the pod IP is accessible, you should be able to access its http endpoint with curl on port 80: ```sh -$ curl http://$(kubectl get pod nginx -o=template -t={{.status.podIP}}) +$ curl http://$(kubectl get pod nginx -o go-template={{.status.podIP}}) ``` Delete the pod by name: diff --git a/docs/user-guide/walkthrough/k8s201.md b/docs/user-guide/walkthrough/k8s201.md index 46b99f6d036..24f9c1d8001 100644 --- a/docs/user-guide/walkthrough/k8s201.md +++ b/docs/user-guide/walkthrough/k8s201.md @@ -217,8 +217,8 @@ On most providers, the service IPs are not externally accessible. The easiest wa Provided the service IP is accessible, you should be able to access its http endpoint with curl on port 80: ```console -$ export SERVICE_IP=$(kubectl get service nginx-service -o=template -t={{.spec.clusterIP}}) -$ export SERVICE_PORT=$(kubectl get service nginx-service -o=template '-t={{(index .spec.ports 0).port}}') +$ export SERVICE_IP=$(kubectl get service nginx-service -o go-template={{.spec.clusterIP}}) +$ export SERVICE_PORT=$(kubectl get service nginx-service -o go-template'={{(index .spec.ports 0).port}}') $ curl http://${SERVICE_IP}:${SERVICE_PORT} ``` diff --git a/examples/k8petstore/k8petstore-nodeport.sh b/examples/k8petstore/k8petstore-nodeport.sh index 07b2cd1d2db..0931b2d8be4 100755 --- a/examples/k8petstore/k8petstore-nodeport.sh +++ b/examples/k8petstore/k8petstore-nodeport.sh @@ -232,10 +232,10 @@ $kubectl create -f bps-load-gen-rc.json --namespace=$NS #Get the IP addresses of all Kubernetes nodes. function getIP { #currently this script is only tested on GCE. The following line may need to be updated if k8s is not running on a cloud platform - NODES_IP=$($kubectl get nodes -t='{{range .items}}{{range .status.addresses}}{{if or (eq .type "ExternalIP") (eq .type "LegacyHostIP")}}{{.address}}{{print "\n"}}{{end}}{{end}}{{end}}') - TEST_IP=$($kubectl get nodes -t='{{range (index .items 0).status.addresses}}{{if eq .type "ExternalIP"}}{{.address}}{{end}}{{end}}') + NODES_IP=$($kubectl get nodes -o go-template='{{range .items}}{{range .status.addresses}}{{if or (eq .type "ExternalIP") (eq .type "LegacyHostIP")}}{{.address}}{{print "\n"}}{{end}}{{end}}{{end}}') + TEST_IP=$($kubectl get nodes -o go-template='{{range (index .items 0).status.addresses}}{{if eq .type "ExternalIP"}}{{.address}}{{end}}{{end}}') if [ -z "$TEST_IP" ]; then - TEST_IP=$($kubectl get nodes -t='{{range (index .items 0).status.addresses}}{{if eq .type "LegacyHostIP"}}{{.address}}{{end}}{{end}}') + TEST_IP=$($kubectl get nodes -o go-template='{{range (index .items 0).status.addresses}}{{if eq .type "LegacyHostIP"}}{{.address}}{{end}}{{end}}') fi if [ -z "$NODES_IP" ]; then echo "Error: Can't get node's IP!!!" @@ -249,7 +249,7 @@ function getIP { } function getNodePort { -NODE_PORT=$($kubectl get services/frontend -t='{{(index .spec.ports 0).nodePort}}') +NODE_PORT=$($kubectl get services/frontend -o go-template='{{(index .spec.ports 0).nodePort}}') if [ -z "$NODE_PORT" ]; then echo "Error: Can't get NodePort of services/frontend!!!" exit 1 diff --git a/hack/lib/test.sh b/hack/lib/test.sh index 907c2ca0050..9cda34ea56b 100644 --- a/hack/lib/test.sh +++ b/hack/lib/test.sh @@ -31,7 +31,7 @@ kube::test::get_object_assert() { local request=$2 local expected=$3 - res=$(eval kubectl get "${kube_flags[@]}" $object -o template -t \"$request\") + res=$(eval kubectl get "${kube_flags[@]}" $object -o go-template=\"$request\") if [[ "$res" =~ ^$expected$ ]]; then echo -n ${green} @@ -56,7 +56,7 @@ kube::test::get_object_jsonpath_assert() { local request=$2 local expected=$3 - res=$(eval kubectl get "${kube_flags[@]}" $object -o jsonpath -t \"$request\") + res=$(eval kubectl get "${kube_flags[@]}" $object -o jsonpath=\"$request\") if [[ "$res" =~ ^$expected$ ]]; then echo -n ${green} diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index 7ae9c01a863..6209b39ebc2 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -163,14 +163,14 @@ runTests() { -s "http://127.0.0.1:${API_PORT}" --match-server-version ) - [ "$(kubectl get nodes -t '{{ .apiVersion }}' "${kube_flags[@]}")" == "v1" ] + [ "$(kubectl get nodes -o go-template='{{ .apiVersion }}' "${kube_flags[@]}")" == "v1" ] else kube_flags=( -s "http://127.0.0.1:${API_PORT}" --match-server-version --api-version="${version}" ) - [ "$(kubectl get nodes -t '{{ .apiVersion }}' "${kube_flags[@]}")" == "${version}" ] + [ "$(kubectl get nodes -o go-template='{{ .apiVersion }}' "${kube_flags[@]}")" == "${version}" ] fi id_field=".metadata.name" labels_field=".metadata.labels" diff --git a/pkg/kubectl/cmd/get.go b/pkg/kubectl/cmd/get.go index 097183c02fb..e0780a5b2bd 100644 --- a/pkg/kubectl/cmd/get.go +++ b/pkg/kubectl/cmd/get.go @@ -79,7 +79,7 @@ func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command { options := &GetOptions{} cmd := &cobra.Command{ - Use: "get [(-o|--output=)json|yaml|template|templatefile|wide|jsonpath|...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags]", + Use: "get [(-o|--output=)json|yaml|wide|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=...] (TYPE [NAME | -l label] | TYPE/NAME ...) [flags]", Short: "Display one or many resources", Long: get_long, Example: get_example, diff --git a/pkg/kubectl/cmd/util/printing.go b/pkg/kubectl/cmd/util/printing.go index 1d709e3bd69..5205998e39a 100644 --- a/pkg/kubectl/cmd/util/printing.go +++ b/pkg/kubectl/cmd/util/printing.go @@ -19,6 +19,7 @@ package util import ( "fmt" "io" + "strings" "k8s.io/kubernetes/pkg/api/meta" "k8s.io/kubernetes/pkg/kubectl" @@ -28,12 +29,12 @@ import ( // AddPrinterFlags adds printing related flags to a command (e.g. output format, no headers, template path) func AddPrinterFlags(cmd *cobra.Command) { - cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml|template|templatefile|wide|jsonpath|name.") + cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml|wide|name|go-template=...|go-template-file=...|jsonpath=...|jsonpath-file=... See golang template [http://golang.org/pkg/text/template/#pkg-overview] and jsonpath template [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md].") cmd.Flags().String("output-version", "", "Output the formatted object with the given version (default api-version).") cmd.Flags().Bool("no-headers", false, "When using the default output, don't print headers.") // template shorthand -t is deprecated to support -t for --tty // TODO: remove template flag shorthand -t - cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when -o=template, -o=templatefile or -o=jsonpath. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]. The jsonpath template is composed of jsonpath expressions enclosed by {} [http://releases.k8s.io/HEAD/docs/user-guide/jsonpath.md]") + cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].") cmd.Flags().MarkShorthandDeprecated("template", "please use --template instead") cmd.Flags().String("sort-by", "", "If non-empty, sort list types using this field specification. The field specification is expressed as a JSONPath expression (e.g. 'ObjectMeta.Name'). The field in the API resource specified by this JSONPath expression must be an integer or a string.") cmd.Flags().BoolP("show-all", "a", false, "When printing, show all resources (default hide terminated pods.)") @@ -94,6 +95,14 @@ func PrinterForCommand(cmd *cobra.Command) (kubectl.ResourcePrinter, bool, error outputFormat = "template" } + templateFormat := []string{"go-template=", "go-template-file=", "jsonpath=", "jsonpath-file="} + for _, format := range templateFormat { + if strings.HasPrefix(outputFormat, format) { + templateFile = outputFormat[len(format):] + outputFormat = format[:len(format)-1] + } + } + printer, generic, err := kubectl.GetPrinter(outputFormat, templateFile) if err != nil { return nil, generic, err diff --git a/pkg/kubectl/resource_printer.go b/pkg/kubectl/resource_printer.go index e95c859fbf0..fc9ea6b58dd 100644 --- a/pkg/kubectl/resource_printer.go +++ b/pkg/kubectl/resource_printer.go @@ -57,7 +57,7 @@ func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error) { printer = &YAMLPrinter{} case "name": printer = &NamePrinter{} - case "template": + case "template", "go-template": if len(formatArgument) == 0 { return nil, false, fmt.Errorf("template format specified but no template given") } @@ -66,7 +66,7 @@ func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error) { if err != nil { return nil, false, fmt.Errorf("error parsing template %s, %v\n", formatArgument, err) } - case "templatefile": + case "templatefile", "go-template-file": if len(formatArgument) == 0 { return nil, false, fmt.Errorf("templatefile format specified but no template file given") } @@ -80,13 +80,25 @@ func GetPrinter(format, formatArgument string) (ResourcePrinter, bool, error) { } case "jsonpath": if len(formatArgument) == 0 { - return nil, false, fmt.Errorf("jsonpath format specified but no jsonpath template given") + return nil, false, fmt.Errorf("jsonpath template format specified but no template given") } var err error printer, err = NewJSONPathPrinter(formatArgument) if err != nil { return nil, false, fmt.Errorf("error parsing jsonpath %s, %v\n", formatArgument, err) } + case "jsonpath-file": + if len(formatArgument) == 0 { + return nil, false, fmt.Errorf("jsonpath file format specified but no template file file given") + } + data, err := ioutil.ReadFile(formatArgument) + if err != nil { + return nil, false, fmt.Errorf("error reading template %s, %v\n", formatArgument, err) + } + printer, err = NewJSONPathPrinter(string(data)) + if err != nil { + return nil, false, fmt.Errorf("error parsing template %s, %v\n", string(data), err) + } case "wide": fallthrough case "": diff --git a/pkg/util/jsonpath/jsonpath_test.go b/pkg/util/jsonpath/jsonpath_test.go index fa181b34656..9922a8fee21 100644 --- a/pkg/util/jsonpath/jsonpath_test.go +++ b/pkg/util/jsonpath/jsonpath_test.go @@ -34,6 +34,26 @@ type jsonpathTest struct { } func testJSONPath(tests []jsonpathTest, t *testing.T) { + for _, test := range tests { + j := New(test.name) + err := j.Parse(test.template) + if err != nil { + t.Errorf("in %s, parse %s error %v", test.name, test.template, err) + } + buf := new(bytes.Buffer) + err = j.Execute(buf, test.input) + if err != nil { + t.Errorf("in %s, execute error %v", test.name, err) + } + out := buf.String() + if out != test.expect { + t.Errorf(`in %s, expect to get "%s", got "%s"`, test.name, test.expect, out) + } + } +} + +// testJSONPathSortOutput test testcases related to map, the results may print in random order +func testJSONPathSortOutput(tests []jsonpathTest, t *testing.T) { for _, test := range tests { j := New(test.name) err := j.Parse(test.template) @@ -218,8 +238,6 @@ func TestKubenates(t *testing.T) { `127.0.0.1 127.0.0.2 127.0.0.3`}, {"double range", "{range .items[*]}{range .status.addresses[*]}{.address}, {end}{end}", nodesData, `127.0.0.1, 127.0.0.2, 127.0.0.3, `}, - // TODO: fix & uncomment the case bellow (#13024) - // {"recursive name", "{..name}", nodesData, `127.0.0.1 127.0.0.2 myself e2e`}, {"item name", "{.items[*].metadata.name}", nodesData, `127.0.0.1 127.0.0.2`}, {"union nodes capacity", "{.items[*]['metadata.name', 'status.capacity']}", nodesData, `127.0.0.1 127.0.0.2 map[cpu:4] map[cpu:8]`}, @@ -228,4 +246,9 @@ func TestKubenates(t *testing.T) { {"user password", `{.users[?(@.name=="e2e")].user.password}`, &nodesData, "secret"}, } testJSONPath(nodesTests, t) + + randomPrintOrderTests := []jsonpathTest{ + {"recursive name", "{..name}", nodesData, `127.0.0.1 127.0.0.2 myself e2e`}, + } + testJSONPathSortOutput(randomPrintOrderTests, t) } diff --git a/test/e2e/util.go b/test/e2e/util.go index 02ffdb4c513..59f4157abf6 100644 --- a/test/e2e/util.go +++ b/test/e2e/util.go @@ -853,7 +853,7 @@ func cleanup(filePath string, ns string, selectors ...string) { if resources != "" { Failf("Resources left running after stop:\n%s", resources) } - pods := runKubectl("get", "pods", "-l", selector, nsArg, "-t", "{{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}") + pods := runKubectl("get", "pods", "-l", selector, nsArg, "-o", "go-template={{ range .items }}{{ if not .metadata.deletionTimestamp }}{{ .metadata.name }}{{ \"\\n\" }}{{ end }}{{ end }}") if pods != "" { Failf("Pods left unterminated after stop:\n%s", pods) }