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()) }