Skip to content

Commit

Permalink
ignore events with no OperationState (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ATGardner authored Dec 16, 2021
1 parent 74e32cb commit 06fae41
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions server/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,11 @@ func (s *Server) streamApplicationEvents(
return fmt.Errorf("failed to get application event: %w", err)
}

if appEvent == nil {
// event did not have an OperationState - skip all events
return nil
}

if err := stream.Send(appEvent); err != nil {
return fmt.Errorf("failed to send event for resource %s/%s: %w", a.Namespace, a.Name, err)
}
Expand Down Expand Up @@ -1078,16 +1083,11 @@ func getResourceEventPayload(
AppName: a.Name,
AppLabels: a.Labels,
SyncStatus: string(rs.Status),
SyncStartedAt: a.Status.OperationState.StartedAt,
SyncFinishedAt: a.Status.OperationState.FinishedAt,
}

if a.Status.OperationState != nil {
source.SyncStartedAt = a.Status.OperationState.StartedAt
source.SyncFinishedAt = a.Status.OperationState.FinishedAt
errors = append(errors, parseResourceSyncResultErrors(rs, a.Status.OperationState)...)
} else {
source.SyncStartedAt = metav1.Now() // new sync operation
}

errors = append(errors, parseResourceSyncResultErrors(rs, a.Status.OperationState)...)
if rs.Health != nil {
source.HealthStatus = (*string)(&rs.Health.Status)
source.HealthMessage = &rs.Health.Message
Expand Down Expand Up @@ -1164,6 +1164,11 @@ func parseAggregativeHealthErrors(rs *appv1.ResourceStatus, apptree *appv1.Appli
}

func (s *Server) getApplicationEventPayload(ctx context.Context, a *appv1.Application, es *events.EventSource) (*events.Event, error) {
// skip all events if there is no OperationState
if a.Status.OperationState == nil {
return nil, nil
}

obj := appv1.Application{}
a.DeepCopyInto(&obj)

Expand Down Expand Up @@ -1199,6 +1204,7 @@ func (s *Server) getApplicationEventPayload(ctx context.Context, a *appv1.Applic
actualManifest = "" // mark as deleted
}

hs := string(a.Status.Health.Status)
source := &events.ObjectSource{
DesiredManifest: "",
GitManifest: "",
Expand All @@ -1211,18 +1217,13 @@ func (s *Server) getApplicationEventPayload(ctx context.Context, a *appv1.Applic
AppName: "",
AppLabels: map[string]string{},
SyncStatus: string(a.Status.Sync.Status),
}

if a.Status.OperationState != nil {
source.SyncStartedAt = a.Status.OperationState.StartedAt
source.SyncFinishedAt = a.Status.OperationState.FinishedAt
hs := string(a.Status.Health.Status)
source.HealthStatus = &hs
source.HealthMessage = &a.Status.Health.Message
SyncStartedAt: a.Status.OperationState.StartedAt,
SyncFinishedAt: a.Status.OperationState.FinishedAt,
HealthStatus: &hs,
HealthMessage: &a.Status.Health.Message,
}

errs := []*events.ObjectError{}

for _, cnd := range a.Status.Conditions {
if !strings.Contains(strings.ToLower(cnd.Type), "error") {
continue
Expand Down

0 comments on commit 06fae41

Please sign in to comment.