Skip to content

Commit 450fb7e

Browse files
committed
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 <[email protected]>
1 parent 4676e8b commit 450fb7e

File tree

10 files changed

+52
-17
lines changed

10 files changed

+52
-17
lines changed

api/v1alpha1/storageclient_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type StorageClientStatus struct {
5252

5353
InMaintenanceMode bool `json:"inMaintenanceMode,omitempty"`
5454

55+
MirrorEnabled bool `json:"generateOMapInfo,omitempty"`
56+
5557
// ConsumerID will hold the identity of this cluster inside the attached provider cluster
5658
ConsumerID string `json:"id,omitempty"`
5759
}

bundle/manifests/ocs-client-operator-config_v1_configmap.yaml

-6
This file was deleted.

bundle/manifests/ocs-client-operator.clusterserviceversion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ metadata:
77
categories: Storage
88
console.openshift.io/plugins: '["odf-client-console"]'
99
containerImage: quay.io/ocs-dev/ocs-client-operator:latest
10-
createdAt: "2024-11-27T03:54:42Z"
10+
createdAt: "2024-12-03T03:52:54Z"
1111
description: OpenShift Data Foundation client operator enables consumption of
1212
storage services from a remote centralized OpenShift Data Foundation provider
1313
cluster.

bundle/manifests/ocs.openshift.io_storageclients.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ spec:
6161
status:
6262
description: StorageClientStatus defines the observed state of StorageClient
6363
properties:
64+
generateOMapInfo:
65+
type: boolean
6466
id:
6567
description: ConsumerID will hold the identity of this cluster inside
6668
the attached provider cluster

config/crd/bases/ocs.openshift.io_storageclients.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ spec:
6161
status:
6262
description: StorageClientStatus defines the observed state of StorageClient
6363
properties:
64+
generateOMapInfo:
65+
type: boolean
6466
id:
6567
description: ConsumerID will hold the identity of this cluster inside
6668
the attached provider cluster

config/manager/kustomization.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ configMapGenerator:
99
- files:
1010
- controller_manager_config.yaml
1111
name: manager-config
12-
- literals:
13-
- generateRbdOMapInfo=true
14-
name: config
1512

1613
apiVersion: kustomize.config.k8s.io/v1beta1
1714
kind: Kustomization

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
327327
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
328328
github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237 h1:ig6ePD0yopC5Qi5BRmhsIsKaOkdsGXTSmG3HTYIpquo=
329329
github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237/go.mod h1:nO6VM/+PEhcPGyFIQJdhY6ip822cA61PAy/s6IjenAA=
330-
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241120160011-2e7cf0127dd4 h1:ppE7R+yh9I2PZuGPaUDdwQ45ZFV8YfHFNKccOxTo8tg=
331-
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241120160011-2e7cf0127dd4/go.mod h1:XEZxUtzjlARPV8YvzcX2p7iiRbrUbDP4Q/CXx9ly5lw=
332330
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241203031449-434063b3178f h1:dqfWQkWWZpdNrzHX7sj+PzrCwbTT4Lqd8Oi8AU9LM3M=
333331
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241203031449-434063b3178f/go.mod h1:XEZxUtzjlARPV8YvzcX2p7iiRbrUbDP4Q/CXx9ly5lw=
334332
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

internal/controller/operatorconfigmap_controller.go

+42-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
"sigs.k8s.io/controller-runtime/pkg/builder"
5151
"sigs.k8s.io/controller-runtime/pkg/client"
5252
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
53+
"sigs.k8s.io/controller-runtime/pkg/event"
5354
"sigs.k8s.io/controller-runtime/pkg/handler"
5455
"sigs.k8s.io/controller-runtime/pkg/log"
5556
"sigs.k8s.io/controller-runtime/pkg/predicate"
@@ -151,6 +152,17 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
151152
),
152153
)
153154

