diff --git a/pkg/controllers/node/node_controller.go b/pkg/controllers/node/node_controller.go index c0197cb74..2f541e7ae 100644 --- a/pkg/controllers/node/node_controller.go +++ b/pkg/controllers/node/node_controller.go @@ -45,6 +45,11 @@ func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. if errors.IsNotFound(err) { log.Info("node not found", "req", req.NamespacedName) deleted = true + if err := r.Service.SyncNodeStore(req.NamespacedName.Name, deleted); err != nil { + log.Error(err, "failed to sync node store", "req", req.NamespacedName) + return common.ResultNormal, err + } + return common.ResultNormal, nil } else { log.Error(err, "unable to fetch node", "req", req.NamespacedName) } @@ -53,7 +58,7 @@ func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. if common.NodeIsMaster(node) { // For WCP supervisor cluster, the master node isn't a transport node. log.Info("skipping handling master node", "node", req.NamespacedName) - return ctrl.Result{}, nil + return common.ResultNormal, nil } if !node.ObjectMeta.DeletionTimestamp.IsZero() { log.Info("node is being deleted", "node", req.NamespacedName) @@ -62,9 +67,9 @@ func (r *NodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl. if err := r.Service.SyncNodeStore(node.Name, deleted); err != nil { log.Error(err, "failed to sync node store", "req", req.NamespacedName) - return ctrl.Result{}, err + return common.ResultNormal, err } - return ctrl.Result{}, nil + return common.ResultNormal, nil } // SetupWithManager sets up the controller with the Manager. diff --git a/pkg/controllers/node/node_controller_test.go b/pkg/controllers/node/node_controller_test.go index 49d03dde7..17df85456 100644 --- a/pkg/controllers/node/node_controller_test.go +++ b/pkg/controllers/node/node_controller_test.go @@ -90,18 +90,28 @@ func TestNodeReconciler_Reconcile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { ctx := context.Background() + nodeName := "test-node" if tt.existingNode != nil { + nodeName = tt.existingNode.Name err := reconciler.Client.Create(ctx, tt.existingNode) assert.NoError(t, err) } req := ctrl.Request{ NamespacedName: types.NamespacedName{ - Name: "test-node", + Name: nodeName, }, } + if tt.name != "Master Node" { + patchesSyncNodeStore := gomonkey.ApplyFunc((*node.NodeService).SyncNodeStore, + func(n *node.NodeService, nodeName string, deleted bool) error { + return nil + }) + defer patchesSyncNodeStore.Reset() + } + result, err := reconciler.Reconcile(ctx, req) if tt.expectedErr {