func readCRDsAtDirectories(t *testing.T, dirs ...string) []apiextensionsv1.CustomResourceDefinition {
	serializer := jsonserializer.NewSerializerWithOptions(jsonserializer.DefaultMetaFactory, internalScheme, internalScheme, jsonserializer.SerializerOptions{
		Yaml: true,
	})
	converter := runtime.UnsafeObjectConvertor(internalScheme)
	codec := versioning.NewCodec(serializer, serializer, converter,
		internalScheme, internalScheme, internalScheme,
		runtime.InternalGroupVersioner, runtime.InternalGroupVersioner,
		internalScheme.Name(),
	)
	var crds []apiextensionsv1.CustomResourceDefinition
	for _, dir := range dirs {
		if err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			if filepath.Ext(path) != ".yaml" {
				return nil
			}
			crd, err := readCRDsAtFilePath(codec, converter, path)
			if err != nil {
				return err
			}
			crds = append(crds, crd...)
			return nil
		}); err != nil {
			t.Fatal(err)
		}
	}
	return crds
}
readCRDsAtDirectories will read all CRDs yaml manifests files at the given
directories, parses and converts them into CustomResourceDefinition objects.
package env
import (
	"os"
	"path/filepath"
	"strings"
	"testing"
	"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
	apiextensionsinstall "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/install"
	apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
	extapi "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/runtime"
	jsonserializer "k8s.io/apimachinery/pkg/runtime/serializer/json"
	"k8s.io/apimachinery/pkg/runtime/serializer/versioning"
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
	"sigs.k8s.io/controller-runtime/pkg/client"
)
var (
	internalScheme = runtime.NewScheme()
)
func init() {
	utilruntime.Must(metav1.AddMetaToScheme(internalScheme))
	utilruntime.Must(extapi.AddToScheme(internalScheme))
	apiextensionsinstall.Install(internalScheme)
}