From a357b9d951c5f4e406a8e4547082fed4bbb836ca Mon Sep 17 00:00:00 2001 From: KfreeZ Date: Thu, 5 Sep 2024 01:08:49 +0800 Subject: [PATCH 1/3] add debug message Signed-off-by: KfreeZ --- .../internal/controller/gmconnector_controller.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microservices-connector/internal/controller/gmconnector_controller.go b/microservices-connector/internal/controller/gmconnector_controller.go index ee3df3fb..53bf82cf 100644 --- a/microservices-connector/internal/controller/gmconnector_controller.go +++ b/microservices-connector/internal/controller/gmconnector_controller.go @@ -825,12 +825,12 @@ func isDeploymentStatusChanged(e event.UpdateEvent) bool { } if len(newDeployment.OwnerReferences) == 0 { - // fmt.Printf("| %s:%s: no owner reference |\n", newDeployment.Namespace, newDeployment.Name) + fmt.Printf("| %s:%s: no owner reference |\n", newDeployment.Namespace, newDeployment.Name) return false } else { for _, owner := range newDeployment.OwnerReferences { if owner.Kind == "GMConnector" { - // fmt.Printf("| %s:%s: owner is GMConnector |\n", newDeployment.Namespace, newDeployment.Name) + fmt.Printf("| %s:%s: owner is GMConnector |\n", newDeployment.Namespace, newDeployment.Name) break } } From 1de3f8d5ba457a1bdbdabb2446b714df83f63dd7 Mon Sep 17 00:00:00 2001 From: KfreeZ Date: Thu, 5 Sep 2024 01:21:23 +0800 Subject: [PATCH 2/3] ignore create/delete func Signed-off-by: KfreeZ --- .../internal/controller/gmconnector_controller.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/microservices-connector/internal/controller/gmconnector_controller.go b/microservices-connector/internal/controller/gmconnector_controller.go index 53bf82cf..6b704cb9 100644 --- a/microservices-connector/internal/controller/gmconnector_controller.go +++ b/microservices-connector/internal/controller/gmconnector_controller.go @@ -880,6 +880,12 @@ func (r *GMConnectorReconciler) SetupWithManager(mgr ctrl.Manager) error { // Predicate to only trigger on status changes for Deployment deploymentFilter := predicate.Funcs{ UpdateFunc: isDeploymentStatusChanged, + //ignore create and delete events, otherwise it will trigger the nested reconcile which is meaningless + CreateFunc: func(e event.CreateEvent) bool { + return false + }, DeleteFunc: func(e event.DeleteEvent) bool { + return false + }, } return ctrl.NewControllerManagedBy(mgr). From e07964b5a30ef86b17fc18f05b63aa39b9df9f86 Mon Sep 17 00:00:00 2001 From: KfreeZ Date: Thu, 5 Sep 2024 01:50:14 +0800 Subject: [PATCH 3/3] add protection Signed-off-by: KfreeZ --- .../internal/controller/gmconnector_controller.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/microservices-connector/internal/controller/gmconnector_controller.go b/microservices-connector/internal/controller/gmconnector_controller.go index 6b704cb9..46169db8 100644 --- a/microservices-connector/internal/controller/gmconnector_controller.go +++ b/microservices-connector/internal/controller/gmconnector_controller.go @@ -474,6 +474,9 @@ func (r *GMConnectorReconciler) deleteRecordedResource(key string, ctx context.C } func (r *GMConnectorReconciler) collectResourceStatus(graph *mcv1alpha3.GMConnector, ctx context.Context) error { + if graph == nil || len(graph.Status.Annotations) == 0 { + return errors.New("graph is empty or no annotations") + } var totalCnt uint = 0 var readyCnt uint = 0 for resName := range graph.Status.Annotations { @@ -825,12 +828,12 @@ func isDeploymentStatusChanged(e event.UpdateEvent) bool { } if len(newDeployment.OwnerReferences) == 0 { - fmt.Printf("| %s:%s: no owner reference |\n", newDeployment.Namespace, newDeployment.Name) + // fmt.Printf("| %s:%s: no owner reference |\n", newDeployment.Namespace, newDeployment.Name) return false } else { for _, owner := range newDeployment.OwnerReferences { if owner.Kind == "GMConnector" { - fmt.Printf("| %s:%s: owner is GMConnector |\n", newDeployment.Namespace, newDeployment.Name) + // fmt.Printf("| %s:%s: owner is GMConnector |\n", newDeployment.Namespace, newDeployment.Name) break } }