Skip to content

Commit

Permalink
controllers: generateOMap info only when required
Browse files Browse the repository at this point in the history
Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Dec 2, 2024
1 parent c99a838 commit 4ee9f67
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 6 deletions.
2 changes: 2 additions & 0 deletions api/v1alpha1/storageclient_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type StorageClientStatus struct {

InMaintenanceMode bool `json:"inMaintenanceMode,omitempty"`

GenerateOMapInfo bool `json:"generateOMapInfo,omitempty"`

// ConsumerID will hold the identity of this cluster inside the attached provider cluster
ConsumerID string `json:"id,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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-02T09:16:34Z"
description: OpenShift Data Foundation client operator enables consumption of
storage services from a remote centralized OpenShift Data Foundation provider
cluster.
Expand Down
2 changes: 2 additions & 0 deletions bundle/manifests/ocs.openshift.io_storageclients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/ocs.openshift.io_storageclients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 42 additions & 5 deletions internal/controller/operatorconfigmap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"bytes"
"context"
"fmt"
"sigs.k8s.io/controller-runtime/pkg/event"
"strconv"
"strings"

Expand Down Expand Up @@ -151,6 +152,17 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
),
)

generateOMapInfoChangedPredicate := 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.GenerateOMapInfo != newObj.Status.GenerateOMapInfo
},
}

generationChangePredicate := predicate.GenerationChangedPredicate{}
bldr := ctrl.NewControllerManagedBy(mgr).
For(&corev1.ConfigMap{}, configMapPredicates).
Expand All @@ -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{},
generateOMapInfoChangedPredicate,
),
),
)

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

shouldGenerateRBDOmapInfo, err := c.shouldGenerateRBDOmapInfo()
if err != nil {
return fmt.Errorf("failed to retrive information to generateOMapInfo: %v", err)

Check failure on line 382 in internal/controller/operatorconfigmap_controller.go

View workflow job for this annotation

GitHub Actions / codespell

retrive ==> retrieve
}

// ceph rbd driver config
rbdDriver := &csiopv1a1.Driver{}
rbdDriver.Name = templates.RBDDriverName
Expand All @@ -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(shouldGenerateRBDOmapInfo)
return nil
}); err != nil {
return fmt.Errorf("failed to reconcile rbd driver: %v", err)
Expand Down Expand Up @@ -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) shouldGenerateRBDOmapInfo() (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.GenerateOMapInfo {
return true, nil
}

}
return false, nil
}

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

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

0 comments on commit 4ee9f67

Please sign in to comment.