From 7d95067f4762ec1aa79879e23c7956eaef8ca4f7 Mon Sep 17 00:00:00 2001 From: ldelossa Date: Wed, 23 Sep 2020 16:58:29 -0400 Subject: [PATCH] notifier: remove first update constraint Claircore will limit the number of returned update diffs now. The check to determine if the first update operation is encountered is no longer needed. Signed-off-by: ldelossa --- notifier/processor.go | 15 ++++++++----- notifier/processor_safe_test.go | 38 --------------------------------- 2 files changed, 10 insertions(+), 43 deletions(-) diff --git a/notifier/processor.go b/notifier/processor.go index 422a79420d..7fc1a2ae9b 100644 --- a/notifier/processor.go +++ b/notifier/processor.go @@ -10,6 +10,7 @@ import ( "github.com/quay/clair/v4/indexer" "github.com/quay/clair/v4/matcher" "github.com/quay/claircore" + "github.com/quay/claircore/libvuln/driver" "github.com/quay/claircore/pkg/distlock" "github.com/rs/zerolog" ) @@ -217,13 +218,17 @@ func (p *Processor) safe(ctx context.Context, e Event) (bool, uuid.UUID) { } uos := all[e.updater] - n := len(uos) - if n < 2 { - log.Info().Msg("encountered first update operation. will not process notifications") - return false, uuid.Nil + + var current driver.UpdateOperation + var prev driver.UpdateOperation + + if len(uos) == 1 { + current = uos[0] + prev.Ref = uuid.Nil + } else { + current, prev = uos[0], uos[1] } - current, prev := uos[0], uos[1] if current.Ref.String() != e.uo.Ref.String() { log.Info().Str("new", current.Ref.String()).Msg("newer update operation is present, will not process notifications") return false, uuid.Nil diff --git a/notifier/processor_safe_test.go b/notifier/processor_safe_test.go index ad5264d839..0fd1e58024 100644 --- a/notifier/processor_safe_test.go +++ b/notifier/processor_safe_test.go @@ -39,7 +39,6 @@ var ( func TestProcessorSafe(t *testing.T) { t.Run("UnsafeDuplications", testUnsafeDuplications) t.Run("UnsafeStaleUOID", testUnsafeStaleUOID) - t.Run("UnSafeFirstUpdate", testUnsafeFirstUpdate) t.Run("UnsafeMatcherErr", testUnsafeMatcherErr) t.Run("UnsafeStoreErr", testUnsafeStoreErr) t.Run("Safe", testSafe) @@ -131,43 +130,6 @@ func testUnsafeMatcherErr(t *testing.T) { } } -// testSafeFirstUpdate confirms notifications will not be created if no previous -// operation can be used as a base in the diff. -func testUnsafeFirstUpdate(t *testing.T) { - ctx := context.TODO() - sm := &MockStore{ - ReceiptByUOID_: func(ctx context.Context, id uuid.UUID) (Receipt, error) { - return Receipt{}, clairerror.ErrNoReceipt{} - }, - } - mm := &matcher.Mock{ - UpdateOperations_: func(context.Context, ...string) (map[string][]driver.UpdateOperation, error) { - // reslice to have only one UOID - latest := processorUpdateOps[testUpdater][:1] - uo := map[string][]driver.UpdateOperation{ - testUpdater: latest, - } - return uo, nil - }, - } - - p := Processor{ - store: sm, - matcher: mm, - } - - e := Event{ - updater: testUpdater, - uo: processorUpdateOps[testUpdater][1], - } - - b, _ := p.safe(ctx, e) - if b { - t.Fatalf("got: %v, want: %v", b, false) - } - -} - // testSafeStaleUOID confirms the guard against creating stale notifications // works correctly. func testUnsafeStaleUOID(t *testing.T) {