feat(agent): execute reconciliation loop directly at startup
This commit is contained in:
parent
1b9914c306
commit
1261beb812
|
@ -39,28 +39,32 @@ func (a *Agent) Run(ctx context.Context) error {
|
||||||
|
|
||||||
ctx = withClient(ctx, client)
|
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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
tick()
|
||||||
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))
|
|
||||||
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return errors.WithStack(ctx.Err())
|
return errors.WithStack(ctx.Err())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue