Skip to content

Commit 055a74c

Browse files
committed
Rename resolver/cache.Operator to Entry.
This type is a data object representing a resolver cache entry. It doesn't have a particular connection to operators other than residing where it resides. This name change should clarify what, exactly, the type represents. Signed-off-by: Ben Luddy <[email protected]>
1 parent 11f1d0c commit 055a74c

12 files changed

+161
-161
lines changed

Diff for: pkg/controller/registry/resolver/cache/cache.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ func (c *NamespacedOperatorCache) Catalog(k SourceKey) OperatorFinder {
261261
return EmptyOperatorFinder{}
262262
}
263263

264-
func (c *NamespacedOperatorCache) FindPreferred(preferred *SourceKey, preferredNamespace string, p ...OperatorPredicate) []*Operator {
265-
var result []*Operator
264+
func (c *NamespacedOperatorCache) FindPreferred(preferred *SourceKey, preferredNamespace string, p ...OperatorPredicate) []*Entry {
265+
var result []*Entry
266266
if preferred != nil && preferred.Empty() {
267267
preferred = nil
268268
}
@@ -291,12 +291,12 @@ func (c *NamespacedOperatorCache) WithExistingOperators(snapshot *Snapshot, name
291291
return o
292292
}
293293

294-
func (c *NamespacedOperatorCache) Find(p ...OperatorPredicate) []*Operator {
294+
func (c *NamespacedOperatorCache) Find(p ...OperatorPredicate) []*Entry {
295295
return c.FindPreferred(nil, "", p...)
296296
}
297297

298298
type Snapshot struct {
299-
Entries []*Operator
299+
Entries []*Entry
300300
}
301301

302302
var _ Source = &Snapshot{}
@@ -402,7 +402,7 @@ func (s sortableSnapshots) Swap(i, j int) {
402402
s.snapshots[i], s.snapshots[j] = s.snapshots[j], s.snapshots[i]
403403
}
404404

405-
func (s *snapshotHeader) Find(p ...OperatorPredicate) []*Operator {
405+
func (s *snapshotHeader) Find(p ...OperatorPredicate) []*Entry {
406406
s.m.RLock()
407407
defer s.m.RUnlock()
408408
if s.snapshot == nil {
@@ -412,39 +412,39 @@ func (s *snapshotHeader) Find(p ...OperatorPredicate) []*Operator {
412412
}
413413

414414
type OperatorFinder interface {
415-
Find(...OperatorPredicate) []*Operator
415+
Find(...OperatorPredicate) []*Entry
416416
}
417417

418418
type MultiCatalogOperatorFinder interface {
419419
Catalog(SourceKey) OperatorFinder
420-
FindPreferred(preferred *SourceKey, preferredNamespace string, predicates ...OperatorPredicate) []*Operator
420+
FindPreferred(preferred *SourceKey, preferredNamespace string, predicates ...OperatorPredicate) []*Entry
421421
WithExistingOperators(snapshot *Snapshot, namespace string) MultiCatalogOperatorFinder
422422
Error() error
423423
OperatorFinder
424424
}
425425

426426
type EmptyOperatorFinder struct{}
427427

428-
func (f EmptyOperatorFinder) Find(...OperatorPredicate) []*Operator {
428+
func (f EmptyOperatorFinder) Find(...OperatorPredicate) []*Entry {
429429
return nil
430430
}
431431

432-
func AtLeast(n int, operators []*Operator) ([]*Operator, error) {
432+
func AtLeast(n int, operators []*Entry) ([]*Entry, error) {
433433
if len(operators) < n {
434434
return nil, fmt.Errorf("expected at least %d operator(s), got %d", n, len(operators))
435435
}
436436
return operators, nil
437437
}
438438

439-
func ExactlyOne(operators []*Operator) (*Operator, error) {
439+
func ExactlyOne(operators []*Entry) (*Entry, error) {
440440
if len(operators) != 1 {
441441
return nil, fmt.Errorf("expected exactly one operator, got %d", len(operators))
442442
}
443443
return operators[0], nil
444444
}
445445

446-
func Filter(operators []*Operator, p ...OperatorPredicate) []*Operator {
447-
var result []*Operator
446+
func Filter(operators []*Entry, p ...OperatorPredicate) []*Entry {
447+
var result []*Entry
448448
for _, o := range operators {
449449
if Matches(o, p...) {
450450
result = append(result, o)
@@ -453,6 +453,6 @@ func Filter(operators []*Operator, p ...OperatorPredicate) []*Operator {
453453
return result
454454
}
455455

456-
func Matches(o *Operator, p ...OperatorPredicate) bool {
456+
func Matches(o *Entry, p ...OperatorPredicate) bool {
457457
return And(p...).Test(o)
458458
}

Diff for: pkg/controller/registry/resolver/cache/cache_test.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestOperatorCacheConcurrency(t *testing.T) {
2525
key := SourceKey{Namespace: strconv.Itoa(i), Name: strconv.Itoa(j)}
2626
keys = append(keys, key)
2727
sp[key] = &Snapshot{
28-
Entries: []*Operator{
28+
Entries: []*Entry{
2929
{Name: fmt.Sprintf("%s/%s", key.Namespace, key.Name)},
3030
},
3131
}
@@ -71,14 +71,14 @@ func TestOperatorCacheExpiration(t *testing.T) {
7171
c.ttl = 0 // instantly stale
7272

7373
ssp[key] = &Snapshot{
74-
Entries: []*Operator{
74+
Entries: []*Entry{
7575
{Name: "v1"},
7676
},
7777
}
7878
require.Len(t, c.Namespaced("dummynamespace").Catalog(key).Find(CSVNamePredicate("v1")), 1)
7979

8080
ssp[key] = &Snapshot{
81-
Entries: []*Operator{
81+
Entries: []*Entry{
8282
{Name: "v2"},
8383
},
8484
}
@@ -91,14 +91,14 @@ func TestOperatorCacheReuse(t *testing.T) {
9191
c := New(ssp)
9292

9393
ssp[key] = &Snapshot{
94-
Entries: []*Operator{
94+
Entries: []*Entry{
9595
{Name: "v1"},
9696
},
9797
}
9898
require.Len(t, c.Namespaced("dummynamespace").Catalog(key).Find(CSVNamePredicate("v1")), 1)
9999

100100
ssp[key] = &Snapshot{
101-
Entries: []*Operator{
101+
Entries: []*Entry{
102102
{Name: "v2"},
103103
},
104104
}
@@ -173,17 +173,17 @@ func TestCatalogSnapshotFind(t *testing.T) {
173173
type tc struct {
174174
Name string
175175
Predicate OperatorPredicate
176-
Operators []*Operator
177-
Expected []*Operator
176+
Operators []*Entry
177+
Expected []*Entry
178178
}
179179

180180
for _, tt := range []tc{
181181
{
182182
Name: "nothing satisfies predicate",
183-
Predicate: OperatorPredicateTestFunc(func(*Operator) bool {
183+
Predicate: OperatorPredicateTestFunc(func(*Entry) bool {
184184
return false
185185
}),
186-
Operators: []*Operator{
186+
Operators: []*Entry{
187187
{Name: "a"},
188188
{Name: "b"},
189189
{Name: "c"},
@@ -192,39 +192,39 @@ func TestCatalogSnapshotFind(t *testing.T) {
192192
},
193193
{
194194
Name: "no operators in snapshot",
195-
Predicate: OperatorPredicateTestFunc(func(*Operator) bool {
195+
Predicate: OperatorPredicateTestFunc(func(*Entry) bool {
196196
return true
197197
}),
198198
Operators: nil,
199199
Expected: nil,
200200
},
201201
{
202202
Name: "everything satisfies predicate",
203-
Predicate: OperatorPredicateTestFunc(func(*Operator) bool {
203+
Predicate: OperatorPredicateTestFunc(func(*Entry) bool {
204204
return true
205205
}),
206-
Operators: []*Operator{
206+
Operators: []*Entry{
207207
{Name: "a"},
208208
{Name: "b"},
209209
{Name: "c"},
210210
},
211-
Expected: []*Operator{
211+
Expected: []*Entry{
212212
{Name: "a"},
213213
{Name: "b"},
214214
{Name: "c"},
215215
},
216216
},
217217
{
218218
Name: "some satisfy predicate",
219-
Predicate: OperatorPredicateTestFunc(func(o *Operator) bool {
219+
Predicate: OperatorPredicateTestFunc(func(o *Entry) bool {
220220
return o.Name != "a"
221221
}),
222-
Operators: []*Operator{
222+
Operators: []*Entry{
223223
{Name: "a"},
224224
{Name: "b"},
225225
{Name: "c"},
226226
},
227-
Expected: []*Operator{
227+
Expected: []*Entry{
228228
{Name: "b"},
229229
{Name: "c"},
230230
},

Diff for: pkg/controller/registry/resolver/cache/operators.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,21 @@ func (s APISet) StripPlural() APISet {
135135
return set
136136
}
137137

138-
type APIOwnerSet map[opregistry.APIKey]*Operator
138+
type APIOwnerSet map[opregistry.APIKey]*Entry
139139

140140
func EmptyAPIOwnerSet() APIOwnerSet {
141-
return map[opregistry.APIKey]*Operator{}
141+
return map[opregistry.APIKey]*Entry{}
142142
}
143143

144-
type OperatorSet map[string]*Operator
144+
type OperatorSet map[string]*Entry
145145

146146
func EmptyOperatorSet() OperatorSet {
147-
return map[string]*Operator{}
147+
return map[string]*Entry{}
148148
}
149149

150150
// Snapshot returns a new set, pointing to the same values
151151
func (o OperatorSet) Snapshot() OperatorSet {
152-
out := make(map[string]*Operator)
152+
out := make(map[string]*Entry)
153153
for key, val := range o {
154154
out[key] = val
155155
}
@@ -204,7 +204,7 @@ func (i *OperatorSourceInfo) String() string {
204204
var NoCatalog = SourceKey{Name: "", Namespace: ""}
205205
var ExistingOperator = OperatorSourceInfo{Package: "", Channel: "", StartingCSV: "", Catalog: NoCatalog, DefaultChannel: false}
206206

207-
type Operator struct {
207+
type Entry struct {
208208
Name string
209209
Replaces string
210210
Skips []string
@@ -223,14 +223,14 @@ type Operator struct {
223223
Bundle *api.Bundle
224224
}
225225

226-
func (o *Operator) Package() string {
226+
func (o *Entry) Package() string {
227227
if si := o.SourceInfo; si != nil {
228228
return si.Package
229229
}
230230
return ""
231231
}
232232

233-
func (o *Operator) Channel() string {
233+
func (o *Entry) Channel() string {
234234
if si := o.SourceInfo; si != nil {
235235
return si.Channel
236236
}

Diff for: pkg/controller/registry/resolver/cache/operators_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -728,15 +728,15 @@ func TestAPIMultiOwnerSet_PopAPIKey(t *testing.T) {
728728
{
729729
name: "OneApi/OneOwner",
730730
s: map[opregistry.APIKey]OperatorSet{
731-
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Operator{
731+
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Entry{
732732
"owner1": {Name: "op1"},
733733
},
734734
},
735735
},
736736
{
737737
name: "OneApi/MultiOwner",
738738
s: map[opregistry.APIKey]OperatorSet{
739-
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Operator{
739+
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Entry{
740740
"owner1": {Name: "op1"},
741741
"owner2": {Name: "op2"},
742742
},
@@ -745,11 +745,11 @@ func TestAPIMultiOwnerSet_PopAPIKey(t *testing.T) {
745745
{
746746
name: "MultipleApi/MultiOwner",
747747
s: map[opregistry.APIKey]OperatorSet{
748-
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Operator{
748+
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Entry{
749749
"owner1": {Name: "op1"},
750750
"owner2": {Name: "op2"},
751751
},
752-
{Group: "g2", Version: "v2", Kind: "k2", Plural: "p2"}: map[string]*Operator{
752+
{Group: "g2", Version: "v2", Kind: "k2", Plural: "p2"}: map[string]*Entry{
753753
"owner1": {Name: "op1"},
754754
"owner2": {Name: "op2"},
755755
},
@@ -788,40 +788,40 @@ func TestAPIMultiOwnerSet_PopAPIRequirers(t *testing.T) {
788788
{
789789
name: "OneApi/OneOwner",
790790
s: map[opregistry.APIKey]OperatorSet{
791-
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Operator{
791+
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Entry{
792792
"owner1": {Name: "op1"},
793793
},
794794
},
795-
want: map[string]*Operator{
795+
want: map[string]*Entry{
796796
"owner1": {Name: "op1"},
797797
},
798798
},
799799
{
800800
name: "OneApi/MultiOwner",
801801
s: map[opregistry.APIKey]OperatorSet{
802-
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Operator{
802+
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Entry{
803803
"owner1": {Name: "op1"},
804804
"owner2": {Name: "op2"},
805805
},
806806
},
807-
want: map[string]*Operator{
807+
want: map[string]*Entry{
808808
"owner1": {Name: "op1"},
809809
"owner2": {Name: "op2"},
810810
},
811811
},
812812
{
813813
name: "MultipleApi/MultiOwner",
814814
s: map[opregistry.APIKey]OperatorSet{
815-
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Operator{
815+
{Group: "g", Version: "v", Kind: "k", Plural: "p"}: map[string]*Entry{
816816
"owner1": {Name: "op1"},
817817
"owner2": {Name: "op2"},
818818
},
819-
{Group: "g2", Version: "v2", Kind: "k2", Plural: "p2"}: map[string]*Operator{
819+
{Group: "g2", Version: "v2", Kind: "k2", Plural: "p2"}: map[string]*Entry{
820820
"owner1": {Name: "op1"},
821821
"owner2": {Name: "op2"},
822822
},
823823
},
824-
want: map[string]*Operator{
824+
want: map[string]*Entry{
825825
"owner1": {Name: "op1"},
826826
"owner2": {Name: "op2"},
827827
},

0 commit comments

Comments
 (0)