155+
mirrorEnabledChangedPredicate := predicate.Funcs{
156+
UpdateFunc: func(e event.UpdateEvent) bool {
157+
if e.ObjectOld == nil || e.ObjectNew == nil {
158+
return false
159+
}
160+
oldObj := e.ObjectOld.(*v1alpha1.StorageClient)
161+
newObj := e.ObjectNew.(*v1alpha1.StorageClient)
162+
return oldObj.Status.MirrorEnabled != newObj.Status.MirrorEnabled
163+
},
164+
}
165+
154166
generationChangePredicate := predicate.GenerationChangedPredicate{}
155167
bldr := ctrl.NewControllerManagedBy(mgr).
156168
For(&corev1.ConfigMap{}, configMapPredicates).
@@ -174,7 +186,16 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
174186
).
175187
Watches(&opv1a1.Subscription{}, enqueueConfigMapRequest, subscriptionPredicates).
176188
Watches(&admrv1.ValidatingWebhookConfiguration{}, enqueueConfigMapRequest, webhookPredicates).
177-
Watches(&v1alpha1.StorageClient{}, enqueueConfigMapRequest, builder.WithPredicates(predicate.AnnotationChangedPredicate{}))
189+
Watches(
190+
&v1alpha1.StorageClient{},
191+
enqueueConfigMapRequest,
192+
builder.WithPredicates(
193+
predicate.Or(
194+
predicate.AnnotationChangedPredicate{},
195+
mirrorEnabledChangedPredicate,
196+
),
197+
),
198+
)
178199

179200
return bldr.Complete(c)
180201
}
@@ -356,6 +377,11 @@ func (c *OperatorConfigMapReconciler) reconcileDelegatedCSI() error {
356377
return fmt.Errorf("failed to reconcile csi operator config: %v", err)
357378
}
358379

380+
shouldGenerateOmapInfo, err := c.shouldGenerateOmapInfo()
381+
if err != nil {
382+
return fmt.Errorf("failed to retrieve information to generateOMapInfo: %v", err)
383+
}
384+
359385
// ceph rbd driver config
360386
rbdDriver := &csiopv1a1.Driver{}
361387
rbdDriver.Name = templates.RBDDriverName
@@ -365,7 +391,7 @@ func (c *OperatorConfigMapReconciler) reconcileDelegatedCSI() error {
365391
if err := c.own(rbdDriver); err != nil {
366392
return fmt.Errorf("failed to own csi rbd driver: %v", err)
367393
}
368-
rbdDriver.Spec.GenerateOMapInfo = ptr.To(c.shouldGenerateRBDOmapInfo())
394+
rbdDriver.Spec.GenerateOMapInfo = ptr.To(shouldGenerateOmapInfo)
369395
return nil
370396
}); err != nil {
371397
return fmt.Errorf("failed to reconcile rbd driver: %v", err)
@@ -532,9 +558,20 @@ func (c *OperatorConfigMapReconciler) getNoobaaSubManagementConfig() bool {
532558
return val
533559
}
534560

535-
func (c *OperatorConfigMapReconciler) shouldGenerateRBDOmapInfo() bool {
536-
valAsString := strings.ToLower(c.operatorConfigMap.Data[generateRbdOMapInfoKey])
537-
return valAsString == strconv.FormatBool(true)
561+
func (c *OperatorConfigMapReconciler) shouldGenerateOmapInfo() (bool, error) {
562+
563+
storageClients := &v1alpha1.StorageClientList{}
564+
if err := c.list(storageClients); err != nil {
565+
return false, err
566+
}
567+
568+
for idx := range storageClients.Items {
569+
if storageClients.Items[idx].Status.MirrorEnabled {
570+
return true, nil
571+
}
572+
573+
}
574+
return false, nil
538575
}
539576

540577
func (c *OperatorConfigMapReconciler) get(obj client.Object, opts ...client.GetOption) error {

internal/controller/storageclient_controller.go

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func (r *StorageClientReconciler) reconcilePhases() (ctrl.Result, error) {
207207

208208
if storageClientResponse.SystemAttributes != nil {
209209
r.storageClient.Status.InMaintenanceMode = storageClientResponse.SystemAttributes.SystemInMaintenanceMode
210+
r.storageClient.Status.MirrorEnabled = storageClientResponse.SystemAttributes.MirrorEnabled
210211
}
211212

212213
if res, err := r.reconcileClientStatusReporterJob(); err != nil {

vendor/github.com/red-hat-storage/ocs-client-operator/api/v1alpha1/storageclient_types.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)