Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,16 @@ e2e-local-deploy: $(KIND) $(HELM) #HELP Deploy OLM for e2e testing (without cert
#SECTION Code Generation

.PHONY: gen-all #HELP Update OLM API, generate code and mocks
gen-all: manifests codegen mockgen
gen-all: manifests openshift-test-crds codegen mockgen

.PHONY: manifests
manifests: vendor #HELP Copy OLM API CRD manifests to deploy/chart/crds
./scripts/copy_crds.sh

.PHONY: openshift-test-crds
openshift-test-crds: #HELP Generate OpenShift CRDs for openshift controller unit tests (ClusterOperator, ClusterVersion)
./scripts/generate_openshift_crds.sh

.PHONY: codegen
codegen: #HELP Generate clients, deepcopy, listers, and informers
./scripts/update_codegen.sh
Expand Down
21 changes: 10 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/onsi/ginkgo/v2 v2.27.2
github.com/onsi/gomega v1.38.2
github.com/openshift/api v0.0.0-20221021112143-4226c2167e40
github.com/openshift/client-go v0.0.0-20220525160904-9e1acff93e4a
github.com/openshift/api v0.0.0-20251111193948-50e2ece149d7
github.com/openshift/client-go v0.0.0-20251015124057-db0dee36e235
github.com/operator-framework/api v0.36.0
github.com/operator-framework/operator-registry v1.61.0
github.com/otiai10/copy v1.14.1
Expand All @@ -33,7 +33,7 @@ require (
github.com/spf13/pflag v1.0.10
github.com/stretchr/testify v1.11.1
go.podman.io/image/v5 v5.38.0
golang.org/x/net v0.46.0
golang.org/x/net v0.47.0
golang.org/x/sync v0.18.0
golang.org/x/time v0.14.0
google.golang.org/grpc v1.76.0
Expand All @@ -47,8 +47,8 @@ require (
k8s.io/component-base v0.34.1
k8s.io/klog v1.0.0
k8s.io/kube-aggregator v0.34.1
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
sigs.k8s.io/controller-runtime v0.22.4
sigs.k8s.io/controller-tools v0.19.0
)
Expand Down Expand Up @@ -90,7 +90,6 @@ require (
github.com/fatih/color v1.18.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.21.1 // indirect
Expand All @@ -105,7 +104,7 @@ require (
github.com/google/btree v1.1.3 // indirect
github.com/google/cel-go v0.26.1 // indirect
github.com/google/gnostic-models v0.7.0 // indirect
github.com/google/pprof v0.0.0-20251007162407-5df77e3f7d1d // indirect
github.com/google/pprof v0.0.0-20250820193118-f64d9cf942d6 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
Expand Down Expand Up @@ -160,18 +159,18 @@ require (
go.uber.org/zap v1.27.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/crypto v0.43.0 // indirect
golang.org/x/crypto v0.44.0 // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/mod v0.29.0 // indirect
golang.org/x/oauth2 v0.32.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/text v0.30.0 // indirect
golang.org/x/term v0.37.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/tools v0.38.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/genproto v0.0.0-20250603155806-513f23925822 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20250804133106-a7a43d27e69b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251110190251-83f479183930 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250804133106-a7a43d27e69b // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
Expand Down
524 changes: 22 additions & 502 deletions go.sum

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions pkg/controller/operators/openshift/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ const (
var _ = BeforeSuite(func() {
logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true)))

base := filepath.Join("..", "..", "..", "..", "vendor", "github.com", "openshift", "api", "config", "v1")
// Note: OpenShift CRDs are loaded from testdata instead of vendor.
// Breaking change: The github.com/openshift/api package (v0.0.0-20251111193948+)
// no longer ships individual CRD YAML files in vendor (they were removed in favor
// of a consolidated manifest). We generate minimal CRDs via scripts/generate_openshift_crds.sh
// and load them from testdata to keep tests self-contained and work in envtest/kind environments.
testEnv = &envtest.Environment{
ErrorIfCRDPathMissing: true,
CRDs: []*apiextensionsv1.CustomResourceDefinition{
crds.ClusterServiceVersion(),
},
CRDDirectoryPaths: []string{
filepath.Join(base, "0000_00_cluster-version-operator_01_clusteroperator.crd.yaml"),
filepath.Join(base, "0000_00_cluster-version-operator_01_clusterversion.crd.yaml"),
filepath.Join("testdata", "crds"),
},
}

Expand All @@ -73,6 +75,9 @@ var _ = BeforeSuite(func() {
})
Expect(err).ToNot(HaveOccurred())

// Register OpenShift types with the scheme
Expect(configv1.AddToScheme(mgr.GetScheme())).To(Succeed())

k8sClient = mgr.GetClient()

syncCh = make(chan error)
Expand Down
42 changes: 42 additions & 0 deletions pkg/controller/operators/openshift/testdata/crds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# OpenShift Test CRDs

## Purpose

These CRD YAML files are used **only for unit testing** the OpenShift controller (`pkg/controller/operators/openshift/`).

## Why These Files Exist

The OpenShift controller reports OLM status by managing `ClusterOperator` and `ClusterVersion` resources on OpenShift clusters. To test this controller in envtest environments (like CI or local development), we need the CRD definitions.

**Problem**: The `github.com/openshift/api` package (v0.0.0-20251111193948+) no longer ships individual CRD YAML files in vendor. They were removed in favor of a consolidated metadata-only manifest (`zz_generated.featuregated-crd-manifests.yaml`).

**Solution**: Generate minimal CRDs with the schema our tests need. These CRDs are NOT used in production - OpenShift clusters have the actual CRDs installed by the platform.

## How They're Generated

Run: `make openshift-test-crds` or `make gen-all`

This executes `scripts/generate_openshift_crds.sh` which creates:
- `clusteroperators.config.openshift.io.yaml` - Minimal ClusterOperator CRD
- `clusterversions.config.openshift.io.yaml` - Minimal ClusterVersion CRD

## How They're Used

In `suite_test.go`:

```go
testEnv = &envtest.Environment{
CRDs: []*apiextensionsv1.CustomResourceDefinition{
crds.ClusterServiceVersion(),
},
CRDDirectoryPaths: []string{
filepath.Join("testdata", "crds"), // <- Loads these files
},
}
```

## DO NOT Edit Manually

These files are generated. Changes should be made in `scripts/generate_openshift_crds.sh`.

Run `make verify-manifests` to check if these files are up-to-date.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: clusteroperators.config.openshift.io
spec:
group: config.openshift.io
names:
kind: ClusterOperator
listKind: ClusterOperatorList
plural: clusteroperators
shortNames:
- co
singular: clusteroperator
scope: Cluster
versions:
- name: v1
schema:
openAPIV3Schema:
description: ClusterOperator is the Custom Resource object which holds the current state of an operator
properties:
spec:
description: spec holds configuration that could apply to any operator
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: status holds the information about the state of an operator
properties:
conditions:
items:
properties:
lastTransitionTime:
format: date-time
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
type: string
required:
- status
- type
type: object
type: array
relatedObjects:
items:
properties:
group:
type: string
name:
type: string
namespace:
type: string
resource:
type: string
required:
- group
- name
- resource
type: object
type: array
versions:
items:
properties:
name:
type: string
version:
type: string
required:
- name
- version
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: clusterversions.config.openshift.io
spec:
group: config.openshift.io
names:
kind: ClusterVersion
listKind: ClusterVersionList
plural: clusterversions
singular: clusterversion
scope: Cluster
versions:
- name: v1
schema:
openAPIV3Schema:
description: ClusterVersion is the configuration for the ClusterVersionOperator
properties:
spec:
description: spec is the desired state
type: object
x-kubernetes-preserve-unknown-fields: true
status:
description: status contains information about the available updates
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 0 additions & 3 deletions pkg/package-server/client/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading