Ask questionsenvtest: no matches for kind "Infrastructure" in version "config.openshift.io/v1"
Dependency versions:
sigs.k8s.io/controller-runtime v0.6.3
github.com/openshift/api v0.0.0-20200326152221-912866ddb162
I'm getting the error above in my test even though I've added the relevant schema like so:
...
configv1 "github.com/openshift/api/config/v1"
...
var _ = BeforeSuite(func(done Done) {
...
err = configv1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())
...
I have some other schemas I've added including the one for our CRD, and those don't give me problems. The controller does start and begins reconciling our CRD. I also checked the version of the OpenShift API that I'm using to make sure it has Infrastructure and it does: https://pkg.go.dev/github.com/openshift/[email protected]/config/v1
Am I missing something else? Full code is here: https://github.com/IBM/starter-kit-operator/blob/operator-sdk-upgrade/controllers/suite_test.go
Answer
questions
mpreu
@avrahams
There is none for Route. All OCP related CRDs are potentially to be found in the API repo, but some of the "older" OCP resources are not published this way. Recently was in contact with some Red Hat people and my information so far is, that there is no really immediate plan to change that.
There is a manual way though. One has to create a 'fake' CRD within the correct OCP API repository path and adapt the make targets.
E.g. for Routes, a CRD file route_crd.yaml with the following content has to be created in the path https://github.com/openshift/api/tree/master/route/v1:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
# name must be in the form: <plural>.<group>
# <group> has to match the correspondig .spec field
name: routes.route.openshift.io
spec:
# group name to use for REST API: /apis/<group>/<version>
group: route.openshift.io
versions:
- name: v1
served: true
storage: true
scope: Namespaced
subresources:
# enable spec/status
status: {}
names:
plural: routes
singular: route
kind: Route
Then the Makefile has to get this line:
$(call add-crd-gen,route,./route/v1,./route/v1,./route/v1)
Updating the CRDs with
make update-codegen-crds
populates the CRD stub with the correct OpenAPI validation content.
Unfortunately it seems to only works this way, as the API repo infrastructure already expects the basic CRD to be there (I am sure one can work around that somehow).
It works for other resources as well, but it is obviously not a very practical solution. So this is just a documentation comment for people experiencing similar problems with OCP related resources.
Just as a warning: In some of my tests I experienced validation errors populating envtest with these CRDs, but I did not investigate it further.
Related questions