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
7 changes: 4 additions & 3 deletions internal/server/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,10 @@ func (s *EventServer) getNotificationParams(ctx context.Context, event *eventv1.
return nil, droppedProviders{}, nil
}

// Skip if the event has commit status update metadata but the provider is not a git provider.
// Git providers (github, gitlab, etc.) are the ones that set commit statuses.
if !isCommitStatusProvider(provider.Spec.Type) && isCommitStatusUpdate(event) {
// Skip if the event has commit status update metadata but the provider is not a git provider
// or a generic provider. Git providers (github, gitlab, etc.) are the ones that set commit
// statuses. Generic providers forward commit status events as-is to the configured webhook.
if !isCommitStatusProvider(provider.Spec.Type) && !isGenericProvider(provider.Spec.Type) && isCommitStatusUpdate(event) {
return nil, droppedProviders{}, nil
}

Expand Down
33 changes: 30 additions & 3 deletions internal/server/event_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,17 +427,20 @@ func TestGetNotificationParams(t *testing.T) {
providerSuspended bool
providerServiceAccount string
secretNamespace string
secretData map[string][]byte
noCrossNSRefs bool
enableObjLevelWI bool
eventMetadata map[string]string
wantErr bool
wantDroppedCommitStatus bool
wantParams bool
}{
{
name: "event src and alert in diff NS",
alertNamespace: "bar-ns",
providerNamespace: "bar-ns",
secretNamespace: "bar-ns",
wantParams: true,
},
{
name: "event src and alert in diff NS with no cross NS refs",
Expand All @@ -464,6 +467,7 @@ func TestGetNotificationParams(t *testing.T) {
{
name: "alert with summary, no event metadata",
alertSummary: "some summary text",
wantParams: true,
},
{
name: "alert with summary, with event metadata",
Expand All @@ -472,13 +476,15 @@ func TestGetNotificationParams(t *testing.T) {
"foo": "bar",
"summary": "baz",
},
wantParams: true,
},
{
name: "alert with event metadata",
alertEventMetadata: map[string]string{
"aaa": "bbb",
"ccc": "ddd",
},
wantParams: true,
},
{
name: "object level workload identity feature gate disabled",
Expand All @@ -490,7 +496,7 @@ func TestGetNotificationParams(t *testing.T) {
name: "object level workload identity feature gate enabled",
providerServiceAccount: "foo",
enableObjLevelWI: true,
wantErr: false,
wantParams: true,
},
{
name: "commit status provider drops event without commit key",
Expand All @@ -503,7 +509,24 @@ func TestGetNotificationParams(t *testing.T) {
eventMetadata: map[string]string{
"kustomize.toolkit.fluxcd.io/" + eventv1.MetaCommitStatusKey: eventv1.MetaCommitStatusUpdateValue,
},
wantErr: true, // proceeds past the guard and fails on notifier creation
wantErr: true,
},
{
name: "generic provider does not drop commit status update event",
providerType: apiv1beta3.GenericProvider,
eventMetadata: map[string]string{
"kustomize.toolkit.fluxcd.io/" + eventv1.MetaCommitStatusKey: eventv1.MetaCommitStatusUpdateValue,
},
wantParams: true,
},
{
name: "generic-hmac provider does not drop commit status update event",
providerType: apiv1beta3.GenericHMACProvider,
secretData: map[string][]byte{"token": []byte("test-hmac-key")},
eventMetadata: map[string]string{
"kustomize.toolkit.fluxcd.io/" + eventv1.MetaCommitStatusKey: eventv1.MetaCommitStatusUpdateValue,
},
wantParams: true,
},
}

Expand Down Expand Up @@ -538,6 +561,9 @@ func TestGetNotificationParams(t *testing.T) {
if tt.secretNamespace != "" {
secret.Namespace = tt.secretNamespace
}
if tt.secretData != nil {
secret.Data = tt.secretData
}
if tt.eventMetadata != nil {
event.Metadata = tt.eventMetadata
}
Expand All @@ -561,8 +587,9 @@ func TestGetNotificationParams(t *testing.T) {
}

params, dropped, err := eventServer.getNotificationParams(context.TODO(), event, alert)
g.Expect(err != nil).To(Equal(tt.wantErr))
g.Expect(err != nil).To(Equal(tt.wantErr), "unexpected error: %v", err)
g.Expect(dropped.commitStatus).To(Equal(tt.wantDroppedCommitStatus))
g.Expect(params != nil).To(Equal(tt.wantParams), "unexpected params: %v", params)
if tt.alertSummary != "" {
g.Expect(params.event.Metadata["summary"]).To(Equal(tt.alertSummary))
}
Expand Down
5 changes: 5 additions & 0 deletions internal/server/provider_commit_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ func newCommitStatus(ctx context.Context, expr string, notification *eventv1.Eve
return result, nil
}

// isGenericProvider returns true if the provider type is a generic provider.
func isGenericProvider(providerType string) bool {
return providerType == apiv1beta3.GenericProvider || providerType == apiv1beta3.GenericHMACProvider
}

// isCommitStatusProvider returns true if the provider type is a Git provider.
func isCommitStatusProvider(providerType string) bool {
gitProviderTypes := []string{
Expand Down
Loading