From e6c3b15f2af032ac1ed09daffe7439f37900b330 Mon Sep 17 00:00:00 2001 From: wuhuizuo Date: Wed, 20 Dec 2023 16:52:29 +0800 Subject: [PATCH] fix(cloudevents): fix notify conditions Signed-off-by: wuhuizuo --- .../events/custom/tekton/handler_pipelinerun.go | 15 +++++++++++---- .../pkg/events/custom/tekton/handler_taskrun.go | 9 +++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/cloudevents-server/pkg/events/custom/tekton/handler_pipelinerun.go b/cloudevents-server/pkg/events/custom/tekton/handler_pipelinerun.go index f8d8665..11ed1b6 100644 --- a/cloudevents-server/pkg/events/custom/tekton/handler_pipelinerun.go +++ b/cloudevents-server/pkg/events/custom/tekton/handler_pipelinerun.go @@ -19,10 +19,10 @@ type pipelineRunHandler struct { func (h *pipelineRunHandler) SupportEventTypes() []string { return []string{ string(tektoncloudevent.PipelineRunFailedEventV1), - // string(tektoncloudevent.PipelineRunRunningEventV1), + string(tektoncloudevent.PipelineRunRunningEventV1), string(tektoncloudevent.PipelineRunStartedEventV1), string(tektoncloudevent.PipelineRunSuccessfulEventV1), - // string(tektoncloudevent.PipelineRunUnknownEventV1), + string(tektoncloudevent.PipelineRunUnknownEventV1), } } @@ -32,8 +32,15 @@ func (h *pipelineRunHandler) Handle(event cloudevents.Event) cloudevents.Result return cloudevents.NewHTTPResult(http.StatusBadRequest, err.Error()) } - log.Debug().Str("ce-type", event.Type()).Msg("skip notifing for the event type.") - return cloudevents.ResultACK + switch tektoncloudevent.TektonEventType(event.Type()) { + case tektoncloudevent.PipelineRunStartedEventV1, + tektoncloudevent.PipelineRunFailedEventV1, + tektoncloudevent.PipelineRunSuccessfulEventV1: + return h.notifyRunStatus(event) + default: + log.Debug().Str("ce-type", event.Type()).Msg("skip notifing for the event type.") + return cloudevents.ResultACK + } } func (h *pipelineRunHandler) notifyRunStatus(event cloudevents.Event) cloudevents.Result { diff --git a/cloudevents-server/pkg/events/custom/tekton/handler_taskrun.go b/cloudevents-server/pkg/events/custom/tekton/handler_taskrun.go index 186bc64..ebd279a 100644 --- a/cloudevents-server/pkg/events/custom/tekton/handler_taskrun.go +++ b/cloudevents-server/pkg/events/custom/tekton/handler_taskrun.go @@ -32,8 +32,13 @@ func (h *taskRunHandler) Handle(event cloudevents.Event) cloudevents.Result { return cloudevents.NewHTTPResult(http.StatusBadRequest, err.Error()) } - log.Debug().Str("ce-type", event.Type()).Msg("skip notifing for the event type.") - return cloudevents.ResultACK + switch event.Type() { + case string(tektoncloudevent.TaskRunFailedEventV1): + return h.notifyRunStatus(event) + default: + log.Debug().Str("ce-type", event.Type()).Msg("skip notifing for the event type.") + return cloudevents.ResultACK + } } func (h *taskRunHandler) notifyRunStatus(event cloudevents.Event) cloudevents.Result {