Commit Graph

26 Commits

Author SHA1 Message Date
Brian Pursley 0eaacc266e i18n: Fix bug where package-level variables are not translated.
Change i18n.T() to load translations if they have not yet been loaded.

Added new integration tests to test help output translation.

Kubernetes-commit: c0dea5e31af856ed96b8257b5caa952161c8a05b
2022-11-29 23:09:57 -05:00
Maciej Szulik 53106cc99b Move events command to top level
Kubernetes-commit: 50c7ebb5b45818a4244728932ce6113c10c2d41d
2022-11-10 14:32:14 +01:00
Marc Khouzam d2df859d92 Add support for shell completion for plugins
When doing completion for arguments or flags for a plugin, kubectl will
call "kubectl_complete-<plugin>" to obtain the list of completions.
For example, for "krew" plugin, when the user triggers completion using:

$ kubectl krew <tab><tab>

kubectl will look for an executable file called "kubectl_complete-krew".
This file should print the list of valid completions for the plugin to
stdout.  Using cobra.ShellCompDirective as the last line of the output
is supported as is done by Cobra.

We also clear global flags when doing plugin completion because plugins
don't necessarily accept the global kubectl flags.  If some plugins do,
they will need to include such flags in their kubectl_complete-<plugin>
output.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: befc8da7efa5d961d9ade4eadc706292c7ca5a64
2021-09-15 21:44:07 -04:00
Davanum Srinivas d3700ce217 Generate and format files
- Run hack/update-codegen.sh
- Run hack/update-generated-device-plugin.sh
- Run hack/update-generated-protobuf.sh
- Run hack/update-generated-runtime.sh
- Run hack/update-generated-swagger-docs.sh
- Run hack/update-openapi-spec.sh
- Run hack/update-gofmt.sh

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: a9593d634c6a053848413e600dadbf974627515f
2022-07-19 20:54:13 -04:00
Davanum Srinivas ded91f6296 Adjust for os/exec changes in 1.19
https://tip.golang.org/doc/go1.19#os-exec-path

Signed-off-by: Davanum Srinivas <davanum@gmail.com>

Kubernetes-commit: 1f557035e053e2f604b228815241d59123f9915c
2022-07-22 17:42:11 -04:00
xin.li 8207383170 update kubectl doc url
Signed-off-by: xin.li <xin.li@daocloud.io>

Kubernetes-commit: e89a87f708a03c5a8331639739982d426077ad3a
2022-05-05 21:27:52 +08:00
Marc Khouzam cd5b039b42 Refactor completion code into its own package
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: c4f8c57b43843abd13bae677b73c622e1c30b46f
2022-03-24 09:06:05 -04:00
Jonny Langefeld a8accff4dc Fix default config flags
This is a follow up to #105520 which only changed the new default config flags in the `NewKubectlCommand` function if `kubeConfigFlags == nil`. However they are not nil because they were initialized before here:
2fe968deb6/staging/src/k8s.io/kubectl/pkg/cmd/cmd.go (L97)

This fix uses the same defaults for both functions

Signed-off-by: Jonny Langefeld <jonny.langefeld@gmail.com>

