From d86ab09377f657acf3fd73e7ee4b6d51c10d3508 Mon Sep 17 00:00:00 2001 From: Jan Fajerski Date: Thu, 7 Nov 2024 16:38:21 +0100 Subject: [PATCH] fix: register scheme in operator (#619) Instead of trying to shoehorn it into the controller. Signed-off-by: Jan Fajerski --- pkg/controllers/operator/controller.go | 13 ------------- pkg/operator/scheme.go | 4 ++++ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/pkg/controllers/operator/controller.go b/pkg/controllers/operator/controller.go index 9c8f80c7..b8a4e0aa 100644 --- a/pkg/controllers/operator/controller.go +++ b/pkg/controllers/operator/controller.go @@ -25,13 +25,11 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" "sigs.k8s.io/controller-runtime/pkg/predicate" - "sigs.k8s.io/controller-runtime/pkg/scheme" ) type resourceManager struct { @@ -49,17 +47,6 @@ type resourceManager struct { // RegisterWithManager registers the controller with Manager func RegisterWithManager(mgr ctrl.Manager, namespace string) error { - // GroupVersion is group version used to register these objects - GroupVersion := schema.GroupVersion{Group: "", Version: "v1"} - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder := &scheme.Builder{GroupVersion: GroupVersion} - SchemeBuilder.Register(&corev1.Service{}, &corev1.ServiceList{}) - // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "monitoring.coreos.com", Version: "v1"} - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} - SchemeBuilder.Register(&monv1.ServiceMonitor{}, &monv1.ServiceMonitorList{}) - rm := &resourceManager{ k8sClient: mgr.GetClient(), scheme: mgr.GetScheme(), diff --git a/pkg/operator/scheme.go b/pkg/operator/scheme.go index b042ab4e..e39234d9 100644 --- a/pkg/operator/scheme.go +++ b/pkg/operator/scheme.go @@ -4,8 +4,10 @@ import ( osv1 "github.com/openshift/api/console/v1" osv1alpha1 "github.com/openshift/api/console/v1alpha1" operatorv1 "github.com/openshift/api/operator/v1" + monv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" monitoringv1 "github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring/v1" multiclusterhubv1 "github.com/stolostron/multiclusterhub-operator/api/v1" + corev1 "k8s.io/api/core/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" @@ -29,6 +31,8 @@ func NewScheme(cfg *OperatorConfiguration) *runtime.Scheme { utilruntime.Must(osv1alpha1.Install(scheme)) utilruntime.Must(operatorv1.Install(scheme)) utilruntime.Must(multiclusterhubv1.AddToScheme(scheme)) + utilruntime.Must(corev1.AddToScheme(scheme)) + utilruntime.Must(monv1.AddToScheme(scheme)) } return scheme