https://kep.k8s.io/3638 has been promoted to stable back in 1.32 so now
is the right time to drop this feature gate entirely.
Signed-off-by: Maciej Szulik <soltysh@gmail.com>
Kubernetes-commit: d1b5f268b48eda4bb8acdeef52407c27add9e076
kubectl command construction is slowly getting more functionality which
sometimes requires to log certain actions. Currently we parse the
verbosity only when actually running the command, so all of construction
code is not able to use -v=5. This commit adds the manual parsing and
loglevel setting berore we even start creating the kubectl command.
Signed-off-by: Maciej Szulik <soltysh@gmail.com>
Kubernetes-commit: 69682b75e508462e01f865a156f2171233b653d1
* Promote plugin resolution to beta
* Not use plugin for kubectl create -f command execution
`kubectl create -f` is legitimate command execution and we shouldn't
search plugins if user invokes this.
* Add integration test for plugin resolution for create command
* Reintroduce feature flag to ability to disable it explicitly
Kubernetes-commit: 074a8b00840e85cc95fd83b1825b14ab21ad09c4
* Add warning handler callback function in shortcut expander
Currently, errors in client-go are propagated back to the callers via
function returns. However, there is no elegant way for just warning users.
For example, when user wants to get a resource with it's short name format
and if there are multiple resources belonging to this short name, we need to
warn user about this ambugity which one is picked and which ones are discarded.
Not only to overcome this particular case mentioned above, but also propose a
way for the possible warnings in the future, this commit adds a warningHandler
callback function in shortcutExpander.
* Add warningPrinter functionality in ConfigFlags
ConfigFlags has neither warning user in a standardized
format functionality nor passing warning callback functions to other upper level
libraries such as client-go.
This commit adds an ability that user can set warningPrinters
according to their IOStreams and this warningPrinters will be used
to raise possible warnings happening not only in cli-runtime but
also in client-go.
* Pass warning callback function in ConfigFlags to shortcutExpander
This commit passes warning callback function to print possible
warnings happened in shortcut expander to warn user in a
standardized format.
* Add integration test for CRDs having ambiguous short names
This commit adds integration test to assure that warning message
related to this ambiguity is printed when resources are being retrieved via their short name
representations in cases where multiple resources have same
short names.
This integration test also ensures that the logic behind which resource
will be selected hasn't been changed which may cause disperancies in
clusters.
* Remove defaultConfigFlag global variable
* Move default config flags initialization into function
* Skip warning for versions of same group/resource
* Run update-vendor
* Warn only once when there are multiple versions registered for ambiguous resource
* Apply gocritic review
* Add multi-resource multi-version ambiguity unit test
Kubernetes-commit: a504aed54d028dbc8ea2508142c94d309f5f1ec6
Plugin subcommand resolution is relatively less used than the
builtin subcommands. That's why, instead always initializing a
hash map on memory, it would be better to use a getter function only
serves as needed.
In addition to that this function will be exported that external
libraries can use it.
Kubernetes-commit: 4634073d0b979d2827106a0a1010456ac420baa8
Removes the need to pass cmd as an argument to Run(). This change required reading the --sort-by flag in Complete() in a way similar to other flags.
This change allows the cobra.Command not to need to be passed throughout the completion code, which I updated as part of this commit.
It also is a step in the direction of the TODO comment requesting the removal of arguments passed to Run() and watch().
Kubernetes-commit: aa7a828f20b479a8a943d897224e8e76c3bb6cff
* Enable plugin resolution as subcommand for selected builtin commands
This PR adds external plugin resolution as subcommand for selected builtin
commands if subcommand does not exist as builtin.
In it's alpha stage, this will only be enabled for create command and
this feature is hidden behind `KUBECTL_ENABLE_CMD_SHADOW` environment variable.
* Rename parameter to exactMatch to better reflect
Kubernetes-commit: a901bb630b5a353898c1b35df582a7faeef160a0
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