Commit add08cb9 authored by Zach Loafman's avatar Zach Loafman

Merge pull request #10491 from JanetKuo/kubectl

Implement 'kubectl get ... -o wide'
parents ffeb9820 682734bc
...@@ -31,7 +31,7 @@ $ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2 ...@@ -31,7 +31,7 @@ $ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2
--merge=true: merge together the full hierarchy of kubeconfig files --merge=true: merge together the full hierarchy of kubeconfig files
--minify=false: remove all information not used by current-context from the output --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. --no-headers=false: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|template|templatefile. -o, --output="": Output format. One of: json|yaml|template|templatefile|wide.
--output-version="": Output the formatted object with the given version (default api-version). --output-version="": Output the formatted object with the given version (default api-version).
--raw=false: display raw byte data --raw=false: display raw byte data
-t, --template="": Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview] -t, --template="": Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]
...@@ -69,6 +69,6 @@ $ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2 ...@@ -69,6 +69,6 @@ $ kubectl config view -o template --template='{{range .users}}{{ if eq .name "e2
### SEE ALSO ### SEE ALSO
* [kubectl config](kubectl_config.md) - config modifies kubeconfig files * [kubectl config](kubectl_config.md) - config modifies kubeconfig files
###### Auto generated by spf13/cobra at 2015-06-09 19:55:35.92095292 +0000 UTC ###### Auto generated by spf13/cobra at 2015-06-30 16:51:25.60964036 +0000 UTC
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_config_view.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_config_view.md?pixel)]()
...@@ -39,7 +39,7 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream ...@@ -39,7 +39,7 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream
-l, --labels="": Labels to apply to the service created by this call. -l, --labels="": Labels to apply to the service created by this call.
--name="": The name for the newly created object. --name="": The name for the newly created object.
--no-headers=false: When using the default output, don't print headers. --no-headers=false: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|template|templatefile. -o, --output="": Output format. One of: json|yaml|template|templatefile|wide.
--output-version="": Output the formatted object with the given version (default api-version). --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. --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. Required. --port=-1: The port that the service should serve on. Required.
...@@ -83,6 +83,6 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream ...@@ -83,6 +83,6 @@ $ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream
### SEE ALSO ### SEE ALSO
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-06-02 11:05:52.857144556 +0000 UTC ###### Auto generated by spf13/cobra at 2015-06-30 16:51:25.609406207 +0000 UTC
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_expose.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_expose.md?pixel)]()
...@@ -16,7 +16,7 @@ By specifying the output as 'template' and providing a Go template as the value ...@@ -16,7 +16,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). of the --template flag, you can filter the attributes of the fetched resource(s).
``` ```
kubectl get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...) kubectl get [(-o|--output=)json|yaml|template|wide|...] (RESOURCE [NAME] | RESOURCE/NAME ...)
``` ```
### Examples ### Examples
...@@ -25,6 +25,9 @@ kubectl get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/N ...@@ -25,6 +25,9 @@ kubectl get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/N
// List all pods in ps output format. // List all pods in ps output format.
$ kubectl get pods $ kubectl get pods
// List all pods in ps output format with more information (such as node name).
$ kubectl get pods -o wide
// List a single replication controller with specified NAME in ps output format. // List a single replication controller with specified NAME in ps output format.
$ kubectl get replicationcontroller web $ kubectl get replicationcontroller web
...@@ -37,7 +40,7 @@ $ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-versi ...@@ -37,7 +40,7 @@ $ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-versi
// List all replication controllers and services together in ps output format. // List all replication controllers and services together in ps output format.
$ kubectl get rc,services $ kubectl get rc,services
// List one or more resources by their type and names // List one or more resources by their type and names.
$ kubectl get rc/web service/frontend pods/web-pod-13je7 $ kubectl get rc/web service/frontend pods/web-pod-13je7
``` ```
...@@ -48,7 +51,7 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7 ...@@ -48,7 +51,7 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7
-h, --help=false: help for get -h, --help=false: help for get
-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... -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. --no-headers=false: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|template|templatefile. -o, --output="": Output format. One of: json|yaml|template|templatefile|wide.
--output-version="": Output the formatted object with the given version (default api-version). --output-version="": Output the formatted object with the given version (default api-version).
-l, --selector="": Selector (label query) to filter on -l, --selector="": Selector (label query) to filter on
-t, --template="": Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview] -t, --template="": Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]
...@@ -88,6 +91,6 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7 ...@@ -88,6 +91,6 @@ $ kubectl get rc/web service/frontend pods/web-pod-13je7
### SEE ALSO ### SEE ALSO
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-06-21 22:41:03.746552518 +0000 UTC ###### Auto generated by spf13/cobra at 2015-06-30 18:05:17.889608636 +0000 UTC
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_get.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_get.md?pixel)]()
...@@ -41,7 +41,7 @@ $ kubectl label pods foo bar- ...@@ -41,7 +41,7 @@ $ kubectl label pods foo bar-
--all=false: select all resources in the namespace of the specified resource types --all=false: select all resources in the namespace of the specified resource types
-h, --help=false: help for label -h, --help=false: help for label
--no-headers=false: When using the default output, don't print headers. --no-headers=false: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|template|templatefile. -o, --output="": Output format. One of: json|yaml|template|templatefile|wide.
--output-version="": Output the formatted object with the given version (default api-version). --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. --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. --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.
...@@ -81,6 +81,6 @@ $ kubectl label pods foo bar- ...@@ -81,6 +81,6 @@ $ kubectl label pods foo bar-
### SEE ALSO ### SEE ALSO
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-05-28 08:44:48.996047458 +0000 UTC ###### Auto generated by spf13/cobra at 2015-06-30 16:51:25.609525621 +0000 UTC
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_label.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_label.md?pixel)]()
...@@ -42,7 +42,7 @@ $ kubectl rolling-update frontend --image=image:v2 ...@@ -42,7 +42,7 @@ $ kubectl rolling-update frontend --image=image:v2
-h, --help=false: help for rolling-update -h, --help=false: help for rolling-update
--image="": Image to use for upgrading the replication controller. Can not be used with --filename/-f --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. --no-headers=false: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|template|templatefile. -o, --output="": Output format. One of: json|yaml|template|templatefile|wide.
--output-version="": Output the formatted object with the given version (default api-version). --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". --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 --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
...@@ -83,6 +83,6 @@ $ kubectl rolling-update frontend --image=image:v2 ...@@ -83,6 +83,6 @@ $ kubectl rolling-update frontend --image=image:v2
### SEE ALSO ### SEE ALSO
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-06-17 14:57:27.791796674 +0000 UTC ###### Auto generated by spf13/cobra at 2015-06-30 16:51:25.608180277 +0000 UTC
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_rolling-update.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_rolling-update.md?pixel)]()
...@@ -38,7 +38,7 @@ $ kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { . ...@@ -38,7 +38,7 @@ $ kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { .
--image="": The image for the container to run. --image="": The image for the container to run.
-l, --labels="": Labels to apply to the pod(s). -l, --labels="": Labels to apply to the pod(s).
--no-headers=false: When using the default output, don't print headers. --no-headers=false: When using the default output, don't print headers.
-o, --output="": Output format. One of: json|yaml|template|templatefile. -o, --output="": Output format. One of: json|yaml|template|templatefile|wide.
--output-version="": Output the formatted object with the given version (default api-version). --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. --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. --port=-1: The port that this container exposes.
...@@ -78,6 +78,6 @@ $ kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { . ...@@ -78,6 +78,6 @@ $ kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { .
### SEE ALSO ### SEE ALSO
* [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager * [kubectl](kubectl.md) - kubectl controls the Kubernetes cluster manager
###### Auto generated by spf13/cobra at 2015-06-05 21:08:36.513272503 +0000 UTC ###### Auto generated by spf13/cobra at 2015-06-30 16:51:25.609119035 +0000 UTC
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_run.md?pixel)]() [![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/kubectl_run.md?pixel)]()
...@@ -42,7 +42,7 @@ You can use \-\-output=template \-\-template=TEMPLATE to extract specific values ...@@ -42,7 +42,7 @@ You can use \-\-output=template \-\-template=TEMPLATE to extract specific values
.PP .PP
\fB\-o\fP, \fB\-\-output\fP="" \fB\-o\fP, \fB\-\-output\fP=""
Output format. One of: json|yaml|template|templatefile. Output format. One of: json|yaml|template|templatefile|wide.
.PP .PP
\fB\-\-output\-version\fP="" \fB\-\-output\-version\fP=""
......
...@@ -56,7 +56,7 @@ re\-use the labels from the resource it exposes. ...@@ -56,7 +56,7 @@ re\-use the labels from the resource it exposes.
.PP .PP
\fB\-o\fP, \fB\-\-output\fP="" \fB\-o\fP, \fB\-\-output\fP=""
Output format. One of: json|yaml|template|templatefile. Output format. One of: json|yaml|template|templatefile|wide.
.PP .PP
\fB\-\-output\-version\fP="" \fB\-\-output\-version\fP=""
......
...@@ -45,7 +45,7 @@ of the \-\-template flag, you can filter the attributes of the fetched resource( ...@@ -45,7 +45,7 @@ of the \-\-template flag, you can filter the attributes of the fetched resource(
.PP .PP
\fB\-o\fP, \fB\-\-output\fP="" \fB\-o\fP, \fB\-\-output\fP=""
Output format. One of: json|yaml|template|templatefile. Output format. One of: json|yaml|template|templatefile|wide.
.PP .PP
\fB\-\-output\-version\fP="" \fB\-\-output\-version\fP=""
...@@ -175,6 +175,9 @@ of the \-\-template flag, you can filter the attributes of the fetched resource( ...@@ -175,6 +175,9 @@ of the \-\-template flag, you can filter the attributes of the fetched resource(
// List all pods in ps output format. // List all pods in ps output format.
$ kubectl get pods $ kubectl get pods
// List all pods in ps output format with more information (such as node name).
$ kubectl get pods \-o wide
// List a single replication controller with specified NAME in ps output format. // List a single replication controller with specified NAME in ps output format.
$ kubectl get replicationcontroller web $ kubectl get replicationcontroller web
...@@ -187,7 +190,7 @@ $ kubectl get \-o template web\-pod\-13je7 \-\-template=\{\{.status.phase\}\} \- ...@@ -187,7 +190,7 @@ $ kubectl get \-o template web\-pod\-13je7 \-\-template=\{\{.status.phase\}\} \-
// List all replication controllers and services together in ps output format. // List all replication controllers and services together in ps output format.
$ kubectl get rc,services $ kubectl get rc,services
// List one or more resources by their type and names // List one or more resources by their type and names.
$ kubectl get rc/web service/frontend pods/web\-pod\-13je7 $ kubectl get rc/web service/frontend pods/web\-pod\-13je7
.fi .fi
......
...@@ -36,7 +36,7 @@ If \-\-resource\-version is specified, then updates will use this resource versi ...@@ -36,7 +36,7 @@ If \-\-resource\-version is specified, then updates will use this resource versi
.PP .PP
\fB\-o\fP, \fB\-\-output\fP="" \fB\-o\fP, \fB\-\-output\fP=""
Output format. One of: json|yaml|template|templatefile. Output format. One of: json|yaml|template|templatefile|wide.
.PP .PP
\fB\-\-output\-version\fP="" \fB\-\-output\-version\fP=""
......
...@@ -48,7 +48,7 @@ existing replication controller and overwrite at least one (common) label in its ...@@ -48,7 +48,7 @@ existing replication controller and overwrite at least one (common) label in its
.PP .PP
\fB\-o\fP, \fB\-\-output\fP="" \fB\-o\fP, \fB\-\-output\fP=""
Output format. One of: json|yaml|template|templatefile. Output format. One of: json|yaml|template|templatefile|wide.
.PP .PP
\fB\-\-output\-version\fP="" \fB\-\-output\-version\fP=""
......
...@@ -48,7 +48,7 @@ Creates a replication controller to manage the created container(s). ...@@ -48,7 +48,7 @@ Creates a replication controller to manage the created container(s).
.PP .PP
\fB\-o\fP, \fB\-\-output\fP="" \fB\-o\fP, \fB\-\-output\fP=""
Output format. One of: json|yaml|template|templatefile. Output format. One of: json|yaml|template|templatefile|wide.
.PP .PP
\fB\-\-output\-version\fP="" \fB\-\-output\-version\fP=""
......
...@@ -140,7 +140,7 @@ func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) { ...@@ -140,7 +140,7 @@ func NewTestFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) { Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
return t.Describer, t.Err return t.Describer, t.Err
}, },
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, columnLabels []string) (kubectl.ResourcePrinter, error) { Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
return t.Printer, t.Err return t.Printer, t.Err
}, },
Validator: func() (validation.Schema, error) { Validator: func() (validation.Schema, error) {
...@@ -194,7 +194,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) { ...@@ -194,7 +194,7 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
Describer: func(*meta.RESTMapping) (kubectl.Describer, error) { Describer: func(*meta.RESTMapping) (kubectl.Describer, error) {
return t.Describer, t.Err return t.Describer, t.Err
}, },
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, columnLabels []string) (kubectl.ResourcePrinter, error) { Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
return t.Printer, t.Err return t.Printer, t.Err
}, },
Validator: func() (validation.Schema, error) { Validator: func() (validation.Schema, error) {
...@@ -243,7 +243,7 @@ func stringBody(body string) io.ReadCloser { ...@@ -243,7 +243,7 @@ func stringBody(body string) io.ReadCloser {
func ExamplePrintReplicationController() { func ExamplePrintReplicationController() {
f, tf, codec := NewAPIFactory() f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, []string{}) tf.Printer = kubectl.NewHumanReadablePrinter(false, false, false, []string{})
tf.Client = &client.FakeRESTClient{ tf.Client = &client.FakeRESTClient{
Codec: codec, Codec: codec,
Client: nil, Client: nil,
...@@ -281,6 +281,38 @@ func ExamplePrintReplicationController() { ...@@ -281,6 +281,38 @@ func ExamplePrintReplicationController() {
// foo foo someimage foo=bar 1 // foo foo someimage foo=bar 1
} }
func ExamplePrintPodWithWideFormat() {
f, tf, codec := NewAPIFactory()
tf.Printer = kubectl.NewHumanReadablePrinter(false, false, true, []string{})
tf.Client = &client.FakeRESTClient{
Codec: codec,
Client: nil,
}
nodeName := "kubernetes-minion-abcd"
cmd := NewCmdRun(f, os.Stdout)
ctrl := &api.Pod{
ObjectMeta: api.ObjectMeta{Name: "test1"},
Spec: api.PodSpec{
Containers: make([]api.Container, 2),
NodeName: nodeName,
},
Status: api.PodStatus{
Phase: "podPhase",
ContainerStatuses: []api.ContainerStatus{
{Ready: true, RestartCount: 3, State: api.ContainerState{Running: &api.ContainerStateRunning{}}},
{RestartCount: 3},
},
},
}
err := f.PrintObject(cmd, ctrl, os.Stdout)
if err != nil {
fmt.Printf("Unexpected error: %v", err)
}
// Output:
// NAME READY REASON RESTARTS AGE NODE
// test1 1/2 podPhase 6 292y kubernetes-minion-abcd
}
func TestNormalizationFuncGlobalExistance(t *testing.T) { func TestNormalizationFuncGlobalExistance(t *testing.T) {
// This test can be safely deleted when we will not support multiple flag formats // This test can be safely deleted when we will not support multiple flag formats
root := NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr) root := NewKubectlCommand(cmdutil.NewFactory(nil), os.Stdin, os.Stdout, os.Stderr)
......
...@@ -43,6 +43,9 @@ of the --template flag, you can filter the attributes of the fetched resource(s) ...@@ -43,6 +43,9 @@ of the --template flag, you can filter the attributes of the fetched resource(s)
get_example = `// List all pods in ps output format. get_example = `// List all pods in ps output format.
$ kubectl get pods $ kubectl get pods
// List all pods in ps output format with more information (such as node name).
$ kubectl get pods -o wide
// List a single replication controller with specified NAME in ps output format. // List a single replication controller with specified NAME in ps output format.
$ kubectl get replicationcontroller web $ kubectl get replicationcontroller web
...@@ -55,18 +58,18 @@ $ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-versi ...@@ -55,18 +58,18 @@ $ kubectl get -o template web-pod-13je7 --template={{.status.phase}} --api-versi
// List all replication controllers and services together in ps output format. // List all replication controllers and services together in ps output format.
$ kubectl get rc,services $ kubectl get rc,services
// List one or more resources by their type and names // List one or more resources by their type and names.
$ kubectl get rc/web service/frontend pods/web-pod-13je7` $ kubectl get rc/web service/frontend pods/web-pod-13je7`
) )
// NewCmdGet creates a command object for the generic "get" action, which // NewCmdGet creates a command object for the generic "get" action, which
// retrieves one or more resources from a server. // retrieves one or more resources from a server.
func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command { func NewCmdGet(f *cmdutil.Factory, out io.Writer) *cobra.Command {
p := kubectl.NewHumanReadablePrinter(false, false, []string{}) p := kubectl.NewHumanReadablePrinter(false, false, false, []string{})
validArgs := p.HandledResources() validArgs := p.HandledResources()
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)", Use: "get [(-o|--output=)json|yaml|template|wide|...] (RESOURCE [NAME] | RESOURCE/NAME ...)",
Short: "Display one or many resources", Short: "Display one or many resources",
Long: get_long, Long: get_long,
Example: get_example, Example: get_example,
......
...@@ -65,7 +65,7 @@ type Factory struct { ...@@ -65,7 +65,7 @@ type Factory struct {
// Returns a Describer for displaying the specified RESTMapping type or an error. // Returns a Describer for displaying the specified RESTMapping type or an error.
Describer func(mapping *meta.RESTMapping) (kubectl.Describer, error) Describer func(mapping *meta.RESTMapping) (kubectl.Describer, error)
// Returns a Printer for formatting objects of the given type or an error. // Returns a Printer for formatting objects of the given type or an error.
Printer func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, columnLabels []string) (kubectl.ResourcePrinter, error) Printer func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, columnLabels []string) (kubectl.ResourcePrinter, error)
// Returns a Scaler for changing the size of the specified RESTMapping type or an error // Returns a Scaler for changing the size of the specified RESTMapping type or an error
Scaler func(mapping *meta.RESTMapping) (kubectl.Scaler, error) Scaler func(mapping *meta.RESTMapping) (kubectl.Scaler, error)
// Returns a Reaper for gracefully shutting down resources. // Returns a Reaper for gracefully shutting down resources.
...@@ -141,8 +141,8 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory { ...@@ -141,8 +141,8 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
} }
return describer, nil return describer, nil
}, },
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, columnLabels []string) (kubectl.ResourcePrinter, error) { Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
return kubectl.NewHumanReadablePrinter(noHeaders, withNamespace, columnLabels), nil return kubectl.NewHumanReadablePrinter(noHeaders, withNamespace, wide, columnLabels), nil
}, },
PodSelectorForObject: func(object runtime.Object) (string, error) { PodSelectorForObject: func(object runtime.Object) (string, error) {
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection) // TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
...@@ -382,7 +382,7 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin ...@@ -382,7 +382,7 @@ func (f *Factory) PrinterForMapping(cmd *cobra.Command, mapping *meta.RESTMappin
} }
printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version, mapping.APIVersion) printer = kubectl.NewVersionedPrinter(printer, mapping.ObjectConvertor, version, mapping.APIVersion)
} else { } else {
printer, err = f.Printer(mapping, GetFlagBool(cmd, "no-headers"), withNamespace, GetFlagStringList(cmd, "label-columns")) printer, err = f.Printer(mapping, GetFlagBool(cmd, "no-headers"), withNamespace, GetWideFlag(cmd), GetFlagStringList(cmd, "label-columns"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -275,6 +275,15 @@ func GetFlagStringList(cmd *cobra.Command, flag string) util.StringList { ...@@ -275,6 +275,15 @@ func GetFlagStringList(cmd *cobra.Command, flag string) util.StringList {
return *f.Value.(*util.StringList) return *f.Value.(*util.StringList)
} }
// GetWideFlag is used to determine if "-o wide" is used
func GetWideFlag(cmd *cobra.Command) bool {
f := cmd.Flags().Lookup("output")
if f.Value.String() == "wide" {
return true
}
return false
}
func GetFlagBool(cmd *cobra.Command, flag string) bool { func GetFlagBool(cmd *cobra.Command, flag string) bool {
f := getFlag(cmd, flag) f := getFlag(cmd, flag)
result, err := strconv.ParseBool(f.Value.String()) result, err := strconv.ParseBool(f.Value.String())
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
// AddPrinterFlags adds printing related flags to a command (e.g. output format, no headers, template path) // AddPrinterFlags adds printing related flags to a command (e.g. output format, no headers, template path)
func AddPrinterFlags(cmd *cobra.Command) { func AddPrinterFlags(cmd *cobra.Command) {
cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml|template|templatefile.") cmd.Flags().StringP("output", "o", "", "Output format. One of: json|yaml|template|templatefile|wide.")
cmd.Flags().String("output-version", "", "Output the formatted object with the given version (default api-version).") 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.") cmd.Flags().Bool("no-headers", false, "When using the default output, don't print headers.")
cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]") cmd.Flags().StringP("template", "t", "", "Template string or path to template file to use when -o=template or -o=templatefile. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview]")
......
...@@ -237,18 +237,18 @@ type TestUnknownType struct{} ...@@ -237,18 +237,18 @@ type TestUnknownType struct{}
func (*TestUnknownType) IsAnAPIObject() {} func (*TestUnknownType) IsAnAPIObject() {}
func PrintCustomType(obj *TestPrintType, w io.Writer, withNamespace bool, columnLabels []string) error { func PrintCustomType(obj *TestPrintType, w io.Writer, withNamespace bool, wide bool, columnLabels []string) error {
_, err := fmt.Fprintf(w, "%s", obj.Data) _, err := fmt.Fprintf(w, "%s", obj.Data)
return err return err
} }
func ErrorPrintHandler(obj *TestPrintType, w io.Writer, withNamespace bool, columnLabels []string) error { func ErrorPrintHandler(obj *TestPrintType, w io.Writer, withNamespace bool, wide bool, columnLabels []string) error {
return fmt.Errorf("ErrorPrintHandler error") return fmt.Errorf("ErrorPrintHandler error")
} }
func TestCustomTypePrinting(t *testing.T) { func TestCustomTypePrinting(t *testing.T) {
columns := []string{"Data"} columns := []string{"Data"}
printer := NewHumanReadablePrinter(false, false, []string{}) printer := NewHumanReadablePrinter(false, false, false, []string{})
printer.Handler(columns, PrintCustomType) printer.Handler(columns, PrintCustomType)
obj := TestPrintType{"test object"} obj := TestPrintType{"test object"}
...@@ -265,7 +265,7 @@ func TestCustomTypePrinting(t *testing.T) { ...@@ -265,7 +265,7 @@ func TestCustomTypePrinting(t *testing.T) {
func TestPrintHandlerError(t *testing.T) { func TestPrintHandlerError(t *testing.T) {
columns := []string{"Data"} columns := []string{"Data"}
printer := NewHumanReadablePrinter(false, false, []string{}) printer := NewHumanReadablePrinter(false, false, false, []string{})
printer.Handler(columns, ErrorPrintHandler) printer.Handler(columns, ErrorPrintHandler)
obj := TestPrintType{"test object"} obj := TestPrintType{"test object"}
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
...@@ -276,7 +276,7 @@ func TestPrintHandlerError(t *testing.T) { ...@@ -276,7 +276,7 @@ func TestPrintHandlerError(t *testing.T) {
} }
func TestUnknownTypePrinting(t *testing.T) { func TestUnknownTypePrinting(t *testing.T) {
printer := NewHumanReadablePrinter(false, false, []string{}) printer := NewHumanReadablePrinter(false, false, false, []string{})
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
err := printer.PrintObj(&TestUnknownType{}, buffer) err := printer.PrintObj(&TestUnknownType{}, buffer)
if err == nil { if err == nil {
...@@ -452,8 +452,8 @@ func TestPrinters(t *testing.T) { ...@@ -452,8 +452,8 @@ func TestPrinters(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
printers := map[string]ResourcePrinter{ printers := map[string]ResourcePrinter{
"humanReadable": NewHumanReadablePrinter(true, false, []string{}), "humanReadable": NewHumanReadablePrinter(true, false, false, []string{}),
"humanReadableHeaders": NewHumanReadablePrinter(false, false, []string{}), "humanReadableHeaders": NewHumanReadablePrinter(false, false, false, []string{}),
"json": &JSONPrinter{}, "json": &JSONPrinter{},
"yaml": &YAMLPrinter{}, "yaml": &YAMLPrinter{},
"template": templatePrinter, "template": templatePrinter,
...@@ -490,7 +490,7 @@ func TestPrinters(t *testing.T) { ...@@ -490,7 +490,7 @@ func TestPrinters(t *testing.T) {
func TestPrintEventsResultSorted(t *testing.T) { func TestPrintEventsResultSorted(t *testing.T) {
// Arrange // Arrange
printer := NewHumanReadablePrinter(false /* noHeaders */, false, []string{}) printer := NewHumanReadablePrinter(false /* noHeaders */, false, false, []string{})
obj := api.EventList{ obj := api.EventList{
Items: []api.Event{ Items: []api.Event{
...@@ -531,7 +531,7 @@ func TestPrintEventsResultSorted(t *testing.T) { ...@@ -531,7 +531,7 @@ func TestPrintEventsResultSorted(t *testing.T) {
} }
func TestPrintMinionStatus(t *testing.T) { func TestPrintMinionStatus(t *testing.T) {
printer := NewHumanReadablePrinter(false, false, []string{}) printer := NewHumanReadablePrinter(false, false, false, []string{})
table := []struct { table := []struct {
minion api.Node minion api.Node
status string status string
...@@ -739,7 +739,7 @@ func TestPrintHumanReadableService(t *testing.T) { ...@@ -739,7 +739,7 @@ func TestPrintHumanReadableService(t *testing.T) {
for _, svc := range tests { for _, svc := range tests {
buff := bytes.Buffer{} buff := bytes.Buffer{}
printService(&svc, &buff, false, []string{}) printService(&svc, &buff, false, false, []string{})
output := string(buff.Bytes()) output := string(buff.Bytes())
ip := svc.Spec.ClusterIP ip := svc.Spec.ClusterIP
if !strings.Contains(output, ip) { if !strings.Contains(output, ip) {
...@@ -921,7 +921,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) { ...@@ -921,7 +921,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
}, },
} }
printer := NewHumanReadablePrinter(false, false, []string{}) printer := NewHumanReadablePrinter(false, false, false, []string{})
for _, test := range table { for _, test := range table {
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
err := printer.PrintObj(test.obj, buffer) err := printer.PrintObj(test.obj, buffer)
...@@ -934,7 +934,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) { ...@@ -934,7 +934,7 @@ func TestPrintHumanReadableWithNamespace(t *testing.T) {
} }
} }
printer = NewHumanReadablePrinter(false, true, []string{}) printer = NewHumanReadablePrinter(false, true, false, []string{})
for _, test := range table { for _, test := range table {
buffer := &bytes.Buffer{} buffer := &bytes.Buffer{}
err := printer.PrintObj(test.obj, buffer) err := printer.PrintObj(test.obj, buffer)
...@@ -1035,7 +1035,7 @@ func TestPrintPod(t *testing.T) { ...@@ -1035,7 +1035,7 @@ func TestPrintPod(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
for _, test := range tests { for _, test := range tests {
printPod(&test.pod, buf, false, []string{}) printPod(&test.pod, buf, false, false, []string{})
// We ignore time // We ignore time
if !strings.HasPrefix(buf.String(), test.expect) { if !strings.HasPrefix(buf.String(), test.expect) {
t.Fatalf("Expected: %s, got: %s", test.expect, buf.String()) t.Fatalf("Expected: %s, got: %s", test.expect, buf.String())
...@@ -1095,7 +1095,7 @@ func TestPrintPodWithLabels(t *testing.T) { ...@@ -1095,7 +1095,7 @@ func TestPrintPodWithLabels(t *testing.T) {
buf := bytes.NewBuffer([]byte{}) buf := bytes.NewBuffer([]byte{})
for _, test := range tests { for _, test := range tests {
printPod(&test.pod, buf, false, test.labelColumns) printPod(&test.pod, buf, false, false, test.labelColumns)
// We ignore time // We ignore time
if !strings.HasPrefix(buf.String(), test.startsWith) || !strings.HasSuffix(buf.String(), test.endsWith) { if !strings.HasPrefix(buf.String(), test.startsWith) || !strings.HasSuffix(buf.String(), test.endsWith) {
t.Fatalf("Expected to start with: %s and end with: %s, but got: %s", test.startsWith, test.endsWith, buf.String()) t.Fatalf("Expected to start with: %s and end with: %s, but got: %s", test.startsWith, test.endsWith, buf.String())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment