Commit Graph

154 Commits (92cb90fc5d118ed5c892f425ed1ded5290894db5)

Author SHA1 Message Date
AdoHe b2280a646a update various commands to adapt the new Factory interface 2016-10-13 21:01:14 +08:00
Kubernetes Submit Queue b8b7f9ffc0 Merge pull request #32722 from juanvallejo/jvallejo_return-err-on-oc-get-empty-list
Automatic merge from submit-queue

return warning on empty list result in kubectl get

**Release note**:
```release-note
NONE
```

The current default behavior of `kubectl get` is to return an empty
output when there are no resources to display. This patch improves
usability by returning a warning through stderr in the case of an empty
list.

##### Before
`$ kubectl get pods`
  - *empty output*

##### After
`$ kubectl get pods`
```
There are no resources to display.
```
2016-10-12 23:48:01 -07:00
Jordan Liggitt 82a099d92d
Simplify kubectl get --raw 2016-10-06 11:42:19 -04:00
bindata-mockuser 5ad518cd2b Switch kubectl to use watch.Until 2016-10-03 17:17:41 +02:00
Kubernetes Submit Queue b840605197 Merge pull request #33677 from juanvallejo/jvallejo/add-linebreak-between-resource-groups
Automatic merge from submit-queue

add linebreak between resource groups

**Release note**:
```release-note
release-note-none
```

Printing multiple groups via `kubectl get all` can produce output that is
hard to read in cases where there are a lot of resource types to display
/ some resource types contain varying column amounts.

This patch adds a linebreak above each group of resources only when
there is more than one group to display, and always omitting the
linebreak above the first group. This makes for slightly improved
output.

Linebreaks are printed to stderr, and honor the `--no-headers` option.

**Before**

```
$ kubectl get all
NAME                     READY     STATUS    RESTARTS   AGE
po/database-1-u9m9l      1/1       Running   3          5d
po/idling-echo-1-9fmz6   2/2       Running   8          5d
po/idling-echo-1-gzb0v   2/2       Running   4          5d
NAME               DESIRED   CURRENT   READY     AGE
rc/database-1      1         1         1         6d
rc/idling-echo-1   2         2         2         6d
NAME              CLUSTER-IP       EXTERNAL-IP   PORT(S)
AGE
svc/database      172.30.11.104    <none>        5434/TCP
6d
svc/frontend      172.30.196.217   <none>        5432/TCP
6d
svc/idling-echo   172.30.115.67    <none>        8675/TCP,3090/UDP
6d
svc/kubernetes    172.30.0.1       <none>        443/TCP,53/UDP,53/TCP
6d
svc/mynodeport    172.30.81.254    <nodes>       8080/TCP
5d
svc/mynodeport1   172.30.198.193   <nodes>       8080/TCP
5d
svc/mynodeport2   172.30.149.48    <nodes>       8080/TCP
5d
svc/mynodeport3   172.30.195.235   <nodes>       8080/TCP
5d
```

**After**

```
$ kubectl get all
NAME                     READY     STATUS    RESTARTS   AGE
po/database-1-u9m9l      1/1       Running   3          5d
po/idling-echo-1-9fmz6   2/2       Running   8          5d
po/idling-echo-1-gzb0v   2/2       Running   4          5d

NAME               DESIRED   CURRENT   READY     AGE
rc/database-1      1         1         1         6d
rc/idling-echo-1   2         2         2         6d

NAME              CLUSTER-IP       EXTERNAL-IP   PORT(S)
AGE
svc/database      172.30.11.104    <none>        5434/TCP
6d
svc/frontend      172.30.196.217   <none>        5432/TCP
6d
svc/idling-echo   172.30.115.67    <none>        8675/TCP,3090/UDP
6d
svc/kubernetes    172.30.0.1       <none>        443/TCP,53/UDP,53/TCP
6d
svc/mynodeport    172.30.81.254    <nodes>       8080/TCP
5d
svc/mynodeport1   172.30.198.193   <nodes>       8080/TCP
5d
svc/mynodeport2   172.30.149.48    <nodes>       8080/TCP
5d
svc/mynodeport3   172.30.195.235   <nodes>       8080/TCP
5d
```

cc @fabianofranz @liggitt
2016-09-28 23:13:07 -07:00
juanvallejo 0988f967f0 add check to NewCmdExec before printing suggestion
checks that the "describe" command and a parent command path exist
before printing suggestion to use the describe command to list
containers in a pod.
2016-09-28 18:02:33 -04:00
juanvallejo 48370b2802 suggest use of `kube explain <resource>` in kube get output
This patch improves usability flow, making it easier for a user to
discover the command `kube explain <resource>` through `kube get`
output.
2016-09-28 14:54:15 -04:00
juanvallejo 735fbf9c09
add linebreak between resource groups
Printing multiple groups via `kubectl get all` can produce output that is
hard to read in cases where there are a lot of resource types to display
/ some resource types contain varying column amounts.

This patch adds a linebreak above each group of resources only when
there is more than one group to display, and always omitting the
linebreak above the first group. This makes for slightly improved
output.

Linebreaks are printed to stderr, and honor the `--no-headers` option.

**Before**

```
$ kubectl get all
NAME                     READY     STATUS    RESTARTS   AGE
po/database-1-u9m9l      1/1       Running   3          5d
po/idling-echo-1-9fmz6   2/2       Running   8          5d
po/idling-echo-1-gzb0v   2/2       Running   4          5d
NAME               DESIRED   CURRENT   READY     AGE
rc/database-1      1         1         1         6d
rc/idling-echo-1   2         2         2         6d
NAME              CLUSTER-IP       EXTERNAL-IP   PORT(S)
AGE
svc/database      172.30.11.104    <none>        5434/TCP
6d
svc/frontend      172.30.196.217   <none>        5432/TCP
6d
svc/idling-echo   172.30.115.67    <none>        8675/TCP,3090/UDP
6d
svc/kubernetes    172.30.0.1       <none>        443/TCP,53/UDP,53/TCP
6d
svc/mynodeport    172.30.81.254    <nodes>       8080/TCP
5d
svc/mynodeport1   172.30.198.193   <nodes>       8080/TCP
5d
svc/mynodeport2   172.30.149.48    <nodes>       8080/TCP
5d
svc/mynodeport3   172.30.195.235   <nodes>       8080/TCP
5d
```

**After**

```
$ kubectl get all
NAME                     READY     STATUS    RESTARTS   AGE
po/database-1-u9m9l      1/1       Running   3          5d
po/idling-echo-1-9fmz6   2/2       Running   8          5d
po/idling-echo-1-gzb0v   2/2       Running   4          5d

NAME               DESIRED   CURRENT   READY     AGE
rc/database-1      1         1         1         6d
rc/idling-echo-1   2         2         2         6d

NAME              CLUSTER-IP       EXTERNAL-IP   PORT(S)
AGE
svc/database      172.30.11.104    <none>        5434/TCP
6d
svc/frontend      172.30.196.217   <none>        5432/TCP
6d
svc/idling-echo   172.30.115.67    <none>        8675/TCP,3090/UDP
6d
svc/kubernetes    172.30.0.1       <none>        443/TCP,53/UDP,53/TCP
6d
svc/mynodeport    172.30.81.254    <nodes>       8080/TCP
5d
svc/mynodeport1   172.30.198.193   <nodes>       8080/TCP
5d
svc/mynodeport2   172.30.149.48    <nodes>       8080/TCP
5d
svc/mynodeport3   172.30.195.235   <nodes>       8080/TCP
5d
```
2016-09-28 14:21:46 -04:00
juanvallejo 7a5ed25c61 return warning on empty list result in kubectl get
The current default behavior of `kubectl get` is to return an empty
output when there are no resources to display. This patch improves
usability by returning a warning through stderr in the case of an empty
list.
2016-09-28 10:41:24 -04:00
Clayton Coleman 9bfa63dbba
Unwrap aggregates of size 1 when writing errors
Also, only use aggregate in get when we actually are dealing with
multiple errors.
2016-09-26 15:56:38 -04:00
juanvallejo 7000e2cf4f
add resource handling before printing
Resources are currently filtered (in order to prevent printing) at print
time in their HumanReadablePrinter handlers. This design makes it not
possible to filter objects when they are printed using any other
printer, such as YAML, JSON, or the NamePrinter.

This patch removes any filters previously added at the printer level for
pods and adds a way to define resource-specific filters before they are
sent to a printer handler. A woking filter handler for pods has also
been
implemented.

Filters affect resources being printed through the HumanReadablePrinter,
YAML, JSON, and `--template` printers.
2016-09-21 10:03:59 -04:00
Kubernetes Submit Queue 2941069307 Merge pull request #32894 from deads2k/cli-01-remove-arg
Automatic merge from submit-queue

make --include-extended-apis deprecated and remove plumbing

Marks a dead CLI parameter as deprecated and removes the plumbing for it.
2016-09-19 21:11:04 -07:00
Kubernetes Submit Queue 051ee17094 Merge pull request #30815 from ymqytw/refactoring
Automatic merge from submit-queue

Fixes #30562: Refactor kubectl command options to use common struct for common file params

Fixes #30562 : Refactor common go struct options in pkg/kubectl/cmd/*.go.
@pwittrock
2016-09-16 19:48:22 -07:00
deads2k 862415aaa2 make --include-extended-apis deprecated and remove plumbing 2016-09-16 16:05:52 -04:00
ymqytw c67a62da49 Fixes #30562: Refactor kubectl command options to use common struct for common file params 2016-09-12 11:01:37 -07:00
deads2k 9d43f7e52c convert more command to use a generated clientset 2016-09-12 07:38:34 -04:00
Kubernetes Submit Queue 19364c2d3b Merge pull request #32222 from juanvallejo/jvallejo_bugfix/single-resource-prefix-kubectl-get-all
Automatic merge from submit-queue

print resource kind prefix when `kubectl get all` has single type to display

**Release note**:
```release-note
NONE
```

This patch forces the HumanReadablePrinter to display resource kind
prefixes when there is only one type of resource to show and a specific
resource type has not been specified as an argument to kubectl get

`$ kubectl get all`
```
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)                 AGE
kubernetes   172.30.0.1   <none>        443/TCP,53/UDP,53/TCP   2m
```

