Skip to content

Commit e801cf9

Browse files
authored
Merge pull request #1290 from fluxcd/fix-1289
Fix generic providers not forwarding commit status events
2 parents 7066af0 + c614f27 commit e801cf9

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

internal/server/event_handlers.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,9 +316,10 @@ func (s *EventServer) getNotificationParams(ctx context.Context, event *eventv1.
316316
return nil, droppedProviders{}, nil
317317
}
318318

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

internal/server/event_handlers_test.go

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,20 @@ func TestGetNotificationParams(t *testing.T) {
427427
providerSuspended bool
428428
providerServiceAccount string
429429
secretNamespace string
430+
secretData map[string][]byte
430431
noCrossNSRefs bool
431432
enableObjLevelWI bool
432433
eventMetadata map[string]string
433434
wantErr bool
434435
wantDroppedCommitStatus bool
436+
wantParams bool
435437
}{
436438
{
437439
name: "event src and alert in diff NS",
438440
alertNamespace: "bar-ns",
439441
providerNamespace: "bar-ns",
440442
secretNamespace: "bar-ns",
443+
wantParams: true,
441444
},
442445
{
443446
name: "event src and alert in diff NS with no cross NS refs",
@@ -464,6 +467,7 @@ func TestGetNotificationParams(t *testing.T) {
464467
{
465468
name: "alert with summary, no event metadata",
466469
alertSummary: "some summary text",
470+
wantParams: true,
467471
},
468472
{
469473
name: "alert with summary, with event metadata",
@@ -472,13 +476,15 @@ func TestGetNotificationParams(t *testing.T) {
472476
"foo": "bar",
473477
"summary": "baz",
474478
},
479+
wantParams: true,
475480
},
476481
{
477482
name: "alert with event metadata",
478483
alertEventMetadata: map[string]string{
479484
"aaa": "bbb",
480485
"ccc": "ddd",
481486
},
487+
wantParams: true,
482488
},
483489
{
484490
name: "object level workload identity feature gate disabled",
@@ -490,7 +496,7 @@ func TestGetNotificationParams(t *testing.T) {
490496
name: "object level workload identity feature gate enabled",
491497
providerServiceAccount: "foo",
492498
enableObjLevelWI: true,
493-
wantErr: false,
499+
wantParams: true,
494500
},
495501
{
496502
name: "commit status provider drops event without commit key",
@@ -503,7 +509,24 @@ func TestGetNotificationParams(t *testing.T) {
503509
eventMetadata: map[string]string{
504510
"kustomize.toolkit.fluxcd.io/" + eventv1.MetaCommitStatusKey: eventv1.MetaCommitStatusUpdateValue,
505511
},
506-
wantErr: true, // proceeds past the guard and fails on notifier creation
512+
wantErr: true,
513+
},
514+
{
515+
name: "generic provider does not drop commit status update event",
516+
providerType: apiv1beta3.GenericProvider,
517+
eventMetadata: map[string]string{
518+
"kustomize.toolkit.fluxcd.io/" + eventv1.MetaCommitStatusKey: eventv1.MetaCommitStatusUpdateValue,
519+
},
520+
wantParams: true,
521+
},
522+
{
523+
name: "generic-hmac provider does not drop commit status update event",
524+
providerType: apiv1beta3.GenericHMACProvider,
525+
secretData: map[string][]byte{"token": []byte("test-hmac-key")},
526+
eventMetadata: map[string]string{
527+
"kustomize.toolkit.fluxcd.io/" + eventv1.MetaCommitStatusKey: eventv1.MetaCommitStatusUpdateValue,
528+
},
529+
wantParams: true,
507530
},
508531
}
509532

@@ -538,6 +561,9 @@ func TestGetNotificationParams(t *testing.T) {
538561
if tt.secretNamespace != "" {
539562
secret.Namespace = tt.secretNamespace
540563
}
564+
if tt.secretData != nil {
565+
secret.Data = tt.secretData
566+
}
541567
if tt.eventMetadata != nil {
542568
event.Metadata = tt.eventMetadata
543569
}
@@ -561,8 +587,9 @@ func TestGetNotificationParams(t *testing.T) {
561587
}
562588

563589
params, dropped, err := eventServer.getNotificationParams(context.TODO(), event, alert)
564-
g.Expect(err != nil).To(Equal(tt.wantErr))
590+
g.Expect(err != nil).To(Equal(tt.wantErr), "unexpected error: %v", err)
565591
g.Expect(dropped.commitStatus).To(Equal(tt.wantDroppedCommitStatus))
592+
g.Expect(params != nil).To(Equal(tt.wantParams), "unexpected params: %v", params)
566593
if tt.alertSummary != "" {
567594
g.Expect(params.event.Metadata["summary"]).To(Equal(tt.alertSummary))
568595
}

internal/server/provider_commit_status.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ func newCommitStatus(ctx context.Context, expr string, notification *eventv1.Eve
8989
return result, nil
9090
}
9191

92+
// isGenericProvider returns true if the provider type is a generic provider.
93+
func isGenericProvider(providerType string) bool {
94+
return providerType == apiv1beta3.GenericProvider || providerType == apiv1beta3.GenericHMACProvider
95+
}
96+
9297
// isCommitStatusProvider returns true if the provider type is a Git provider.
9398
func isCommitStatusProvider(providerType string) bool {
9499
gitProviderTypes := []string{

0 commit comments

Comments
 (0)