Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📖 : add faq section on 3rd party APIs in envtest #1393

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,36 @@ from the API groups that it needs (be they Kubernetes types or your own).
See the [scheme builder
docs](https://godoc.org/sigs.k8s.io/controller-runtime/pkg/scheme) for
more information.

### Q: When using envtest with a third party API, why do I see the error: `no matches for kind "Kind" in version "<group>/<version>"`?

**A**: While testing a third party API with `envtest`, in addition to registering the API type with the test client, you would also
have to register it with the test server. To do so, download the associated CustomResourceDefinition's manifest locally
and add its path to [`Environment.CRDDirectoryPaths`](https://pkg.go.dev/github.com/kubernetes-sigs/controller-runtime/pkg/envtest#Environment).

For example, to use `customapiv1` in `envtest`:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this involves adding the api to scheme (which is explained in the previous question), and just specifying the path in CRDDirectoryPaths, is this example section required ? @coderanger @camilamacedo86

- Register the API type with test client by adding it to the `scheme` used in the tests:

```go
...
var _ = BeforeSuite(func (done Done)) {
...
testScheme := scheme.Scheme
err := customapiv1.AddToScheme(testScheme)
Expect(err).NotTo(HaveOccurred())
}
```

- Specify the CRD path to install it in the test environment:

```go
...
var _ = BeforeSuite(func(done Done) {
...
By("bootstrapping test environment")
testEnv = &envtest.Environment{
CRDDirectoryPaths: []string{<location_of_the_CRD_for_`customapi`>},
}
...
```