Skip to content

Commit 874936f

Browse files
fix tests to work with latest ocp/api versions
Generated-by: Cursor
1 parent 0d7562a commit 874936f

File tree

1 file changed

+155
-7
lines changed

1 file changed

+155
-7
lines changed

pkg/controller/operators/openshift/suite_test.go

Lines changed: 155 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package openshift
22

33
import (
44
"context"
5-
"path/filepath"
65
"testing"
76
"time"
87

@@ -46,15 +45,15 @@ const (
4645
var _ = 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+
// The github.com/openshift/api package no longer ships individual CRD YAML files
50+
// (they were removed in favor of a consolidated manifest). For envtest, we need
51+
// to provide CRD definitions, so we create minimal versions programmatically.
5052
testEnv = &envtest.Environment{
51-
ErrorIfCRDPathMissing: true,
5253
CRDs: []*apiextensionsv1.CustomResourceDefinition{
5354
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"),
55+
newClusterOperatorCRD(),
56+
newClusterVersionCRD(),
5857
},
5958
}
6059

@@ -73,6 +72,9 @@ var _ = BeforeSuite(func() {
7372
})
7473
Expect(err).ToNot(HaveOccurred())
7574

75+
// Register OpenShift types with the scheme
76+
Expect(configv1.AddToScheme(mgr.GetScheme())).To(Succeed())
77+
7678
k8sClient = mgr.GetClient()
7779

7880
syncCh = make(chan error)
@@ -111,3 +113,149 @@ var _ = AfterSuite(func() {
111113
close(syncCh)
112114
testEnv.Stop()
113115
})
116+
117+
// newClusterOperatorCRD creates a minimal ClusterOperator CRD for testing.
118+
// This is required because github.com/openshift/api no longer ships individual
119+
// CRD YAML files in vendor. We create a programmatic CRD with the minimum schema
120+
// needed for the controller tests to pass.
121+
func newClusterOperatorCRD() *apiextensionsv1.CustomResourceDefinition {
122+
return &apiextensionsv1.CustomResourceDefinition{
123+
ObjectMeta: metav1.ObjectMeta{
124+
Name: "clusteroperators.config.openshift.io",
125+
},
126+
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
127+
Group: "config.openshift.io",
128+
Names: apiextensionsv1.CustomResourceDefinitionNames{
129+
Plural: "clusteroperators",
130+
Singular: "clusteroperator",
131+
Kind: "ClusterOperator",
132+
ListKind: "ClusterOperatorList",
133+
ShortNames: []string{"co"},
134+
},
135+
Scope: apiextensionsv1.ClusterScoped,
136+
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
137+
{
138+
Name: "v1",
139+
Served: true,
140+
Storage: true,
141+
Schema: &apiextensionsv1.CustomResourceValidation{
142+
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
143+
Type: "object",
144+
Description: "ClusterOperator is the Custom Resource object which holds the current state of an operator",
145+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
146+
"spec": {
147+
Type: "object",
148+
Description: "spec holds configuration that could apply to any operator",
149+
Properties: map[string]apiextensionsv1.JSONSchemaProps{},
150+
},
151+
"status": {
152+
Type: "object",
153+
Description: "status holds the information about the state of an operator",
154+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
155+
"conditions": {
156+
Type: "array",
157+
Items: &apiextensionsv1.JSONSchemaPropsOrArray{
158+
Schema: &apiextensionsv1.JSONSchemaProps{
159+
Type: "object",
160+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
161+
"type": {Type: "string"},
162+
"status": {Type: "string"},
163+
"lastTransitionTime": {Type: "string", Format: "date-time"},
164+
"reason": {Type: "string"},
165+
"message": {Type: "string"},
166+
},
167+
Required: []string{"type", "status"},
168+
},
169+
},
170+
},
171+
"versions": {
172+
Type: "array",
173+
Items: &apiextensionsv1.JSONSchemaPropsOrArray{
174+
Schema: &apiextensionsv1.JSONSchemaProps{
175+
Type: "object",
176+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
177+
"name": {Type: "string"},
178+
"version": {Type: "string"},
179+
},
180+
Required: []string{"name", "version"},
181+
},
182+
},
183+
},
184+
"relatedObjects": {
185+
Type: "array",
186+
Items: &apiextensionsv1.JSONSchemaPropsOrArray{
187+
Schema: &apiextensionsv1.JSONSchemaProps{
188+
Type: "object",
189+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
190+
"group": {Type: "string"},
191+
"resource": {Type: "string"},
192+
"namespace": {Type: "string"},
193+
"name": {Type: "string"},
194+
},
195+
Required: []string{"group", "resource", "name"},
196+
},
197+
},
198+
},
199+
},
200+
},
201+
},
202+
},
203+
},
204+
Subresources: &apiextensionsv1.CustomResourceSubresources{
205+
Status: &apiextensionsv1.CustomResourceSubresourceStatus{},
206+
},
207+
},
208+
},
209+
},
210+
}
211+
}
212+
213+
// newClusterVersionCRD creates a minimal ClusterVersion CRD for testing.
214+
// This is required because github.com/openshift/api no longer ships individual
215+
// CRD YAML files in vendor. We create a programmatic CRD with the minimum schema
216+
// needed for the controller tests to pass.
217+
func newClusterVersionCRD() *apiextensionsv1.CustomResourceDefinition {
218+
return &apiextensionsv1.CustomResourceDefinition{
219+
ObjectMeta: metav1.ObjectMeta{
220+
Name: "clusterversions.config.openshift.io",
221+
},
222+
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
223+
Group: "config.openshift.io",
224+
Names: apiextensionsv1.CustomResourceDefinitionNames{
225+
Plural: "clusterversions",
226+
Singular: "clusterversion",
227+
Kind: "ClusterVersion",
228+
ListKind: "ClusterVersionList",
229+
},
230+
Scope: apiextensionsv1.ClusterScoped,
231+
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
232+
{
233+
Name: "v1",
234+
Served: true,
235+
Storage: true,
236+
Schema: &apiextensionsv1.CustomResourceValidation{
237+
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
238+
Type: "object",
239+
Description: "ClusterVersion is the configuration for the ClusterVersionOperator",
240+
Properties: map[string]apiextensionsv1.JSONSchemaProps{
241+
"spec": {
242+
Type: "object",
243+
Description: "spec is the desired state",
244+
Properties: map[string]apiextensionsv1.JSONSchemaProps{},
245+
},
246+
"status": {
247+
Type: "object",
248+
Description: "status contains information about the available updates",
249+
Properties: map[string]apiextensionsv1.JSONSchemaProps{},
250+
},
251+
},
252+
},
253+
},
254+
Subresources: &apiextensionsv1.CustomResourceSubresources{
255+
Status: &apiextensionsv1.CustomResourceSubresourceStatus{},
256+
},
257+
},
258+
},
259+
},
260+
}
261+
}

0 commit comments

Comments
 (0)