Skip to content

Commit

Permalink
Add watching on Secrets in drcluster_controller
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Gershkovich <elenage@il.ibm.com>
  • Loading branch information
ELENAGER committed Jan 11, 2024
1 parent 85fa41c commit 445d8a1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion controllers/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,13 @@ func (r *DRClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {

return ctrl.NewControllerManagedBy(mgr).
For(&ramen.DRCluster{}).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, handler.EnqueueRequestsFromMapFunc(r.drClusterConfigMapMapFunc)).
Watches(&source.Kind{Type: &ramen.DRPlacementControl{}}, drpcMapFun, builder.WithPredicates(drpcPred())).
Watches(&source.Kind{Type: &ocmworkv1.ManifestWork{}}, mwMapFun, builder.WithPredicates(mwPred)).
Watches(&source.Kind{Type: &viewv1beta1.ManagedClusterView{}}, mcvMapFun, builder.WithPredicates(mcvPred)).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, handler.EnqueueRequestsFromMapFunc(r.drClusterConfigMapMapFunc)).
Watches(&source.Kind{Type: &corev1.Secret{}}, handler.EnqueueRequestsFromMapFunc(r.drClusterSecretMapFunc),
builder.WithPredicates(util.CreateOrDeleteOrResourceVersionUpdatePredicate{}),
).
Complete(r)
}

Expand All @@ -141,6 +144,24 @@ func (r *DRClusterReconciler) drClusterConfigMapMapFunc(configMap client.Object)
return requests
}

func (r *DRClusterReconciler) drClusterSecretMapFunc(secret client.Object) []reconcile.Request {
if secret.GetNamespace() != NamespaceName() {
return []reconcile.Request{}
}

drcusters := &ramen.DRClusterList{}
if err := r.Client.List(context.TODO(), drcusters); err != nil {
return []reconcile.Request{}
}

requests := make([]reconcile.Request, len(drcusters.Items))
for i := range drcusters.Items {
requests[i].Name = drcusters.Items[i].GetName()
}

return requests
}

// drpcPred watches for updates to the DRPC resource and checks if it requires an appropriate DRCluster reconcile
func drpcPred() predicate.Funcs {
drpcPredicate := predicate.Funcs{
Expand Down Expand Up @@ -263,6 +284,7 @@ func filterDRClusterMCV(mcv *viewv1beta1.ManagedClusterView) []ctrl.Request {
// +kubebuilder:rbac:groups=apps.open-cluster-management.io,resources=placementrules,verbs=get;list;watch
// +kubebuilder:rbac:groups=cluster.open-cluster-management.io,resources=placements,verbs=get;list;watch
// +kubebuilder:rbac:groups=argoproj.io,resources=applicationsets,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=secrets,verbs=list;watch
// +kubebuilder:rbac:groups="",resources=configmaps,verbs=list;watch

func (r *DRClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
Expand Down

0 comments on commit 445d8a1

Please sign in to comment.