From 5a2b3066397c85b75b3ba1c395e6e69f387de610 Mon Sep 17 00:00:00 2001 From: Kefei Zhang Date: Thu, 5 Sep 2024 02:26:05 +0800 Subject: [PATCH] fix GMC crashes in e2e (#395) * add debug message Signed-off-by: KfreeZ * ignore create/delete func Signed-off-by: KfreeZ * add protection Signed-off-by: KfreeZ --------- Signed-off-by: KfreeZ --- .../internal/controller/gmconnector_controller.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/microservices-connector/internal/controller/gmconnector_controller.go b/microservices-connector/internal/controller/gmconnector_controller.go index ee3df3fb..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 { @@ -880,6 +883,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).