From 5ddf9d4b7707d4f3638c5ed863f3b5a75b32c781 Mon Sep 17 00:00:00 2001 From: Rewant Soni Date: Tue, 3 Dec 2024 09:25:58 +0530 Subject: [PATCH] controllers: deploy omap sidecar only when required move from always deploying the omap side car to deploy it only when required Signed-off-by: Rewant Soni --- api/v1alpha1/storageclient_types.go | 2 + ...s-client-operator-config_v1_configmap.yaml | 2 - ...client-operator.clusterserviceversion.yaml | 2 +- .../ocs.openshift.io_storageclients.yaml | 2 + .../ocs.openshift.io_storageclients.yaml | 2 + config/manager/kustomization.yaml | 4 +- go.sum | 2 - .../operatorconfigmap_controller.go | 47 +++++++++++++++++-- .../controller/storageclient_controller.go | 1 + .../api/v1alpha1/storageclient_types.go | 2 + 10 files changed, 53 insertions(+), 13 deletions(-) diff --git a/api/v1alpha1/storageclient_types.go b/api/v1alpha1/storageclient_types.go index 897b2a13..b7c447a8 100644 --- a/api/v1alpha1/storageclient_types.go +++ b/api/v1alpha1/storageclient_types.go @@ -52,6 +52,8 @@ type StorageClientStatus struct { InMaintenanceMode bool `json:"inMaintenanceMode,omitempty"` + MirrorEnabled bool `json:"generateOMapInfo,omitempty"` + // ConsumerID will hold the identity of this cluster inside the attached provider cluster ConsumerID string `json:"id,omitempty"` } diff --git a/bundle/manifests/ocs-client-operator-config_v1_configmap.yaml b/bundle/manifests/ocs-client-operator-config_v1_configmap.yaml index b0b1a4e2..360b979a 100644 --- a/bundle/manifests/ocs-client-operator-config_v1_configmap.yaml +++ b/bundle/manifests/ocs-client-operator-config_v1_configmap.yaml @@ -1,6 +1,4 @@ apiVersion: v1 -data: - generateRbdOMapInfo: "true" kind: ConfigMap metadata: name: ocs-client-operator-config diff --git a/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml b/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml index c58b1255..bb4c5eaf 100644 --- a/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml +++ b/bundle/manifests/ocs-client-operator.clusterserviceversion.yaml @@ -7,7 +7,7 @@ metadata: categories: Storage console.openshift.io/plugins: '["odf-client-console"]' containerImage: quay.io/ocs-dev/ocs-client-operator:latest - createdAt: "2024-11-27T03:54:42Z" + createdAt: "2024-12-03T03:52:54Z" description: OpenShift Data Foundation client operator enables consumption of storage services from a remote centralized OpenShift Data Foundation provider cluster. diff --git a/bundle/manifests/ocs.openshift.io_storageclients.yaml b/bundle/manifests/ocs.openshift.io_storageclients.yaml index de346ec3..a22f7f93 100644 --- a/bundle/manifests/ocs.openshift.io_storageclients.yaml +++ b/bundle/manifests/ocs.openshift.io_storageclients.yaml @@ -61,6 +61,8 @@ spec: status: description: StorageClientStatus defines the observed state of StorageClient properties: + generateOMapInfo: + type: boolean id: description: ConsumerID will hold the identity of this cluster inside the attached provider cluster diff --git a/config/crd/bases/ocs.openshift.io_storageclients.yaml b/config/crd/bases/ocs.openshift.io_storageclients.yaml index ef813739..afa4a64c 100644 --- a/config/crd/bases/ocs.openshift.io_storageclients.yaml +++ b/config/crd/bases/ocs.openshift.io_storageclients.yaml @@ -61,6 +61,8 @@ spec: status: description: StorageClientStatus defines the observed state of StorageClient properties: + generateOMapInfo: + type: boolean id: description: ConsumerID will hold the identity of this cluster inside the attached provider cluster diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index c351400d..23a2e734 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -9,9 +9,7 @@ configMapGenerator: - files: - controller_manager_config.yaml name: manager-config -- literals: - - generateRbdOMapInfo=true - name: config +- name: config apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization diff --git a/go.sum b/go.sum index f454f87e..12e9e19c 100644 --- a/go.sum +++ b/go.sum @@ -327,8 +327,6 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237 h1:ig6ePD0yopC5Qi5BRmhsIsKaOkdsGXTSmG3HTYIpquo= github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237/go.mod h1:nO6VM/+PEhcPGyFIQJdhY6ip822cA61PAy/s6IjenAA= -github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241120160011-2e7cf0127dd4 h1:ppE7R+yh9I2PZuGPaUDdwQ45ZFV8YfHFNKccOxTo8tg= -github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241120160011-2e7cf0127dd4/go.mod h1:XEZxUtzjlARPV8YvzcX2p7iiRbrUbDP4Q/CXx9ly5lw= github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241203031449-434063b3178f h1:dqfWQkWWZpdNrzHX7sj+PzrCwbTT4Lqd8Oi8AU9LM3M= github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241203031449-434063b3178f/go.mod h1:XEZxUtzjlARPV8YvzcX2p7iiRbrUbDP4Q/CXx9ly5lw= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/internal/controller/operatorconfigmap_controller.go b/internal/controller/operatorconfigmap_controller.go index 6b7ceea2..d7fec00a 100644 --- a/internal/controller/operatorconfigmap_controller.go +++ b/internal/controller/operatorconfigmap_controller.go @@ -50,6 +50,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" + "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/predicate" @@ -151,6 +152,17 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error { ), ) + mirrorEnabledChangedPredicate := predicate.Funcs{ + UpdateFunc: func(e event.UpdateEvent) bool { + if e.ObjectOld == nil || e.ObjectNew == nil { + return false + } + oldObj := e.ObjectOld.(*v1alpha1.StorageClient) + newObj := e.ObjectNew.(*v1alpha1.StorageClient) + return oldObj.Status.MirrorEnabled != newObj.Status.MirrorEnabled + }, + } + generationChangePredicate := predicate.GenerationChangedPredicate{} bldr := ctrl.NewControllerManagedBy(mgr). For(&corev1.ConfigMap{}, configMapPredicates). @@ -174,7 +186,16 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error { ). Watches(&opv1a1.Subscription{}, enqueueConfigMapRequest, subscriptionPredicates). Watches(&admrv1.ValidatingWebhookConfiguration{}, enqueueConfigMapRequest, webhookPredicates). - Watches(&v1alpha1.StorageClient{}, enqueueConfigMapRequest, builder.WithPredicates(predicate.AnnotationChangedPredicate{})) + Watches( + &v1alpha1.StorageClient{}, + enqueueConfigMapRequest, + builder.WithPredicates( + predicate.Or( + predicate.AnnotationChangedPredicate{}, + mirrorEnabledChangedPredicate, + ), + ), + ) return bldr.Complete(c) } @@ -356,6 +377,11 @@ func (c *OperatorConfigMapReconciler) reconcileDelegatedCSI() error { return fmt.Errorf("failed to reconcile csi operator config: %v", err) } + shouldGenerateOmapInfo, err := c.shouldGenerateOmapInfo() + if err != nil { + return fmt.Errorf("failed to retrieve information to generateOMapInfo: %v", err) + } + // ceph rbd driver config rbdDriver := &csiopv1a1.Driver{} rbdDriver.Name = templates.RBDDriverName @@ -365,7 +391,7 @@ func (c *OperatorConfigMapReconciler) reconcileDelegatedCSI() error { if err := c.own(rbdDriver); err != nil { return fmt.Errorf("failed to own csi rbd driver: %v", err) } - rbdDriver.Spec.GenerateOMapInfo = ptr.To(c.shouldGenerateRBDOmapInfo()) + rbdDriver.Spec.GenerateOMapInfo = ptr.To(shouldGenerateOmapInfo) return nil }); err != nil { return fmt.Errorf("failed to reconcile rbd driver: %v", err) @@ -532,9 +558,20 @@ func (c *OperatorConfigMapReconciler) getNoobaaSubManagementConfig() bool { return val } -func (c *OperatorConfigMapReconciler) shouldGenerateRBDOmapInfo() bool { - valAsString := strings.ToLower(c.operatorConfigMap.Data[generateRbdOMapInfoKey]) - return valAsString == strconv.FormatBool(true) +func (c *OperatorConfigMapReconciler) shouldGenerateOmapInfo() (bool, error) { + + storageClients := &v1alpha1.StorageClientList{} + if err := c.list(storageClients); err != nil { + return false, err + } + + for idx := range storageClients.Items { + if storageClients.Items[idx].Status.MirrorEnabled { + return true, nil + } + + } + return false, nil } func (c *OperatorConfigMapReconciler) get(obj client.Object, opts ...client.GetOption) error { diff --git a/internal/controller/storageclient_controller.go b/internal/controller/storageclient_controller.go index c1585c13..d533fff8 100644 --- a/internal/controller/storageclient_controller.go +++ b/internal/controller/storageclient_controller.go @@ -207,6 +207,7 @@ func (r *StorageClientReconciler) reconcilePhases() (ctrl.Result, error) { if storageClientResponse.SystemAttributes != nil { r.storageClient.Status.InMaintenanceMode = storageClientResponse.SystemAttributes.SystemInMaintenanceMode + r.storageClient.Status.MirrorEnabled = storageClientResponse.SystemAttributes.MirrorEnabled } if res, err := r.reconcileClientStatusReporterJob(); err != nil { diff --git a/vendor/github.com/red-hat-storage/ocs-client-operator/api/v1alpha1/storageclient_types.go b/vendor/github.com/red-hat-storage/ocs-client-operator/api/v1alpha1/storageclient_types.go index 897b2a13..b7c447a8 100644 --- a/vendor/github.com/red-hat-storage/ocs-client-operator/api/v1alpha1/storageclient_types.go +++ b/vendor/github.com/red-hat-storage/ocs-client-operator/api/v1alpha1/storageclient_types.go @@ -52,6 +52,8 @@ type StorageClientStatus struct { InMaintenanceMode bool `json:"inMaintenanceMode,omitempty"` + MirrorEnabled bool `json:"generateOMapInfo,omitempty"` + // ConsumerID will hold the identity of this cluster inside the attached provider cluster ConsumerID string `json:"id,omitempty"` }