`$ kubectl get all`
```
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)                 AGE
svc/kubernetes   172.30.0.1   <none>        443/TCP,53/UDP,53/TCP   2m
```
2016-09-11 19:39:17 -07:00
Angus Salkeld ee298a80e9 Simplify the output in AfterPrint()
- Change FinishPrint() to AfterPrint()
  (As suggested in #31160)
- add a newline to separate it from the table
- remove the "objects" and ()
- assume plural
2016-09-08 09:42:17 +10:00
juanvallejo 59ba00f822
print resource kind prefix when `kubectl get all` has single type to display
This patch forces the HumanReadablePrinter to display resource kind
prefixes when there is only one type of resource to show and a specific
resource type has not been specified as an argument to kubectl get

`$ kubectl get all`
```
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)                 AGE
kubernetes   172.30.0.1   <none>        443/TCP,53/UDP,53/TCP   2m
```

`$ kubectl get all`
```
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)                 AGE
svc/kubernetes   172.30.0.1   <none>        443/TCP,53/UDP,53/TCP   2m
    ```
2016-09-07 16:12:34 -04:00
lojies f21c37db64 change to stderr 2016-08-23 14:51:56 +08:00
Kubernetes Submit Queue 3787a068fc Merge pull request #30955 from lojies/modifygetresource
Automatic merge from submit-queue

use valid_resources to replace kubectl.PossibleResourceTypes

```release
Fix resource list printed by kubectl help 
```

 `kubectl get` return 

> 
You must specify the type of resource to get. Valid resource types include:
   * componentstatuses (aka 'cs')
   * configmaps
   * daemonsets (aka 'ds')
   * deployments
   * events (aka 'ev')
   * endpoints (aka 'ep')
   * horizontalpodautoscalers (aka 'hpa')
   * ingress (aka 'ing')
   * jobs
   * limitranges (aka 'limits')
   * nodes (aka 'no')
   * namespaces (aka 'ns')
   * pods (aka 'po')
   * persistentvolumes (aka 'pv')
   * persistentvolumeclaims (aka 'pvc')
   * quota
   * resourcequotas (aka 'quota')
   * replicasets (aka 'rs')
   * replicationcontrollers (aka 'rc')
   * secrets
   * serviceaccounts (aka 'sa')
   * services (aka 'svc')
error: Required resource not specified.
See 'kubectl get -h' for help and examples.

while `kubectl get --help` return

> root@k8s-node1:~# kubectl get --help
Display one or many resources.
Possible resource types include (case insensitive): pods (po), services (svc), deployments,
replicasets (rs), replicationcontrollers (rc), nodes (no), events (ev), limitranges (limits),
persistentvolumes (pv), persistentvolumeclaims (pvc), resourcequotas (quota), namespaces (ns),
serviceaccounts (sa), ingresses (ing), horizontalpodautoscalers (hpa), daemonsets (ds), configmaps,
componentstatuses (cs), endpoints (ep), and secrets.
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.PossibleResourceTypes missing some resouces such as jobs quota.
describe and explain have the same problem.

i think using valid_resources to replace kubectl.PossibleResourceTypes more suitable.
2016-08-19 15:49:15 -07:00
Kubernetes Submit Queue 56045bbd6a Merge pull request #30971 from lojies/removenil
Automatic merge from submit-queue

remove unnecessary err == nil

because if err != nil has returned err, so remove unnecessary err == nil.
2016-08-19 15:48:23 -07:00
lojies a459a4a188 remove unnecessary err == nil 2016-08-19 14:34:27 +08:00
lojies f81fef1f04 use valid_resources to replace kubectl.PossibleResourceTypes 2016-08-19 09:42:46 +08:00
deads2k 1ed263e0e5 add --raw for kubectl get 2016-08-17 08:45:50 -04:00
vefimova f20c40ed65 Added warning msg for `kubectl get`
- added warning description regarding terminated objects to `get` long help message
  - added printing of warning message in case of `get pods` if there are hidden pods
Fixes #22986
2016-08-15 22:49:37 +00:00
Kubernetes Submit Queue 6f20321833 Merge pull request #28509 from juanvallejo/jvallejo_update-human-readable-printer-signature
Automatic merge from submit-queue

Update HumanResourcePrinter signature w single PrintOptions param

release-note-none

- Makes [HumanReadablePrinter options field non-exported again](https://github.com/kubernetes/kubernetes/blob/master/pkg/kubectl/resource_printer.go#L346-349)
- Adds test-case for HumanReadablePrinter resource printing with aliases.
- Better formatting for saving resource "kind" aliases

[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/.github/PULL_REQUEST_TEMPLATE.md?pixel)]()

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.kubernetes.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.kubernetes.io/reviews/kubernetes/kubernetes/28509)
<!-- Reviewable:end -->
2016-08-12 07:27:56 -07:00
juanvallejo 620758c7e9 format resource printing with aliases 2016-08-04 12:01:25 -04:00
Kubernetes Submit Queue 4f9c3d52b2 Merge pull request #29163 from lojies/adderr
Automatic merge from submit-queue

add err return

Since err can be returned by previous code,  add err return.
2016-08-02 21:39:39 -07:00
Kubernetes Submit Queue f2a9ba2339 Merge pull request #27392 from sjenning/old-kubectl-watch
Automatic merge from submit-queue

allow watching old resources with kubectl

Right now, one can not watch a resource with kubectl whose resourceVersion is outside the etcd watch window.  Specifying resourceVersion=0 returns the current object, then watches from the current index.

This PR changes the logic to use resourceVersion=0, which will work regardless of the resourceVersion of the object, and discard the first event if --watch-only is specified.

@ncdc @aveshagarwal
2016-08-02 14:44:20 -07:00
Seth Jennings 461faae367 allow watching old resources with kubectl 2016-08-02 10:28:04 -05:00
lojies bf24ff00eb add err return 2016-07-26 08:55:53 +08:00
k8s-merge-robot b4b430bf0d Merge pull request #28833 from tnguyen-rh/fix-docstring
Automatic merge from submit-queue

Fix docstring: Say "flag options" instead of "flag statements"

