Skip to content

Commit 66e4a11

Browse files
authored
Merge pull request etcd-io#20570 from AwesomePatrol/add-stale-lists-to-robustness-tests
Add stale lists to Kubernetes robustness tests
2 parents 21d04d7 + fdfe042 commit 66e4a11

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

tests/robustness/model/describe.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ func describeRangeRequest(opts RangeOptions, revision int64) string {
223223
return fmt.Sprintf("get(%q%s)", opts.Start, kwargsString)
224224
case opts.End == clientv3.GetPrefixRangeEnd(opts.Start):
225225
return fmt.Sprintf("list(%q%s)", opts.Start, kwargsString)
226+
case strings.HasSuffix(opts.Start, "\x00") && strings.HasSuffix(opts.End, "0") && strings.HasPrefix(opts.Start, opts.End[:len(opts.End)-1]):
227+
return fmt.Sprintf("list[continued](%q%s)", strings.TrimRight(opts.Start, "\x00"), kwargsString)
226228
default:
227229
return fmt.Sprintf("range(%q..%q%s)", opts.Start, opts.End, kwargsString)
228230
}

tests/robustness/traffic/kubernetes.go

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ var (
4141
resource: "pods",
4242
namespace: "default",
4343
// Please keep the sum of weights equal 100.
44+
readChoices: []random.ChoiceWeight[KubernetesRequestType]{
45+
{Choice: KubernetesListStale, Weight: 20},
46+
{Choice: KubernetesListAndWatch, Weight: 80},
47+
},
48+
// Please keep the sum of weights equal 100.
4449
writeChoices: []random.ChoiceWeight[KubernetesRequestType]{
4550
{Choice: KubernetesUpdate, Weight: 90},
4651
{Choice: KubernetesDelete, Weight: 5},
@@ -53,6 +58,11 @@ var (
5358
resource: "pods",
5459
namespace: "default",
5560
// Please keep the sum of weights equal 100.
61+
readChoices: []random.ChoiceWeight[KubernetesRequestType]{
62+
{Choice: KubernetesListStale, Weight: 20},
63+
{Choice: KubernetesListAndWatch, Weight: 80},
64+
},
65+
// Please keep the sum of weights equal 100.
5666
writeChoices: []random.ChoiceWeight[KubernetesRequestType]{
5767
{Choice: KubernetesDelete, Weight: 40},
5868
{Choice: KubernetesCreate, Weight: 60},
@@ -64,6 +74,7 @@ type kubernetesTraffic struct {
6474
averageKeyCount int
6575
resource string
6676
namespace string
77+
readChoices []random.ChoiceWeight[KubernetesRequestType]
6778
writeChoices []random.ChoiceWeight[KubernetesRequestType]
6879
}
6980

@@ -76,7 +87,6 @@ func (t kubernetesTraffic) RunTrafficLoop(ctx context.Context, c *client.Recordi
7687
s := newStorage()
7788
keyPrefix := "/registry/" + t.resource + "/"
7889
g := errgroup.Group{}
79-
readLimit := t.averageKeyCount
8090

8191
g.Go(func() error {
8292
for {
@@ -87,11 +97,10 @@ func (t kubernetesTraffic) RunTrafficLoop(ctx context.Context, c *client.Recordi
8797
return nil
8898
default:
8999
}
90-
rev, err := t.Read(ctx, kc, s, limiter, keyPrefix, readLimit)
100+
err := t.Read(ctx, c, s, limiter, keyPrefix)
91101
if err != nil {
92102
continue
93103
}
94-
t.Watch(ctx, c, s, limiter, keyPrefix, rev+1)
95104
}
96105
})
97106
g.Go(func() error {
@@ -106,7 +115,7 @@ func (t kubernetesTraffic) RunTrafficLoop(ctx context.Context, c *client.Recordi
106115
}
107116
// Avoid multiple failed writes in a row
108117
if lastWriteFailed {
109-
_, err := t.Read(ctx, kc, s, limiter, keyPrefix, 0)
118+
_, err := t.List(ctx, kc, s, limiter, keyPrefix, t.averageKeyCount, 0)
110119
if err != nil {
111120
continue
112121
}
@@ -121,10 +130,29 @@ func (t kubernetesTraffic) RunTrafficLoop(ctx context.Context, c *client.Recordi
121130
g.Wait()
122131
}
123132

124-
func (t kubernetesTraffic) Read(ctx context.Context, kc kubernetes.Interface, s *storage, limiter *rate.Limiter, keyPrefix string, limit int) (rev int64, err error) {
133+
func (t kubernetesTraffic) Read(ctx context.Context, c *client.RecordingClient, s *storage, limiter *rate.Limiter, keyPrefix string) error {
134+
kc := kubernetes.Client{Client: &clientv3.Client{KV: c}}
135+
op := random.PickRandom(t.readChoices)
136+
switch op {
137+
case KubernetesListStale:
138+
_, rev := s.PickRandom()
139+
_, err := t.List(ctx, kc, s, limiter, keyPrefix, t.averageKeyCount, rev)
140+
return err
141+
case KubernetesListAndWatch:
142+
rev, err := t.List(ctx, kc, s, limiter, keyPrefix, t.averageKeyCount, 0)
143+
if err != nil {
144+
return err
145+
}
146+
t.Watch(ctx, c, s, limiter, keyPrefix, rev+1)
147+
return nil
148+
default:
149+
panic(fmt.Sprintf("invalid choice: %q", op))
150+
}
151+
}
152+
153+
func (t kubernetesTraffic) List(ctx context.Context, kc kubernetes.Interface, s *storage, limiter *rate.Limiter, keyPrefix string, limit int, revision int64) (rev int64, err error) {
125154
hasMore := true
126155
var kvs []*mvccpb.KeyValue
127-
var revision int64
128156
var cont string
129157

130158
for hasMore {
@@ -277,9 +305,11 @@ func compact(ctx context.Context, client *client.RecordingClient, t, rev int64)
277305
type KubernetesRequestType string
278306

279307
const (
280-
KubernetesDelete KubernetesRequestType = "delete"
281-
KubernetesUpdate KubernetesRequestType = "update"
282-
KubernetesCreate KubernetesRequestType = "create"
308+
KubernetesDelete KubernetesRequestType = "delete"
309+
KubernetesUpdate KubernetesRequestType = "update"
310+
KubernetesCreate KubernetesRequestType = "create"
311+
KubernetesListStale KubernetesRequestType = "list_stale"
312+
KubernetesListAndWatch KubernetesRequestType = "list_watch"
283313
)
284314

285315
type storage struct {
@@ -333,7 +363,11 @@ func (s *storage) Count() int {
333363
func (s *storage) PickRandom() (key string, rev int64) {
334364
s.mux.RLock()
335365
defer s.mux.RUnlock()
336-
n := rand.Intn(len(s.keyRevision))
366+
l := len(s.keyRevision)
367+
if l == 0 {
368+
return "", 0
369+
}
370+
n := rand.Intn(l)
337371
i := 0
338372
for k, v := range s.keyRevision {
339373
if i == n {

0 commit comments

Comments
 (0)