Skip to content

Commit

Permalink
Merge pull request #111 from weaveworks/fix-k8s-event-sink
Browse files Browse the repository at this point in the history
fix error handling in writing k8s events
  • Loading branch information
Ahmed El-Sayed authored Oct 10, 2022
2 parents a07d233 + 603d622 commit 9ddde49
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions internal/sink/k8s-event/k8s_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ func (f *K8sEventSink) writeWorker(ctx context.Context) error {

func (k *K8sEventSink) write(ctx context.Context, result domain.PolicyValidation) {
event, err := domain.NewK8sEventFromPolicyValidation(result)
if err != nil {
logger.Errorw(
"failed to create event from policy validation",
"error",
err,
"entity_kind", result.Entity.Kind,
"entity_name", result.Entity.Name,
"entity_namespace", result.Entity.Namespace,
"policy", result.Policy.ID,
)
return
}

fluxObject := utils.GetFluxObject(result.Entity.Labels)
if fluxObject != nil {
Expand All @@ -93,18 +105,6 @@ func (k *K8sEventSink) write(ctx context.Context, result domain.PolicyValidation
event.Namespace = fluxObject.GetNamespace()
}

if err != nil {
logger.Errorw(
"failed to create event from policy validation",
"error",
err,
"entity_kind", result.Entity.Kind,
"entity_name", result.Entity.Name,
"entity_namespace", result.Entity.Namespace,
"policy", result.Policy.ID,
)
return
}
event.ReportingController = k.reportingController
event.ReportingInstance = k.reportingInstance
event.Source = v1.EventSource{Component: k.reportingController}
Expand Down

0 comments on commit 9ddde49

Please sign in to comment.