test(mcp): use envtest built-in features to apply CRDs #516
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Trying to speed up the test cases that require additional
kubernetes APIs.
Each time a test suite or test case requires an additional
API (like OpenShift Routes or Kiali CRDs), provided by
k8s.io/apiextensions, a fixed 2 seconds delay is introduced.
There's no way to reduce that delay by using envtest features
or APIServer CLI flags.
The delays are introduced by kube-aggregator, apiextensions, and others:
https://github.com/kubernetes/kube-aggregator/blob/a00232cf7e758c2771b3542033bec19e69e6451a/pkg/controllers/openapiv3/controller.go#L34
https://github.com/kubernetes/apiextensions-apiserver/blob/8db5ab628dd026827c1c9677944432db70c065c3/pkg/apiserver/customresource_handler.go#L381-L394
To mitigate this, we're going to declare all CRDs used in the test in
the common_test.go TestMain function.
This will make sure we only have a single delay at the beginning of
the entire test suite instead of per test suite or test case.
The CRDs are NOT served by default.
For each test suite we'll be able to enable them or disable them
by using the EnvTestEnableCRD and EnvTestDisableCRD functions.
These will also ensure that the API server lists the new APIs or not.