[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/.github/PULL_REQUEST_TEMPLATE.md?pixel)]()
2016-07-25 16:16:06 -07:00
Thien-Thi Nguyen 165363a834 Fix docstring: Say "flag options" instead of "flag statements" 2016-07-18 11:58:40 +02:00
Ivan Shvedunov 5ed881c6c4 Refactor Printer arguments
Fixes #21260
2016-07-14 16:23:02 +03:00
Davanum Srinivas 09fee66783
Add custom-columns and custom-template-file to --help text
Fixes #28314
2016-07-06 09:02:50 -04:00
k8s-merge-robot fe07ca6c86 Merge pull request #27379 from juanvallejo/jvallejo_kube-get-all-show-kind-in-headers
Automatic merge from submit-queue

Update "kubectl get all" to display resource type as part of name

fixes #23838
release-note-none

When running "kubectl get all", or printing any output with mixed resource kinds, an additional column is added to the output with each resource's kind:

`kubectl get all --all-namespaces`
```
NAMESPACE     NAME                         DESIRED          CURRENT       AGE
default       rc/docker-registry-1         1                1             23h
testproject   rc/node-1                    0                0             2d
NAMESPACE     NAME                         CLUSTER-IP       EXTERNAL-IP   PORT(S)                 AGE
default       svc/docker-registry          172.30.36.42     <none>        5000/TCP                23h
default       svc/kubernetes               172.30.0.1       <none>        443/TCP,53/UDP,53/TCP   7d
testproject   svc/ruby-ex                  172.30.187.128   <none>        8080/TCP                6d
NAMESPACE     NAME                         READY            STATUS        RESTARTS                AGE
default       po/docker-registry-1-cpf8o   1/1              Running       1                       23h
```

[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/.github/PULL_REQUEST_TEMPLATE.md?pixel)]()
2016-07-01 14:15:05 -07:00
juanvallejo 7df60d6b64 display resource type as part of its name 2016-07-01 12:58:02 -04:00
Andy Goldstein 67d929a3d2 Return immediately for singular get on error
Return immediately when attempting to get a singular resource that isn't found, so that we avoid
printing out a List if the output format is something like json or yaml.

Before:

```
$ kubectl get pod/foo -o yaml
apiVersion: v1
items: []
kind: List
metadata: {}
pods "foo" not found
```

After:

```
$ kubectl get pod/foo -o yaml
pods "foo" not found
```
2016-06-30 12:28:51 -04:00
David McMahon ef0c9f0c5b Remove "All rights reserved" from all the headers. 2016-06-29 17:47:36 -07:00
Michael Rubin 760b04e294 Use dedent for the kubectl commands
The one side effect is that for the "kubectl help" commands a newline
is prepended to output, which will alter the yaml output.

Here we use dedent to format the code to match the output.

hack/update-generated-docs.sh has been run and the affected files have
been added.

Note: for describe.go we added a period to the end of an output message.
2016-06-26 22:51:14 -07:00
Mike Metral 4409eed57f fix recursive & non-recursive kubectl get of generic output format 2016-06-02 21:46:15 -07:00
Mike Metral 950612eb5f fix recursive get for proper err display 2016-05-24 20:05:07 -07:00
Jeff Lowdermilk e9aecf6b9e Merge pull request #25181 from janetkuo/kubectl-suggest
kubectl suggest for get (list, ps), and delete(rm)
2016-05-13 10:08:22 -07:00
Clayton Coleman 51b624103f
Change ConvertToVersion to use GroupVersion
Long delayed refactor, avoids a few more allocations.
2016-05-12 10:10:35 -04:00
Janet Kuo 181627e36c kubectl suggest for get (list, ps), and delete(rm) 2016-05-04 17:18:52 -07:00
Mike Metral 999c8e211e allow kubectl subcmds to process multiple resources
- use resource.Visit() to recursively process resources, as well as, aggregate
errors where possible
2016-05-01 20:27:37 -07:00
Dr. Stefan Schimanski 7e0bb885f1 Make kubectl bash completion namespace aware and add noun aliases
- add namespace filtering to bash completion
- add --namespace flag bash completion
- add bash completion noun aliases
- adapt to new cobra package structure
2016-04-03 16:25:56 +02:00
Brendan Burns be6c5b332b Add third party support to kubectl 2016-03-31 10:53:32 -07:00
Mike Metral 7403878ac0 allow kubectl cmd to process dirs recursively
reqs:
    - the kubectl cmd must support the -f | --filename flag
    - the kubectl cmd must support visiting a dir one level deep,
    or using more than one resource
2016-03-28 12:44:21 -07:00