Skip to content

Commit

Permalink
notifier: remove first update constraint
Browse files Browse the repository at this point in the history
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 <ldelossa@redhat.com>
  • Loading branch information
ldelossa authored and ldelossa committed Sep 28, 2020
1 parent c447bcc commit 7d95067
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 43 deletions.
15 changes: 10 additions & 5 deletions notifier/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
38 changes: 0 additions & 38 deletions notifier/processor_safe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 7d95067

Please sign in to comment.