Skip to content

Commit 482d3e0

Browse files
committed
refactor(e2e): throttling k8sclient
1 parent c4f52f4 commit 482d3e0

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

e2e/suite_client_test.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//go:build e2e
2+
3+
// Copyright 2020-2023 Project Capsule Authors.
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package e2e
7+
8+
import (
9+
"context"
10+
"time"
11+
12+
"sigs.k8s.io/controller-runtime/pkg/client"
13+
)
14+
15+
type e2eClient struct {
16+
client.Client
17+
}
18+
19+
func (e *e2eClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
20+
time.Sleep(time.Second)
21+
22+
return e.Client.Get(ctx, key, obj, opts...)
23+
}
24+
25+
func (e *e2eClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
26+
time.Sleep(time.Second)
27+
28+
return e.Client.List(ctx, list, opts...)
29+
}
30+
31+
func (e *e2eClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
32+
time.Sleep(time.Second)
33+
34+
return e.Client.Create(ctx, obj, opts...)
35+
}
36+
37+
func (e *e2eClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error {
38+
time.Sleep(time.Second)
39+
40+
return e.Client.Delete(ctx, obj, opts...)
41+
}
42+
43+
func (e *e2eClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
44+
time.Sleep(time.Second)
45+
46+
return e.Client.Update(ctx, obj, opts...)
47+
}
48+
49+
func (e *e2eClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
50+
time.Sleep(time.Second)
51+
52+
return e.Client.Patch(ctx, obj, patch, opts...)
53+
}
54+
55+
func (e *e2eClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error {
56+
time.Sleep(time.Second)
57+
58+
return e.Client.DeleteAllOf(ctx, obj, opts...)
59+
}

e2e/suite_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ var _ = BeforeSuite(func() {
5353

5454
Expect(capsulev1beta2.AddToScheme(scheme.Scheme)).NotTo(HaveOccurred())
5555

56-
k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
56+
ctrlClient, err := client.New(cfg, client.Options{Scheme: scheme.Scheme})
5757
Expect(err).ToNot(HaveOccurred())
58-
Expect(k8sClient).ToNot(BeNil())
58+
Expect(ctrlClient).ToNot(BeNil())
59+
60+
k8sClient = e2eClient{Client: ctrlClient}
5961
})
6062

6163
var _ = AfterSuite(func() {
@@ -70,5 +72,6 @@ func ownerClient(owner capsulev1beta2.OwnerSpec) (cs kubernetes.Interface) {
7072
c.Impersonate.UserName = owner.Name
7173
cs, err = kubernetes.NewForConfig(c)
7274
Expect(err).ToNot(HaveOccurred())
73-
return
75+
76+
return cs
7477
}

0 commit comments

Comments
 (0)