feat(agent): execute reconciliation loop directly at startup

This commit is contained in:
wpetit 2023-03-21 16:05:29 +01:00
parent 1b9914c306
commit 1261beb812
1 changed files with 23 additions and 19 deletions

View File

@ -39,16 +39,13 @@ func (a *Agent) Run(ctx context.Context) error {
ctx = withClient(ctx, client) ctx = withClient(ctx, client)
for { tick := func() {
select {
case <-ticker.C:
logger.Debug(ctx, "registering agent") logger.Debug(ctx, "registering agent")
if err := a.registerAgent(ctx, client, state); err != nil { if err := a.registerAgent(ctx, client, state); err != nil {
logger.Error(ctx, "could not register agent", logger.E(errors.WithStack(err))) logger.Error(ctx, "could not register agent", logger.E(errors.WithStack(err)))
continue return
} }
logger.Debug(ctx, "state before reconciliation", logger.F("state", state)) logger.Debug(ctx, "state before reconciliation", logger.F("state", state))
@ -56,11 +53,18 @@ func (a *Agent) Run(ctx context.Context) error {
if err := a.Reconcile(ctx, state); err != nil { if err := a.Reconcile(ctx, state); err != nil {
logger.Error(ctx, "could not reconcile node with state", logger.E(errors.WithStack(err))) logger.Error(ctx, "could not reconcile node with state", logger.E(errors.WithStack(err)))
continue return
} }
logger.Debug(ctx, "state after reconciliation", logger.F("state", state)) logger.Debug(ctx, "state after reconciliation", logger.F("state", state))
}
tick()
for {
select {
case <-ticker.C:
tick()
case <-ctx.Done(): case <-ctx.Done():
return errors.WithStack(ctx.Err()) return errors.WithStack(ctx.Err())
} }