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
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
- 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
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
* 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
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
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
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
`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