Skip to content

Commit d8f1e3d

Browse files
author
YuChen
committed
add ConfigMaps predicate functions in cs controller setup
Signed-off-by: YuChen <yuchen.shen@mail.utoronto.ca>
1 parent 01889f6 commit d8f1e3d

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

internal/controller/commonservice_controller.go

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,24 @@ func (r *CommonServiceReconciler) ReconcileNonConfigurableCR(ctx context.Context
469469
return ctrl.Result{}, nil
470470
}
471471

472-
func (r *CommonServiceReconciler) mappingToCsRequest() handler.MapFunc {
472+
func (r *CommonServiceReconciler) mappingToCsRequestForConfigMaps() handler.MapFunc {
473473
return func(object client.Object) []reconcile.Request {
474-
CsInstance := []reconcile.Request{}
475-
cmName := object.GetName()
476-
cmNs := object.GetNamespace()
477-
if cmName == constant.CsMapConfigMap && cmNs == "kube-public" {
478-
CsInstance = append(CsInstance, reconcile.Request{NamespacedName: types.NamespacedName{Name: constant.MasterCR, Namespace: r.Bootstrap.CSData.OperatorNs}})
474+
configMap, ok := object.(*corev1.ConfigMap)
475+
if !ok {
476+
return nil
477+
}
478+
479+
// Check two configmaps: common-service-maps and ibm-cpp-config
480+
if (configMap.Name == constant.CsMapConfigMap && configMap.Namespace == constant.CsMapConfigMapNs) ||
481+
(configMap.Name == constant.IBMCPPCONFIG && configMap.Namespace == r.Bootstrap.CSData.ServicesNs) {
482+
return []reconcile.Request{
483+
{NamespacedName: types.NamespacedName{
484+
Name: constant.MasterCR,
485+
Namespace: r.Bootstrap.CSData.OperatorNs,
486+
}},
487+
}
479488
}
480-
return CsInstance
489+
return nil
481490
}
482491
}
483492

@@ -546,17 +555,11 @@ func (r *CommonServiceReconciler) SetupWithManager(mgr ctrl.Manager) error {
546555
predicate.LabelChangedPredicate{}))).
547556
Watches(
548557
&source.Kind{Type: &corev1.ConfigMap{}},
549-
handler.EnqueueRequestsFromMapFunc(r.mappingToCsRequest()),
558+
handler.EnqueueRequestsFromMapFunc(r.mappingToCsRequestForConfigMaps()),
550559
builder.WithPredicates(predicate.Funcs{
551-
CreateFunc: func(e event.CreateEvent) bool {
552-
return true
553-
},
554-
DeleteFunc: func(e event.DeleteEvent) bool {
555-
return !e.DeleteStateUnknown
556-
},
557-
UpdateFunc: func(e event.UpdateEvent) bool {
558-
return true
559-
},
560+
CreateFunc: func(e event.CreateEvent) bool { return true },
561+
UpdateFunc: func(e event.UpdateEvent) bool { return true },
562+
DeleteFunc: func(e event.DeleteEvent) bool { return !e.DeleteStateUnknown },
560563
}))
561564
if isOpregAPI, err := r.Bootstrap.CheckCRD(constant.OpregAPIGroupVersion, constant.OpregKind); err != nil {
562565
klog.Errorf("Failed to check if OperandRegistry CRD exists: %v", err)

internal/controller/constant/constant.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const (
4242
ClusterOperatorNamespace = "openshift-operators"
4343
// CS map configMap
4444
CsMapConfigMap = "common-service-maps"
45+
// CS map configMap namespace
46+
CsMapConfigMapNs = "kube-public"
4547
// CS Saas configMap
4648
SaasConfigMap = "saas-config"
4749
// Namespace Scope Operator resource name

0 commit comments

Comments
 (0)