Merge pull request #96797 from jqmichael/initialCountLength

Fixed a bug where initialPopulationCount should be based on the key length not list size in DeltaFIFO#Replace()

Kubernetes-commit: 7d8587c4cc3529dc9065c1536071ea382e6c725c
This commit is contained in:
Kubernetes Publisher 2020-12-08 20:03:17 -08:00
commit e24efdc77f
5 changed files with 15 additions and 6 deletions

2
Godeps/Godeps.json generated
View File

@ -464,7 +464,7 @@
},
{
"ImportPath": "k8s.io/api",
"Rev": "d10e393578ca"
"Rev": "fcac651617f2"
},
{
"ImportPath": "k8s.io/apimachinery",

4
go.mod
View File

@ -26,7 +26,7 @@ require (
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
k8s.io/api v0.0.0-20201209045732-d10e393578ca
k8s.io/api v0.0.0-20201209045733-fcac651617f2
k8s.io/apimachinery v0.0.0-20201209005534-8f01ffc4dcb8
k8s.io/klog/v2 v2.4.0
k8s.io/utils v0.0.0-20201110183641-67b214c5f920
@ -34,6 +34,6 @@ require (
)
replace (
k8s.io/api => k8s.io/api v0.0.0-20201209045732-d10e393578ca
k8s.io/api => k8s.io/api v0.0.0-20201209045733-fcac651617f2
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20201209005534-8f01ffc4dcb8
)

2
go.sum
View File

@ -433,7 +433,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-20201209045732-d10e393578ca/go.mod h1:xjrWEKNUnu5XTPx3c+1VDDkb3vXmUiTwwHureX1M32c=
k8s.io/api v0.0.0-20201209045733-fcac651617f2/go.mod h1:xjrWEKNUnu5XTPx3c+1VDDkb3vXmUiTwwHureX1M32c=
k8s.io/apimachinery v0.0.0-20201209005534-8f01ffc4dcb8/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
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=

View File

@ -572,7 +572,7 @@ func (f *DeltaFIFO) Replace(list []interface{}, resourceVersion string) error {
f.populated = true
// While there shouldn't be any queued deletions in the initial
// population of the queue, it's better to be on the safe side.
f.initialPopulationCount = len(list) + queuedDeletions
f.initialPopulationCount = keys.Len() + queuedDeletions
}
return nil
@ -602,7 +602,7 @@ func (f *DeltaFIFO) Replace(list []interface{}, resourceVersion string) error {
if !f.populated {
f.populated = true
f.initialPopulationCount = len(list) + queuedDeletions
f.initialPopulationCount = keys.Len() + queuedDeletions
}
return nil

View File

@ -633,6 +633,15 @@ func TestDeltaFIFO_HasSynced(t *testing.T) {
},
expectedSynced: true,
},
{
// This test case won't happen in practice since a Reflector, the only producer for delta_fifo today, always passes a complete snapshot consistent in time;
// there cannot be duplicate keys in the list or apiserver is broken.
actions: []func(f *DeltaFIFO){
func(f *DeltaFIFO) { f.Replace([]interface{}{mkFifoObj("a", 1), mkFifoObj("a", 2)}, "0") },
func(f *DeltaFIFO) { Pop(f) },
},
expectedSynced: true,
},
}
for i, test := range tests {