@@ -2,7 +2,6 @@ package openshift
22
33import (
44 "context"
5- "path/filepath"
65 "testing"
76 "time"
87
@@ -46,15 +45,18 @@ const (
4645var _ = BeforeSuite (func () {
4746 logf .SetLogger (zap .New (zap .WriteTo (GinkgoWriter ), zap .UseDevMode (true )))
4847
49- base := filepath .Join (".." , ".." , ".." , ".." , "vendor" , "github.com" , "openshift" , "api" , "config" , "v1" )
48+ // Note: OpenShift CRDs are created programmatically instead of loading from files.
49+ // Breaking change: The github.com/openshift/api package (v0.0.0-20251111193948+)
50+ // no longer ships individual CRD YAML files in vendor (they were removed in favor
51+ // of a consolidated manifest). Previously, tests loaded CRDs directly from vendor
52+ // paths like "0000_00_cluster-version-operator_01_clusteroperator.crd.yaml".
53+ // Now we generate minimal CRDs programmatically to keep tests self-contained and
54+ // ensure they work in envtest/kind environments. CRD schemas generated by AI.
5055 testEnv = & envtest.Environment {
51- ErrorIfCRDPathMissing : true ,
5256 CRDs : []* apiextensionsv1.CustomResourceDefinition {
5357 crds .ClusterServiceVersion (),
54- },
55- CRDDirectoryPaths : []string {
56- filepath .Join (base , "0000_00_cluster-version-operator_01_clusteroperator.crd.yaml" ),
57- filepath .Join (base , "0000_00_cluster-version-operator_01_clusterversion.crd.yaml" ),
58+ newClusterOperatorCRD (),
59+ newClusterVersionCRD (),
5860 },
5961 }
6062
@@ -73,6 +75,9 @@ var _ = BeforeSuite(func() {
7375 })
7476 Expect (err ).ToNot (HaveOccurred ())
7577
78+ // Register OpenShift types with the scheme
79+ Expect (configv1 .AddToScheme (mgr .GetScheme ())).To (Succeed ())
80+
7681 k8sClient = mgr .GetClient ()
7782
7883 syncCh = make (chan error )
@@ -111,3 +116,149 @@ var _ = AfterSuite(func() {
111116 close (syncCh )
112117 testEnv .Stop ()
113118})
119+
120+ // newClusterOperatorCRD creates a minimal ClusterOperator CRD for testing.
121+ // This is required because github.com/openshift/api no longer ships individual
122+ // CRD YAML files in vendor. We create a programmatic CRD with the minimum schema
123+ // needed for the controller tests to pass.
124+ func newClusterOperatorCRD () * apiextensionsv1.CustomResourceDefinition {
125+ return & apiextensionsv1.CustomResourceDefinition {
126+ ObjectMeta : metav1.ObjectMeta {
127+ Name : "clusteroperators.config.openshift.io" ,
128+ },
129+ Spec : apiextensionsv1.CustomResourceDefinitionSpec {
130+ Group : "config.openshift.io" ,
131+ Names : apiextensionsv1.CustomResourceDefinitionNames {
132+ Plural : "clusteroperators" ,
133+ Singular : "clusteroperator" ,
134+ Kind : "ClusterOperator" ,
135+ ListKind : "ClusterOperatorList" ,
136+ ShortNames : []string {"co" },
137+ },
138+ Scope : apiextensionsv1 .ClusterScoped ,
139+ Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
140+ {
141+ Name : "v1" ,
142+ Served : true ,
143+ Storage : true ,
144+ Schema : & apiextensionsv1.CustomResourceValidation {
145+ OpenAPIV3Schema : & apiextensionsv1.JSONSchemaProps {
146+ Type : "object" ,
147+ Description : "ClusterOperator is the Custom Resource object which holds the current state of an operator" ,
148+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {
149+ "spec" : {
150+ Type : "object" ,
151+ Description : "spec holds configuration that could apply to any operator" ,
152+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {},
153+ },
154+ "status" : {
155+ Type : "object" ,
156+ Description : "status holds the information about the state of an operator" ,
157+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {
158+ "conditions" : {
159+ Type : "array" ,
160+ Items : & apiextensionsv1.JSONSchemaPropsOrArray {
161+ Schema : & apiextensionsv1.JSONSchemaProps {
162+ Type : "object" ,
163+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {
164+ "type" : {Type : "string" },
165+ "status" : {Type : "string" },
166+ "lastTransitionTime" : {Type : "string" , Format : "date-time" },
167+ "reason" : {Type : "string" },
168+ "message" : {Type : "string" },
169+ },
170+ Required : []string {"type" , "status" },
171+ },
172+ },
173+ },
174+ "versions" : {
175+ Type : "array" ,
176+ Items : & apiextensionsv1.JSONSchemaPropsOrArray {
177+ Schema : & apiextensionsv1.JSONSchemaProps {
178+ Type : "object" ,
179+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {
180+ "name" : {Type : "string" },
181+ "version" : {Type : "string" },
182+ },
183+ Required : []string {"name" , "version" },
184+ },
185+ },
186+ },
187+ "relatedObjects" : {
188+ Type : "array" ,
189+ Items : & apiextensionsv1.JSONSchemaPropsOrArray {
190+ Schema : & apiextensionsv1.JSONSchemaProps {
191+ Type : "object" ,
192+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {
193+ "group" : {Type : "string" },
194+ "resource" : {Type : "string" },
195+ "namespace" : {Type : "string" },
196+ "name" : {Type : "string" },
197+ },
198+ Required : []string {"group" , "resource" , "name" },
199+ },
200+ },
201+ },
202+ },
203+ },
204+ },
205+ },
206+ },
207+ Subresources : & apiextensionsv1.CustomResourceSubresources {
208+ Status : & apiextensionsv1.CustomResourceSubresourceStatus {},
209+ },
210+ },
211+ },
212+ },
213+ }
214+ }
215+
216+ // newClusterVersionCRD creates a minimal ClusterVersion CRD for testing.
217+ // This is required because github.com/openshift/api no longer ships individual
218+ // CRD YAML files in vendor. We create a programmatic CRD with the minimum schema
219+ // needed for the controller tests to pass.
220+ func newClusterVersionCRD () * apiextensionsv1.CustomResourceDefinition {
221+ return & apiextensionsv1.CustomResourceDefinition {
222+ ObjectMeta : metav1.ObjectMeta {
223+ Name : "clusterversions.config.openshift.io" ,
224+ },
225+ Spec : apiextensionsv1.CustomResourceDefinitionSpec {
226+ Group : "config.openshift.io" ,
227+ Names : apiextensionsv1.CustomResourceDefinitionNames {
228+ Plural : "clusterversions" ,
229+ Singular : "clusterversion" ,
230+ Kind : "ClusterVersion" ,
231+ ListKind : "ClusterVersionList" ,
232+ },
233+ Scope : apiextensionsv1 .ClusterScoped ,
234+ Versions : []apiextensionsv1.CustomResourceDefinitionVersion {
235+ {
236+ Name : "v1" ,
237+ Served : true ,
238+ Storage : true ,
239+ Schema : & apiextensionsv1.CustomResourceValidation {
240+ OpenAPIV3Schema : & apiextensionsv1.JSONSchemaProps {
241+ Type : "object" ,
242+ Description : "ClusterVersion is the configuration for the ClusterVersionOperator" ,
243+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {
244+ "spec" : {
245+ Type : "object" ,
246+ Description : "spec is the desired state" ,
247+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {},
248+ },
249+ "status" : {
250+ Type : "object" ,
251+ Description : "status contains information about the available updates" ,
252+ Properties : map [string ]apiextensionsv1.JSONSchemaProps {},
253+ },
254+ },
255+ },
256+ },
257+ Subresources : & apiextensionsv1.CustomResourceSubresources {
258+ Status : & apiextensionsv1.CustomResourceSubresourceStatus {},
259+ },
260+ },
261+ },
262+ },
263+ }
264+ }
0 commit comments