mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-05 00:51:02 +00:00
Avoid thundering herd on etcd on masters upgrade
Kubernetes-commit: 773d3583bcb7a2ac39c772a9861978d81db0df2f
This commit is contained in:
committed by
Kubernetes Publisher
parent
21de178e1d
commit
5534e24283
37
tools/cache/reflector_test.go
vendored
37
tools/cache/reflector_test.go
vendored
@@ -425,6 +425,8 @@ func TestReflectorWatchListPageSize(t *testing.T) {
|
||||
},
|
||||
}
|
||||
r := NewReflector(lw, &v1.Pod{}, s, 0)
|
||||
// Set resource version to test pagination also for not consistent reads.
|
||||
r.setLastSyncResourceVersion("10")
|
||||
// Set the reflector to paginate the list request in 4 item chunks.
|
||||
r.WatchListPageSize = 4
|
||||
r.ListAndWatch(stopCh)
|
||||
@@ -435,6 +437,41 @@ func TestReflectorWatchListPageSize(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReflectorNotPaginatingNotConsistentReads(t *testing.T) {
|
||||
stopCh := make(chan struct{})
|
||||
s := NewStore(MetaNamespaceKeyFunc)
|
||||
|
||||
lw := &testLW{
|
||||
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
|
||||
// Stop once the reflector begins watching since we're only interested in the list.
|
||||
close(stopCh)
|
||||
fw := watch.NewFake()
|
||||
return fw, nil
|
||||
},
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
if options.ResourceVersion != "10" {
|
||||
t.Fatalf("Expected ResourceVersion: \"10\", got: %s", options.ResourceVersion)
|
||||
}
|
||||
if options.Limit != 0 {
|
||||
t.Fatalf("Expected list Limit of 0 but got %d", options.Limit)
|
||||
}
|
||||
pods := make([]v1.Pod, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
pods[i] = v1.Pod{ObjectMeta: metav1.ObjectMeta{Name: fmt.Sprintf("pod-%d", i), ResourceVersion: fmt.Sprintf("%d", i)}}
|
||||
}
|
||||
return &v1.PodList{ListMeta: metav1.ListMeta{ResourceVersion: "10"}, Items: pods}, nil
|
||||
},
|
||||
}
|
||||
r := NewReflector(lw, &v1.Pod{}, s, 0)
|
||||
r.setLastSyncResourceVersion("10")
|
||||
r.ListAndWatch(stopCh)
|
||||
|
||||
results := s.List()
|
||||
if len(results) != 10 {
|
||||
t.Errorf("Expected 10 results, got %d", len(results))
|
||||
}
|
||||
}
|
||||
|
||||
// TestReflectorResyncWithResourceVersion ensures that a reflector keeps track of the ResourceVersion and sends
|
||||
// it in relist requests to prevent the reflector from traveling back in time if the relist is to a api-server or
|
||||
// etcd that is partitioned and serving older data than the reflector has already processed.
|
||||
|
Reference in New Issue
Block a user