From 1261beb81292380574804da29b6625a0ef9cef05 Mon Sep 17 00:00:00 2001 From: William Petit Date: Tue, 21 Mar 2023 16:05:29 +0100 Subject: [PATCH] feat(agent): execute reconciliation loop directly at startup --- internal/agent/agent.go | 42 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 676cd81..a9a7d87 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -39,28 +39,32 @@ func (a *Agent) Run(ctx context.Context) error { ctx = withClient(ctx, client) + tick := func() { + logger.Debug(ctx, "registering agent") + + if err := a.registerAgent(ctx, client, state); err != nil { + logger.Error(ctx, "could not register agent", logger.E(errors.WithStack(err))) + + return + } + + logger.Debug(ctx, "state before reconciliation", logger.F("state", state)) + + if err := a.Reconcile(ctx, state); err != nil { + logger.Error(ctx, "could not reconcile node with state", logger.E(errors.WithStack(err))) + + return + } + + logger.Debug(ctx, "state after reconciliation", logger.F("state", state)) + } + + tick() + for { select { case <-ticker.C: - - logger.Debug(ctx, "registering agent") - - if err := a.registerAgent(ctx, client, state); err != nil { - logger.Error(ctx, "could not register agent", logger.E(errors.WithStack(err))) - - continue - } - - logger.Debug(ctx, "state before reconciliation", logger.F("state", state)) - - if err := a.Reconcile(ctx, state); err != nil { - logger.Error(ctx, "could not reconcile node with state", logger.E(errors.WithStack(err))) - - continue - } - - logger.Debug(ctx, "state after reconciliation", logger.F("state", state)) - + tick() case <-ctx.Done(): return errors.WithStack(ctx.Err()) }