diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 1a404d76..b8ff0ba0 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -476,7 +476,7 @@ }, { "ImportPath": "k8s.io/api", - "Rev": "e32abb16c84d" + "Rev": "c2af72098886" }, { "ImportPath": "k8s.io/apimachinery", diff --git a/go.mod b/go.mod index 2036d570..1fbee9e3 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba - k8s.io/api v0.0.0-20210408231833-e32abb16c84d + k8s.io/api v0.0.0-20210409072620-c2af72098886 k8s.io/apimachinery v0.0.0-20210408225951-74cf9d365d5e k8s.io/klog/v2 v2.8.0 k8s.io/utils v0.0.0-20201110183641-67b214c5f920 @@ -36,6 +36,6 @@ require ( ) replace ( - k8s.io/api => k8s.io/api v0.0.0-20210408231833-e32abb16c84d + k8s.io/api => k8s.io/api v0.0.0-20210409072620-c2af72098886 k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20210408225951-74cf9d365d5e ) diff --git a/go.sum b/go.sum index 004feee5..fcb3462f 100644 --- a/go.sum +++ b/go.sum @@ -431,7 +431,7 @@ honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -k8s.io/api v0.0.0-20210408231833-e32abb16c84d/go.mod h1:qWBQaP6/XkVq3wtewQmaEEUxdGD1f/HstASE9fJtjns= +k8s.io/api v0.0.0-20210409072620-c2af72098886/go.mod h1:qWBQaP6/XkVq3wtewQmaEEUxdGD1f/HstASE9fJtjns= k8s.io/apimachinery v0.0.0-20210408225951-74cf9d365d5e/go.mod h1:jbreFvJo3ov9rj7eWT7+sYiRx+qZuCYXwWT1bcDswPY= k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= diff --git a/tools/cache/controller_test.go b/tools/cache/controller_test.go index 4c071281..1603b9d7 100644 --- a/tools/cache/controller_test.go +++ b/tools/cache/controller_test.go @@ -44,7 +44,10 @@ func Example() { // This will hold incoming changes. Note how we pass downstream in as a // KeyLister, that way resync operations will result in the correct set // of update/delete deltas. - fifo := NewDeltaFIFO(MetaNamespaceKeyFunc, downstream) + fifo := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: MetaNamespaceKeyFunc, + KnownObjects: downstream, + }) // Let's do threadsafe output to get predictable test results. deletionCounter := make(chan string, 1000) diff --git a/tools/cache/delta_fifo_test.go b/tools/cache/delta_fifo_test.go index 9e12341d..ec4e4ff2 100644 --- a/tools/cache/delta_fifo_test.go +++ b/tools/cache/delta_fifo_test.go @@ -56,7 +56,7 @@ func (kl literalListerGetter) GetByKey(key string) (interface{}, bool, error) { } func TestDeltaFIFO_basic(t *testing.T) { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) const amount = 500 go func() { for i := 0; i < amount; i++ { @@ -100,9 +100,12 @@ func TestDeltaFIFO_replaceWithDeleteDeltaIn(t *testing.T) { oldObj := mkFifoObj("foo", 1) newObj := mkFifoObj("foo", 2) - f := NewDeltaFIFO(testFifoObjectKeyFunc, literalListerGetter(func() []testFifoObject { - return []testFifoObject{oldObj} - })) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { + return []testFifoObject{oldObj} + }), + }) f.Delete(oldObj) f.Replace([]interface{}{newObj}, "") @@ -118,7 +121,7 @@ func TestDeltaFIFO_replaceWithDeleteDeltaIn(t *testing.T) { } func TestDeltaFIFO_requeueOnPop(t *testing.T) { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) f.Add(mkFifoObj("foo", 10)) _, err := f.Pop(func(obj interface{}) error { @@ -162,7 +165,7 @@ func TestDeltaFIFO_requeueOnPop(t *testing.T) { } func TestDeltaFIFO_addUpdate(t *testing.T) { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) f.Add(mkFifoObj("foo", 10)) f.Update(mkFifoObj("foo", 12)) f.Delete(mkFifoObj("foo", 15)) @@ -200,7 +203,7 @@ func TestDeltaFIFO_addUpdate(t *testing.T) { } func TestDeltaFIFO_enqueueingNoLister(t *testing.T) { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) f.Add(mkFifoObj("foo", 10)) f.Update(mkFifoObj("bar", 15)) f.Add(mkFifoObj("qux", 17)) @@ -221,12 +224,12 @@ func TestDeltaFIFO_enqueueingNoLister(t *testing.T) { } func TestDeltaFIFO_enqueueingWithLister(t *testing.T) { - f := NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)} }), - ) + }) f.Add(mkFifoObj("foo", 10)) f.Update(mkFifoObj("bar", 15)) @@ -245,7 +248,7 @@ func TestDeltaFIFO_enqueueingWithLister(t *testing.T) { } func TestDeltaFIFO_addReplace(t *testing.T) { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) f.Add(mkFifoObj("foo", 10)) f.Replace([]interface{}{mkFifoObj("foo", 15)}, "0") got := make(chan testFifoObject, 2) @@ -271,12 +274,12 @@ func TestDeltaFIFO_addReplace(t *testing.T) { } func TestDeltaFIFO_ResyncNonExisting(t *testing.T) { - f := NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{mkFifoObj("foo", 5)} }), - ) + }) f.Delete(mkFifoObj("foo", 10)) f.Resync() @@ -290,12 +293,12 @@ func TestDeltaFIFO_ResyncNonExisting(t *testing.T) { } func TestDeltaFIFO_Resync(t *testing.T) { - f := NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{mkFifoObj("foo", 5)} }), - ) + }) f.Resync() deltas := f.items["foo"] @@ -308,12 +311,12 @@ func TestDeltaFIFO_Resync(t *testing.T) { } func TestDeltaFIFO_DeleteExistingNonPropagated(t *testing.T) { - f := NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{} }), - ) + }) f.Add(mkFifoObj("foo", 5)) f.Delete(mkFifoObj("foo", 6)) @@ -331,12 +334,12 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) { // promise about how their deletes are ordered. // Try it with a pre-existing Delete - f := NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)} }), - ) + }) f.Delete(mkFifoObj("baz", 10)) f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0") @@ -356,12 +359,12 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) { } // Now try starting with an Add instead of a Delete - f = NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f = NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)} }), - ) + }) f.Add(mkFifoObj("baz", 10)) f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0") @@ -382,10 +385,7 @@ func TestDeltaFIFO_ReplaceMakesDeletions(t *testing.T) { } // Now try starting without an explicit KeyListerGetter - f = NewDeltaFIFO( - testFifoObjectKeyFunc, - nil, - ) + f = NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) f.Add(mkFifoObj("baz", 10)) f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0") @@ -458,12 +458,12 @@ func TestDeltaFIFO_ReplaceDeltaType(t *testing.T) { } func TestDeltaFIFO_UpdateResyncRace(t *testing.T) { - f := NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{mkFifoObj("foo", 5)} }), - ) + }) f.Update(mkFifoObj("foo", 6)) f.Resync() @@ -480,12 +480,12 @@ func TestDeltaFIFO_UpdateResyncRace(t *testing.T) { } func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) { - f := NewDeltaFIFO( - testFifoObjectKeyFunc, - literalListerGetter(func() []testFifoObject { + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{ + KeyFunction: testFifoObjectKeyFunc, + KnownObjects: literalListerGetter(func() []testFifoObject { return []testFifoObject{mkFifoObj("foo", 5), mkFifoObj("bar", 6), mkFifoObj("baz", 7)} }), - ) + }) f.Replace([]interface{}{mkFifoObj("foo", 5)}, "0") expectedList := []Deltas{ @@ -511,7 +511,7 @@ func TestDeltaFIFO_HasSyncedCorrectOnDeletion(t *testing.T) { } func TestDeltaFIFO_detectLineJumpers(t *testing.T) { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) f.Add(mkFifoObj("foo", 10)) f.Add(mkFifoObj("bar", 1)) @@ -539,7 +539,7 @@ func TestDeltaFIFO_detectLineJumpers(t *testing.T) { } func TestDeltaFIFO_addIfNotPresent(t *testing.T) { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) f.Add(mkFifoObj("b", 3)) b3 := Pop(f) @@ -645,7 +645,7 @@ func TestDeltaFIFO_HasSynced(t *testing.T) { } for i, test := range tests { - f := NewDeltaFIFO(testFifoObjectKeyFunc, nil) + f := NewDeltaFIFOWithOptions(DeltaFIFOOptions{KeyFunction: testFifoObjectKeyFunc}) for _, action := range test.actions { action(f)