Kubernetes-commit: c4fbd35cf4bdc76b86dd74e468b69328f5aa20f9
2021-12-19 19:59:46 -08:00
Maciej Szulik 691bf81946 Allow changing discovery QPS with cli-runtime
Kubernetes-commit: 2fe968deb6cef4feea5bd0eb435e71844e397eed
2021-11-16 22:27:33 +01:00
Maciej Szulik ca7662ebb5 Bump discovery burst for kubectl
Kubernetes-commit: e944d2c365af0d2d2784dd8f71f90ca5bd0cdbc9
2021-11-16 22:26:32 +01:00
Maciej Szulik 19d74f894c Switch from arguments to an input structure for kubectl command
Kubernetes-commit: baab99d04cd4c4314525e19c14ec85a072161cb1
2021-11-04 16:29:08 +01:00
Maciej Szulik d89f23e807 Allow providing wrapper for client config
Kubernetes-commit: c5aea015c30735b0e64f8bbd41acd811782c1fe5
2021-11-04 16:14:27 +01:00
Bryan Boreham 0a152f103a 'kubectl events' command (#99557)
* Basic scaffolding for kubectl events command

* Simple implementation of 'kubectl events'

* Print event fields

Borrowing code from 'kubectl describe'

* Sort events before printing

* Make output more like 'kubectl get events'

Print namespace if fetching from all

* Refactor: extract print functions

To make it easier to add watch function next.

* Implement watch for new events

Run the list function same as before, so those events come out in order,
then watch from the ResourceVersion after the last event.

* Clear up some lint warnings

* Update description and example text

* refactor: introduce a listOptions variable

* Implement --for option

splitResourceTypeName() function borrowed from cli-runtime because we
need similar behaviour to Builder.ResourceNames(), but applying to
Event.InvolvedObject.

* Add kubectl/pkg/cmd/events to vendor/modules.txt

* Add back cmdutil.Factory

Needed in NewCmdAlpha to construct the 'events' command

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Fix lint

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Make package alias go-cromulent

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Use genericclioptions.RESTClientGetter instead of cmdutil.Factory

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Decode object parameter to GroupVersionKind and name

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Merge two files into one

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Include example for --for option

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Fix inconsistent option name in error message

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Remove unnecessary Validate call

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Use fields from event series

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Support chunking of list of events

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Use watchtools utility to receive watch events

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Split struct into flags and options

Flags represents the inputs from the CLI; options are what the running
command needs. This structure parallels the 'wait' command, and should
be easier to write tests for.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Add some parameters to usage string

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Do only one of list or watch

We tried to print the list first then start a watch after the last
event, but sometimes the server will return "watch is too old" on that
ResourceVersion.
Instead, if we need to watch just start it from the beginning.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

* Print message if no events found

Also, if watching, don't print the headings until the first event
arrives.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>

Kubernetes-commit: a988182f595af64bc007ba9162509e089c36fd89
2021-10-29 17:13:38 +00:00
Marc Khouzam e6118325f3 Ignore flags that could precede the Cobra command
See https://github.com/kubernetes/kubectl/issues/1119

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: d41c2685b67317fea1d1a3843d8f5870bc724b3b
2021-09-20 18:20:49 -04:00
Marc Khouzam 10504c18ad Do not try to load plugins for cobra commands
Cobra adds the commands 'help', '__complete' and '__completeNoDesc'
inside rootCmd.Execute(), however, when kubectl decides if it should
lookup plugins, rootCmd.Execute() had not been called yet.  Therefore,
the call to cmd.Find(cmdPathPieces) done by kubectl does not find the
commands added by Cobra.  To fix this we must check for them explicitly.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: e703b3d25377e763b117805b3d88fe7236f3ff76
2021-09-19 14:34:10 -04:00
Sean Sullivan 8a45e525e5 Fixes kubectl command headers which hangs on kubectl run
Kubernetes-commit: 1d1a5499e717b928c6b2782fdcad9fa4052a38a1
2021-09-30 13:53:00 -07:00
Patrick Ohly 466b483531 initialize logging after flag parsing
It wasn't documented that InitLogs already uses the log flush frequency, so
some commands have called it before parsing (for example, kubectl in the
original code for logs.go). The flag never had an effect in such commands.

Fixing this turned into a major refactoring of how commands set up flags and
run their Cobra command:

- component-base/logs: implicitely registering flags during package init is an
  anti-pattern that makes it impossible to use the package in commands which
  want full control over their command line. Logging flags must be added
  explicitly now, something that the new cli.Run does automatically.

- component-base/logs: AddFlags would have crashed in kubectl-convert if it
  had been called because it relied on the global pflag.CommandLine. This
  has been fixed and kubectl-convert now has the same --log-flush-frequency
  flag as other commands.

- component-base/logs/testinit: an exception are tests where flag.CommandLine has
  to be used. This new package can be imported to add flags to that
  once per test program.

- Normalization of the klog command line flags was inconsistent. Some commands
  unintentionally didn't normalize to the recommended format with hyphens. This
  gets fixed for sample programs, but not for production programs because
  it would be a breaking change.

This refactoring has the following user-visible effects:

- The validation error for `go run ./cmd/kube-apiserver --logging-format=json
  --add-dir-header` now references `add-dir-header` instead of `add_dir_header`.

- `staging/src/k8s.io/cloud-provider/sample` uses flags with hyphen instead of
  underscore.

- `--log-flush-frequency` is not listed anymore in the --logging-format flag's
  `non-default formats don't honor these flags` usage text because it will also
  work for non-default formats once it is needed.

- `cmd/kubelet`: the description of `--logging-format` uses hyphens instead of
  underscores for the flags, which now matches what the command is using.

- `staging/src/k8s.io/component-base/logs/example/cmd`: added logging flags.

- `apiextensions-apiserver` no longer prints a useless stack trace for `main`
  when command line parsing raises an error.

Kubernetes-commit: 21d1bcd6b8498370832fa76f680d3de56837bc83
2021-09-16 18:18:35 +02:00
navist2020 2128ec58c8 remove Factory that not used
Kubernetes-commit: 0a83041d4d3698d36ade2a310184248c61eec64f
2021-05-17 16:56:12 +08:00
Sean Sullivan 42a8170920 kubectl command headers as default in beta
Kubernetes-commit: 4add8ed910654087683444ac7f8e441e8d32baa3
2021-06-26 20:53:49 -07:00
Marc Khouzam 5c679b006e Join common functions for completion
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: 9625872d1e4fd0d4d397b3ab732c6969a3a376fe
2021-05-15 21:22:42 -04:00
Marc Khouzam 1946af5761 Move all completion bash code to Go code
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: 879cdc5fa9e518ce76b9e1dc7e795132457966f3
2021-03-05 15:43:31 -05:00
knight42 6c78436886 refactor: implement custom completions for some flags using Go
Only --context, --cluster, --user and --namespace are included.

Signed-off-by: knight42 <anonymousknight96@gmail.com>
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>

Kubernetes-commit: 663b13e814909070e83642c42969174ce03a0e1e
2020-08-06 23:48:33 +08:00
Sean Sullivan 76c2cf7eb6 Kubectl command headers in requests: KEP 859
Kubernetes-commit: 211fc12b67ea2d04a46b24ef245b3513f2cfeb03
2021-02-09 23:09:22 -08:00
Philipp Stehle 2aa5185d01 bash-completion for comma separated list on get
`kubectl get` supports specifying a comma separated list of resource types. E.g.:

```bash
kubectl get pods,secrets
```

Will list all pods and secrets in the current namespace.

This commit adds support to the kubectl bash completion for this feature. Which means if you type `kubectl get pods,sec<tab>` it will be auto-completed to `kubectl get pods,secrets` (assuming the cluster does not have a CRD starting with `sec`).

Kubernetes-commit: 51671ecc2e258d50c7b1315b7b68c4e239f7e829
2021-01-22 10:04:56 +01:00
xiongzhongliang b0de341b90 Remove kubectl alpha debug command in 1.21
Kubernetes-commit: e650a8a38c30ff3707292c060613acdb0714b2ec
2021-01-16 20:17:22 +08:00
Maciej Szulik d64f53f6eb Move the remaining kubectl bits to k8s.io/kubectl
Kubernetes-commit: 9b8247e5ddb15f3fb9ffe59871172d9a3268af55
2020-11-03 22:11:39 +01:00