From b3bf87d574aca4cf37af7bb8cc07865de3c74191 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Thu, 10 Oct 2024 17:51:06 +0200 Subject: [PATCH] Make sure to log error in findObjectsForSrc() It is hidden right now if there is an error in configured named fields and index. Lets log the error and return the current state of requests. With this the findObjectsForSrc() will exit with an hidden error like: ``` "error": "Index with name field:.spec.ksmTls.caBundleSecretName does not exist" ``` Signed-off-by: Martin Schuppert --- .../instanceha/instanceha_controller.go | 22 +++++-------------- controllers/memcached/memcached_controller.go | 7 +++++- .../rabbitmq/transporturl_controller.go | 7 +++++- controllers/redis/redis_controller.go | 7 +++++- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/controllers/instanceha/instanceha_controller.go b/controllers/instanceha/instanceha_controller.go index 306eb176..9ce979fc 100644 --- a/controllers/instanceha/instanceha_controller.go +++ b/controllers/instanceha/instanceha_controller.go @@ -540,27 +540,14 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc), builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), ). - Watches( - &corev1.Secret{}, - handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc), - builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), - ). - Watches( - &corev1.Secret{}, - handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc), - builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), - ). - Watches( - &corev1.ConfigMap{}, - handler.EnqueueRequestsFromMapFunc(r.findObjectsForSrc), - builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), - ). Complete(r) } func (r *Reconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request { requests := []reconcile.Request{} + l := log.FromContext(context.Background()).WithName("Controllers").WithName("InstanceHa") + for _, field := range allWatchFields { crList := &instancehav1.InstanceHaList{} listOps := &client.ListOptions{ @@ -569,10 +556,13 @@ func (r *Reconciler) findObjectsForSrc(ctx context.Context, src client.Object) [ } err := r.List(ctx, crList, listOps) if err != nil { - return []reconcile.Request{} + l.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace())) + return requests } for _, item := range crList.Items { + l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace())) + requests = append(requests, reconcile.Request{ NamespacedName: types.NamespacedName{ diff --git a/controllers/memcached/memcached_controller.go b/controllers/memcached/memcached_controller.go index 39018d73..edf18af5 100644 --- a/controllers/memcached/memcached_controller.go +++ b/controllers/memcached/memcached_controller.go @@ -468,6 +468,8 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *Reconciler) findObjectsForSrc(_ context.Context, src client.Object) []reconcile.Request { requests := []reconcile.Request{} + l := log.FromContext(context.Background()).WithName("Controllers").WithName("Memcached") + for _, field := range allWatchFields { crList := &memcachedv1.MemcachedList{} listOps := &client.ListOptions{ @@ -476,10 +478,13 @@ func (r *Reconciler) findObjectsForSrc(_ context.Context, src client.Object) []r } err := r.List(context.TODO(), crList, listOps) if err != nil { - return []reconcile.Request{} + l.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace())) + return requests } for _, item := range crList.Items { + l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace())) + requests = append(requests, reconcile.Request{ NamespacedName: types.NamespacedName{ diff --git a/controllers/rabbitmq/transporturl_controller.go b/controllers/rabbitmq/transporturl_controller.go index f7ebdf9a..b95a8718 100644 --- a/controllers/rabbitmq/transporturl_controller.go +++ b/controllers/rabbitmq/transporturl_controller.go @@ -368,6 +368,8 @@ func (r *TransportURLReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *TransportURLReconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request { requests := []reconcile.Request{} + l := log.FromContext(context.Background()).WithName("Controllers").WithName("TransportURL") + for _, field := range allWatchFields { crList := &rabbitmqv1.TransportURLList{} listOps := &client.ListOptions{ @@ -376,10 +378,13 @@ func (r *TransportURLReconciler) findObjectsForSrc(ctx context.Context, src clie } err := r.List(ctx, crList, listOps) if err != nil { - return []reconcile.Request{} + l.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace())) + return requests } for _, item := range crList.Items { + l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace())) + requests = append(requests, reconcile.Request{ NamespacedName: types.NamespacedName{ diff --git a/controllers/redis/redis_controller.go b/controllers/redis/redis_controller.go index f69e3122..dd7c5746 100644 --- a/controllers/redis/redis_controller.go +++ b/controllers/redis/redis_controller.go @@ -465,6 +465,8 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *Reconciler) findObjectsForSrc(ctx context.Context, src client.Object) []reconcile.Request { requests := []reconcile.Request{} + l := log.FromContext(context.Background()).WithName("Controllers").WithName("Redis") + for _, field := range allWatchFields { crList := &redisv1.RedisList{} listOps := &client.ListOptions{ @@ -473,10 +475,13 @@ func (r *Reconciler) findObjectsForSrc(ctx context.Context, src client.Object) [ } err := r.List(ctx, crList, listOps) if err != nil { - return []reconcile.Request{} + l.Error(err, fmt.Sprintf("listing %s for field: %s - %s", crList.GroupVersionKind().Kind, field, src.GetNamespace())) + return requests } for _, item := range crList.Items { + l.Info(fmt.Sprintf("input source %s changed, reconcile: %s - %s", src.GetName(), item.GetName(), item.GetNamespace())) + requests = append(requests, reconcile.Request{ NamespacedName: types.NamespacedName{