kubectl/pkg/cmd
Arda Güçlü 507fbad069 Add shortname ambiguity warning in shortcut expander (#117668)
* 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
2023-10-11 19:58:38 +00:00
..
annotate Gracefully handle empty config error when local flag is used 2023-06-15 10:13:52 +03:00
apiresources Fix typo in kubectl api-resources help text for --categories flag 2023-04-25 20:26:10 -04:00
apply kubectl prune v2: switch to contains-group-kinds annotation 2023-06-28 11:27:00 -04:00
attach Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
auth Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
autoscale Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
certificates Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
clusterinfo Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
completion Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
config Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
cp Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
create kubectl: ensure '--duration' must be positive for 'kubectl create token' command 2023-10-07 11:19:33 +08:00
debug New repo who dis? distribution/reference 2023-08-31 10:48:53 -04:00
delete kubectl delete: Introduce new interactive flag for interactive deletion (#114530) 2023-07-11 16:05:11 +03:00
describe Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
diff kubectl: Allow parallelizing diffing 2023-06-05 13:18:49 +02:00
drain Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
edit Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
events fixes the issue in the documentation of kubectl events 2023-07-13 13:10:33 -04:00
exec Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
explain Remove KUBECTL_EXPLAIN_OPENAPIV3 environment variable 2023-07-13 13:37:03 +03:00
expose cleanup: Update deprecated FromInt to FromInt32 (#119858) 2023-08-16 21:07:06 +00:00
get Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
help Move pkg/kubectl/cmd/{command} to staging 2019-08-01 11:01:40 -07:00
kustomize Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
label Gracefully handle empty config error when local flag is used 2023-06-15 10:13:52 +03:00
logs Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
options replace deprecated setoutput 2022-04-05 14:04:22 +08:00
patch Gracefully handle empty config error when local flag is used 2023-06-15 10:13:52 +03:00
plugin feat: make user-defined plugins discoverable with e.g. kubectl help (#116752) 2023-09-06 18:12:52 +02:00
portforward Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
proxy Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
replace Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
rollout doc: Add example for restarting all deployments in a namespace 2023-09-01 19:25:54 +08:00
run New repo who dis? distribution/reference 2023-08-31 10:48:53 -04:00
scale Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
set Gracefully handle empty config error when local flag is used 2023-06-15 10:13:52 +03:00
taint Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
testing Add shortname ambiguity warning in shortcut expander (#117668) 2023-10-11 19:58:38 +00:00
top Update CLI help text for grammar and consistency 2023-06-12 15:55:59 -04:00
util Remove KUBECTL_EXPLAIN_OPENAPIV3 environment variable 2023-07-13 13:37:03 +03:00
version Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
wait Improve conditionFuncFor expression parsing for wait --for jsonpath 2023-06-20 03:34:50 +02:00
alpha.go Migrate genericclioptions.IOStreams usage to genericiooptions 2023-04-05 14:07:46 +03:00
cmd.go Add shortname ambiguity warning in shortcut expander (#117668) 2023-10-11 19:58:38 +00:00
cmd_test.go rename err to lookupErr 2023-05-15 16:41:54 +02:00
profiling.go Add Close() for profile 2021-12-15 21:03:34 +08:00
skiplookerr_go118.go Adjust for os/exec changes in 1.19 2022-07-22 17:42:11 -04:00
skiplookerr_go119.go Adjust for os/exec changes in 1.19 2022-07-22 17:42:11 -04:00