Skip to content

Commit 88bec5e

Browse files
committed
controllers: deploy omap sidecar only when required
Signed-off-by: Rewant Soni <[email protected]>
1 parent c99a838 commit 88bec5e

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
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+
GenerateOMapInfo 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.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-02T09:16:34Z"
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

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+
generateOMapInfoChangedPredicate := 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.GenerateOMapInfo != newObj.Status.GenerateOMapInfo
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+
generateOMapInfoChangedPredicate,
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+
shouldGenerateRBDOmapInfo, err := c.shouldGenerateRBDOmapInfo()
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(shouldGenerateRBDOmapInfo)
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) shouldGenerateRBDOmapInfo() (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.GenerateOMapInfo {
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 {

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)