Skip to content

Commit

Permalink
[agent] fix agent state updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Frostman committed May 7, 2024
1 parent b5d04d7 commit c73af6e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func (svc *Service) Run(ctx context.Context, getClient func() (*gnmi.Client, err
if st := svc.reg.GetSwitchState(); st != nil {
agent.Status.State = *st
}
agent.Status.LastHeartbeat = metav1.Time{Time: time.Now()}

err = kube.Status().Update(ctx, agent) // TODO maybe use patch for such status updates?
if err != nil {
Expand Down Expand Up @@ -201,7 +202,9 @@ func (svc *Service) Run(ctx context.Context, getClient func() (*gnmi.Client, err
if err := svc.processor.UpdateSwitchState(ctx, agent, svc.reg); err != nil {
return errors.Wrapf(err, "failed to update switch state")
}

if st := svc.reg.GetSwitchState(); st != nil {
agent.Status.State = *st
}
agent.Status.LastHeartbeat = metav1.Time{Time: time.Now()}

err = kube.Status().Update(ctx, agent)
Expand Down Expand Up @@ -299,6 +302,7 @@ func (svc *Service) processAgent(ctx context.Context, agent *agentapi.Agent, rea
if st := svc.reg.GetSwitchState(); st != nil {
agent.Status.State = *st
}
agent.Status.LastHeartbeat = metav1.Time{Time: time.Now()}
}

desired, err := svc.processor.PlanDesiredState(ctx, agent)
Expand Down

0 comments on commit c73af6e

Please sign in to comment.