Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/server/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ func (s *EventServer) getNotificationParams(ctx context.Context, event *eventv1.
return nil, droppedProviders{}, nil
}

// Skip if the provider is a commit status provider but the event doesn't have the commit metadata key.
if isCommitStatusProvider(provider.Spec.Type) && !hasCommitKey(event) {
// Skip if the provider is a commit status provider but the event doesn't have the commit metadata key
// and the event is not a commit status update.
if isCommitStatusProvider(provider.Spec.Type) && !hasCommitKey(event) && !isCommitStatusUpdate(event) {
// Return true on dropped event for a commit status provider
// when the event doesn't have the commit metadata key.
return nil, droppedProviders{commitStatus: true}, nil
Expand Down
45 changes: 32 additions & 13 deletions internal/server/event_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,18 +418,20 @@ func TestGetNotificationParams(t *testing.T) {
testEvent := &eventv1.Event{InvolvedObject: involvedObj}

tests := []struct {
name string
alertNamespace string
alertSummary string
alertEventMetadata map[string]string
providerNamespace string
providerSuspended bool
providerServiceAccount string
secretNamespace string
noCrossNSRefs bool
enableObjLevelWI bool
eventMetadata map[string]string
wantErr bool
name string
alertNamespace string
alertSummary string
alertEventMetadata map[string]string
providerType string
providerNamespace string
providerSuspended bool
providerServiceAccount string
secretNamespace string
noCrossNSRefs bool
enableObjLevelWI bool
eventMetadata map[string]string
wantErr bool
wantDroppedCommitStatus bool
}{
{
name: "event src and alert in diff NS",
Expand Down Expand Up @@ -490,6 +492,19 @@ func TestGetNotificationParams(t *testing.T) {
enableObjLevelWI: true,
wantErr: false,
},
{
name: "commit status provider drops event without commit key",
providerType: apiv1beta3.GitHubProvider,
wantDroppedCommitStatus: true,
},
{
name: "commit status provider does not drop commit status update event without commit key",
providerType: apiv1beta3.GitHubProvider,
eventMetadata: map[string]string{
"kustomize.toolkit.fluxcd.io/" + eventv1.MetaCommitStatusKey: eventv1.MetaCommitStatusUpdateValue,
},
wantErr: true, // proceeds past the guard and fails on notifier creation
},
}

for _, tt := range tests {
Expand All @@ -512,6 +527,9 @@ func TestGetNotificationParams(t *testing.T) {
if tt.alertEventMetadata != nil {
alert.Spec.EventMetadata = tt.alertEventMetadata
}
if tt.providerType != "" {
provider.Spec.Type = tt.providerType
}
if tt.providerNamespace != "" {
provider.Namespace = tt.providerNamespace
}
Expand Down Expand Up @@ -542,8 +560,9 @@ func TestGetNotificationParams(t *testing.T) {
EventRecorder: record.NewFakeRecorder(32),
}

params, _, err := eventServer.getNotificationParams(context.TODO(), event, alert)
params, dropped, err := eventServer.getNotificationParams(context.TODO(), event, alert)
g.Expect(err != nil).To(Equal(tt.wantErr))
g.Expect(dropped.commitStatus).To(Equal(tt.wantDroppedCommitStatus))
if tt.alertSummary != "" {
g.Expect(params.event.Metadata["summary"]).To(Equal(tt.alertSummary))
}
Expand Down