forked from rook/rook
mon: add watcher for DRBD ConfigMap in TNF deployments
Added a watcher in the cluster controller to detect changes to the DRBD ConfigMap used by floating monitors in TNF deployments. When the ConfigMap is updated, the watcher triggers a CephCluster reconciliation to ensure configuration changes are applied.
Fixes #17338
Signed-off-by: Prabhala Tara Aasrita <taraasrita@ibm.com>
(cherry picked from commit af03615e97)
This commit is contained in:
committed by
Mergify
parent
1b41970bed
commit
2821bd1bb4
@@ -296,7 +296,7 @@ func add(opManagerContext context.Context, mgr manager.Manager, r reconcile.Reco
|
||||
mgr.GetCache(),
|
||||
&corev1.ConfigMap{TypeMeta: metav1.TypeMeta{Kind: "ConfigMap", APIVersion: corev1.SchemeGroupVersion.String()}},
|
||||
handler.TypedEnqueueRequestsFromMapFunc(cmHandler),
|
||||
predicateForOperatorConfigCMWatcher(),
|
||||
predicateForClusterConfigMapWatcher(opManagerContext, mgr.GetClient()),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
|
||||
@@ -140,12 +140,26 @@ func isHotPlugCM(cm *corev1.ConfigMap) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// predicateForOperatorConfigCMWatcher is the predicate function to trigger reconcile on operator config ConfigMap events
|
||||
func predicateForOperatorConfigCMWatcher[T *corev1.ConfigMap]() predicate.TypedFuncs[T] {
|
||||
// predicateForClusterConfigMapWatcher is the predicate function to trigger reconcile on operator config ConfigMap events
|
||||
func predicateForClusterConfigMapWatcher[T *corev1.ConfigMap](ctx context.Context, client client.Client) predicate.TypedFuncs[T] {
|
||||
return predicate.TypedFuncs[T]{
|
||||
UpdateFunc: func(e event.TypedUpdateEvent[T]) bool {
|
||||
objNew := (*corev1.ConfigMap)(e.ObjectNew)
|
||||
return objNew.Name == opcontroller.OperatorSettingConfigMapName
|
||||
objOld := (*corev1.ConfigMap)(e.ObjectOld)
|
||||
|
||||
if objNew.Name == opcontroller.OperatorSettingConfigMapName {
|
||||
if objOld.Data["ROOK_USE_CSI_OPERATOR"] != objNew.Data["ROOK_USE_CSI_OPERATOR"] {
|
||||
log.NamespacedInfo(objNew.Namespace, logger, "ROOK_USE_CSI_OPERATOR changed from %q to %q", objOld.Data["ROOK_USE_CSI_OPERATOR"], objNew.Data["ROOK_USE_CSI_OPERATOR"])
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if isFloatingMonConfigMap(ctx, client, objNew) {
|
||||
log.NamespacedInfo(objNew.Namespace, logger, "floating mon ConfigMap %q changed", objNew.Name)
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
},
|
||||
|
||||
CreateFunc: func(e event.TypedCreateEvent[T]) bool {
|
||||
@@ -163,6 +177,25 @@ func predicateForOperatorConfigCMWatcher[T *corev1.ConfigMap]() predicate.TypedF
|
||||
}
|
||||
}
|
||||
|
||||
// isFloatingMonConfigMap checks if any floating mon configuration refers to the updated ConfigMap
|
||||
func isFloatingMonConfigMap(ctx context.Context, client client.Client, cm *corev1.ConfigMap) bool {
|
||||
clusterList := cephv1.CephClusterList{}
|
||||
err := client.List(ctx, &clusterList)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, cluster := range clusterList.Items {
|
||||
if cluster.Spec.Mon.FloatingMon.ConfigMapName != "" {
|
||||
if cm.GetName() == cluster.Spec.Mon.FloatingMon.ConfigMapName {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func watchControllerPredicate[T *cephv1.CephCluster](ctx context.Context, c client.Client) predicate.TypedFuncs[T] {
|
||||
return predicate.TypedFuncs[T]{
|
||||
CreateFunc: func(e event.TypedCreateEvent[T]) bool {
|
||||
|
||||
Reference in New Issue
Block a user