Skip to content

Commit

Permalink
debug logs for controller ref
Browse files Browse the repository at this point in the history
Signed-off-by: Coleen Iona Quadros <[email protected]>
  • Loading branch information
coleenquadros committed Oct 13, 2023
1 parent 53cb37d commit c5165b9
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ func (r *MultiClusterObservabilityReconciler) Reconcile(ctx context.Context, req
reqLogger.Error(err, fmt.Sprintf("Failed to create namespace %s", resNS))
return ctrl.Result{}, err
}
//set controller reference for the namespace
if err := controllerutil.SetControllerReference(instance, ns, r.Scheme); err != nil {
reqLogger.Error(err, "Failed to set controller reference", "kind", resNS, "name", ns.GetName())
}
}
if err := deployer.Deploy(res); err != nil {
reqLogger.Error(err, fmt.Sprintf("Failed to deploy %s %s/%s",
Expand Down Expand Up @@ -514,6 +510,20 @@ func (r *MultiClusterObservabilityReconciler) SetupWithManager(mgr ctrl.Manager)
},
}

var namespacePred = predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
return e.Object.GetName() == config.GetDefaultNamespace()
},
UpdateFunc: func(e event.UpdateEvent) bool {
labelVal, labelExists := e.ObjectNew.GetLabels()[openShiftClusterMonitoringLabel]
shouldReconcile := !labelExists || (labelExists && labelVal != "true")
return e.ObjectNew.GetName() == config.GetDefaultNamespace() && shouldReconcile
},
DeleteFunc: func(e event.DeleteEvent) bool {
return false
},
}

ctrBuilder := ctrl.NewControllerManagedBy(mgr).
// Watch for changes to primary resource MultiClusterObservability with predicate
For(&mcov1beta2.MultiClusterObservability{}, builder.WithPredicates(mcoPred)).
Expand All @@ -529,13 +539,12 @@ func (r *MultiClusterObservabilityReconciler) SetupWithManager(mgr ctrl.Manager)
Owns(&corev1.Service{}).
// Watch for changes to secondary Observatorium CR and requeue the owner MultiClusterObservability
Owns(&observatoriumv1alpha1.Observatorium{}).
//Watch for changes to namespace and requeue the owner MultiClusterObservability
Owns(&corev1.Namespace{}).
// Watch the configmap for thanos-ruler-custom-rules update
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(cmPred)).

// Watch the secret for deleting event of alertmanager-config
Watches(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(secretPred))
Watches(&source.Kind{Type: &corev1.Secret{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(secretPred)).
// Watch the namespace for changes
Watches(&source.Kind{Type: &corev1.Namespace{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(namespacePred))

mchGroupKind := schema.GroupKind{Group: mchv1.GroupVersion.Group, Kind: "MultiClusterHub"}
if _, err := r.RESTMapper.RESTMapping(mchGroupKind, mchv1.GroupVersion.Version); err == nil {
Expand Down

0 comments on commit c5165b9

Please sign in to comment.