2021-08-06 17:46:01 +02:00
|
|
|
/*
|
|
|
|
|
Copyright 2021 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Package operator to manage Kubernetes storage.
|
|
|
|
|
package operator
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/rook/rook/pkg/operator/ceph/controller"
|
2025-03-31 08:46:53 -07:00
|
|
|
corev1 "k8s.io/api/core/v1"
|
2021-08-06 17:46:01 +02:00
|
|
|
"sigs.k8s.io/controller-runtime/pkg/event"
|
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
|
|
|
|
)
|
|
|
|
|
|
2024-04-08 18:01:54 +08:00
|
|
|
// predicateController is the predicate function to trigger reconcile on operator configuration cm change
|
2025-03-31 08:46:53 -07:00
|
|
|
func operatorSettingConfigMapPredicate[T *corev1.ConfigMap]() predicate.TypedFuncs[T] {
|
|
|
|
|
return predicate.TypedFuncs[T]{
|
|
|
|
|
CreateFunc: func(e event.TypedCreateEvent[T]) bool {
|
|
|
|
|
obj := (*corev1.ConfigMap)(e.Object)
|
|
|
|
|
|
|
|
|
|
return obj.GetName() == controller.OperatorSettingConfigMapName
|
2021-08-06 17:46:01 +02:00
|
|
|
},
|
|
|
|
|
|
2025-03-31 08:46:53 -07:00
|
|
|
UpdateFunc: func(e event.TypedUpdateEvent[T]) bool {
|
|
|
|
|
objOld := (*corev1.ConfigMap)(e.ObjectOld)
|
|
|
|
|
objNew := (*corev1.ConfigMap)(e.ObjectNew)
|
2021-08-06 17:46:01 +02:00
|
|
|
|
2025-03-31 08:46:53 -07:00
|
|
|
if objOld.GetName() == controller.OperatorSettingConfigMapName && objNew.GetName() == controller.OperatorSettingConfigMapName {
|
|
|
|
|
if objOld.Data["ROOK_CURRENT_NAMESPACE_ONLY"] != objNew.Data["ROOK_CURRENT_NAMESPACE_ONLY"] {
|
|
|
|
|
logger.Debug("ROOK_CURRENT_NAMESPACE_ONLY config updated, reloading the manager")
|
|
|
|
|
controller.ReloadManager()
|
2021-08-06 17:46:01 +02:00
|
|
|
|
2025-03-31 08:46:53 -07:00
|
|
|
// No need to ask for reconciliation since the context is going to be terminated when
|
|
|
|
|
// the signal is caught and the reconcile will run when the controller starts.
|
2021-08-06 17:46:01 +02:00
|
|
|
return false
|
|
|
|
|
}
|
2025-03-31 08:46:53 -07:00
|
|
|
|
|
|
|
|
// We still want to reconcile the operator manager if the configmap is updated
|
|
|
|
|
return true
|
2021-08-06 17:46:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
},
|
|
|
|
|
|
2025-03-31 08:46:53 -07:00
|
|
|
DeleteFunc: func(e event.TypedDeleteEvent[T]) bool {
|
|
|
|
|
obj := (*corev1.ConfigMap)(e.Object)
|
|
|
|
|
|
|
|
|
|
if obj.GetName() == controller.OperatorSettingConfigMapName {
|
|
|
|
|
logger.Debug("operator configmap deleted, not reconciling")
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
GenericFunc: func(e event.TypedGenericEvent[T]) bool {
|
2021-08-06 17:46:01 +02:00
|
|
|
return false
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|