Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers: deploy omap sidecar only when required #286

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:"mirrorEnabled,omitempty"`

// ConsumerID will hold the identity of this cluster inside the attached provider cluster
ConsumerID string `json:"id,omitempty"`
}
Expand Down
2 changes: 0 additions & 2 deletions bundle/manifests/ocs-client-operator-config_v1_configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
apiVersion: v1
data:
generateRbdOMapInfo: "true"
kind: ConfigMap
metadata:
name: ocs-client-operator-config
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-03T04:06:44Z"
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 @@ -67,6 +67,8 @@ spec:
type: string
inMaintenanceMode:
type: boolean
mirrorEnabled:
type: boolean
phase:
type: string
type: object
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 @@ -67,6 +67,8 @@ spec:
type: string
inMaintenanceMode:
type: boolean
mirrorEnabled:
type: boolean
phase:
type: string
type: object
Expand Down
4 changes: 1 addition & 3 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.76.0
github.com/ramendr/ramen/api v0.0.0-20241001141243-29d6f22ad237
github.com/red-hat-storage/ocs-client-operator/api v0.0.0-00010101000000-000000000000
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241120160011-2e7cf0127dd4
github.com/red-hat-storage/ocs-operator/services/provider/api/v4 v4.0.0-20241203031449-434063b3178f
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.68.0
k8s.io/api v0.31.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,8 @@ 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=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
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
},
}
Comment on lines +155 to +164
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually do not predicate on a single field in the spec but on the entire spec using a generation change predicate (as we consider this an overoptimization), especially when considering CRs that are almost singletons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we are storing the MirroringEnabled flag in the status of the storageClient CR, I want the operatorConfigmap controller to trigger a reconciliation only when the field changes. I could watch for the entire status but I think it's better to be specific here

Copy link
Contributor

@nb-ohad nb-ohad Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if a status update affects the generation of a CR or not. But either way, this seems like the wrong thing to watch


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
}

}
Comment on lines +568 to +573
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are to generate omap data in cases where a single client requests it, how would that affect the other clients that don't need it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any client is requesting for the omap info, we are going to enable it, as this is a operator level operation we cannot restrict it to per client

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but I was asking about the impact/the side effects. Not the procedure

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The impact would be that we enable it for all other clients as well. I don't think we have any side effects if it is always enabled

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we are talking about the status section (where we reflect the actual state and not the desired state) I am not sure it is correct to reflect that the client is mirror-enabled before validating that the omap generator is running. In addition shouldn't we reflect similar things for other clients? shouldn't this be more granular?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I want to convey that the client is enabled for mirroring on the provider side. Hence storing the actual state in the Status, the desired state would be in the storage-client-mapping in the Provider side

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an issue here, status should not be treated as desired state and should be considered as something that can be deleted at any point in time.

}

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.

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

Loading
Loading