kubernetes/test/cmd
Arda Güçlü a504aed54d
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
2023-10-11 17:04:11 +02:00
..
apply.sh Ignore api-resources not found error until it's ready 2022-12-21 10:34:53 +03:00
apps.sh Update shellcheck version (0.7.2 -> 0.8.0) and fix findings 2022-11-08 11:53:57 +01:00
auth_whoami.sh Fix cmd, integration, and conformance tests 2023-05-03 01:29:37 +02:00
authentication.sh Check whether static cert is already configured in UpdateTransportConfig 2022-03-07 13:54:32 -08:00
authorization.sh --as-uid flag in kubectl and kubeconfigs. 2021-11-05 13:23:49 -07:00
batch.sh Update shellcheck version (0.7.2 -> 0.8.0) and fix findings 2022-11-08 11:53:57 +01:00
certificate.sh Add --chunk-size support to kubectl describe 2021-04-21 11:44:15 -07:00
convert.sh Add kubectl-convert tests 2021-02-22 17:01:34 +01:00
core.sh kubectl scale: Add dry-run prefix to indicate result is not applied 2022-12-02 16:27:18 +03:00
crd.sh Update shellcheck version (0.7.2 -> 0.8.0) and fix findings 2022-11-08 11:53:57 +01:00
create.sh Merge pull request #109850 from ardaguclu/validate-nooptdefval 2022-06-13 08:04:11 -07:00
debug.sh Add startup probe in integration test 2023-06-09 08:49:31 +03:00
delete.sh kubectl delete: Introduce new interactive flag for interactive deletion (#114530) 2023-07-11 06:05:11 -07:00
diff.sh Re-enable label selector 2023-02-20 09:10:51 +03:00
discovery.sh Add shortname ambiguity warning in shortcut expander (#117668) 2023-10-11 17:04:11 +02:00
events.sh fix(test): delete cronjobs.v1.example.com pi for clean up 2023-09-01 23:13:26 +08:00
exec.sh kubectl exec: return descriptive error message when multi resource passed 2022-12-02 14:05:11 +03:00
generic-resources.sh tests: adding integration test for rollout status 2022-04-21 11:21:13 -04:00
get.sh Ignore api-resources not found error until it's ready 2022-12-21 10:34:53 +03:00
help.sh Optimize usage message of commands which have subcommands. 2023-05-26 10:07:43 +08:00
kubeconfig.sh --as-uid flag in kubectl and kubeconfigs. 2021-11-05 13:23:49 -07:00
legacy-script.sh Add shortname ambiguity warning in shortcut expander (#117668) 2023-10-11 17:04:11 +02:00
node-management.sh Update shellcheck version (0.7.2 -> 0.8.0) and fix findings 2022-11-08 11:53:57 +01:00
OWNERS Update sig-cli OWNERS 2022-02-14 10:55:35 -07:00
plugins.sh Isolate kubectl test-cmd plugin tests 2019-12-19 01:35:36 -05:00
proxy.sh use a non-deprecated API to check kube-proxy 2021-03-25 12:41:50 -04:00
rbac.sh add a warning printer in cli-runtime to coordinate warning style 2022-05-23 19:10:15 +08:00
README.md Change legacy-script.sh to produce junit output in location set by the 2022-02-02 21:51:15 -05:00
request-timeout.sh go1.14: fix test/cmd timeout message check 2020-06-23 19:04:43 -04:00
results.sh kubectl: add integration test for result reporting 2022-01-11 09:04:56 +01:00
run.sh Use --dry-run=client,server in kubectl. 2020-02-12 20:46:54 -05:00
save-config.sh rename v2beta2 to v2 2021-11-09 10:34:54 +08:00
storage.sh add a warning printer in cli-runtime to coordinate warning style 2022-05-23 19:10:15 +08:00
template-output.sh fix typos in pkg/validation and test/cmd 2022-09-20 19:12:17 +05:30
version.sh Remove long/golang version information making short the default 2023-07-07 18:46:34 +02:00
wait.sh Improve conditionFuncFor expression parsing for wait --for jsonpath 2023-07-23 15:54:28 +02:00

Kubernetes Command-Line Integration Test Suite

This document describes how you can use the Kubernetes command-line integration test-suite.

Running Tests

All Tests

To run this entire suite, execute make test-cmd from the top level. This will import each file containing tests functions

Specific Tests

To run a subset of tests (e.g. run_deployment_tests and run_impersonation_tests), execute make test-cmd WHAT="deployment impersonation". Running specific tests will not try and validate any required resources are available on the server.

Adding Tests

Test functions need to have the format run_*_tests so they can be executed individually. Once a test has been added, insert a section in legacy-script.sh like

######################
# Replica Sets       #
######################

if kube::test::if_supports_resource "${replicasets}" ; then
    record_command run_rs_tests
fi

Be sure to validate any supported resources required for the test by using the kube::test::if_supports_resource function.

New File

If the test resides in a new file, source the file in the top of the legacy-script.sh file by adding a new line in

source "${KUBE_ROOT}/test/cmd/apply.sh"
source "${KUBE_ROOT}/test/cmd/apps.sh"
source "${KUBE_ROOT}/test/cmd/authorization.sh"
source "${KUBE_ROOT}/test/cmd/batch.sh"
...

Please keep the order of the source list alphabetical.