-
Notifications
You must be signed in to change notification settings - Fork 23
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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" | ||
|
@@ -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). | ||
|
@@ -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) | ||
} | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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