Skip to content

Commit

Permalink
controllers: deploy omap sidecar only when required
Browse files Browse the repository at this point in the history
move from always deploying the omap side car to deploy it only
when required

Signed-off-by: Rewant Soni <[email protected]>
  • Loading branch information
rewantsoni committed Dec 3, 2024
1 parent 4676e8b commit 450fb7e
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 17 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"`

MirrorEnabled bool `json:"generateOMapInfo,omitempty"`

// ConsumerID will hold the identity of this cluster inside the attached provider cluster
ConsumerID string `json:"id,omitempty"`
}
Expand Down
6 changes: 0 additions & 6 deletions bundle/manifests/ocs-client-operator-config_v1_configmap.yaml

This file was deleted.

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-03T03:52:54Z"
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
3 changes: 0 additions & 3 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ configMapGenerator:
- files:
- controller_manager_config.yaml
name: manager-config
- literals:
- generateRbdOMapInfo=true
name: config

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
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 @@ -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"
Expand Down Expand Up @@ -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).
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{},
mirrorEnabledChangedPredicate,
),
),
)

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)
}

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
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(shouldGenerateOmapInfo)
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) 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 {
Expand Down
1 change: 1 addition & 0 deletions internal/controller/storageclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

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

0 comments on commit 450fb7e

Please sign in to comment.