Skip to content

Commit

Permalink
refactor(e2e): throttling k8sclient
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Tranchitella <[email protected]>
  • Loading branch information
prometherion committed Nov 20, 2023
1 parent 6ea480c commit 5bf1887
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 3 deletions.
59 changes: 59 additions & 0 deletions e2e/suite_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//go:build e2e

// Copyright 2020-2023 Project Capsule Authors.
// SPDX-License-Identifier: Apache-2.0

package e2e

import (
"context"
"time"

"sigs.k8s.io/controller-runtime/pkg/client"
)

type e2eClient struct {
client.Client
}

func (e *e2eClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
time.Sleep(time.Second)

return e.Client.Get(ctx, key, obj, opts...)
}

func (e *e2eClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
time.Sleep(time.Second)

return e.Client.List(ctx, list, opts...)
}

func (e *e2eClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error {
time.Sleep(time.Second)

return e.Client.Create(ctx, obj, opts...)
}

func (e *e2eClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error {
time.Sleep(time.Second)

return e.Client.Delete(ctx, obj, opts...)
}

func (e *e2eClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error {
time.Sleep(time.Second)

return e.Client.Update(ctx, obj, opts...)
}

func (e *e2eClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error {
time.Sleep(time.Second)

return e.Client.Patch(ctx, obj, patch, opts...)
}

func (e *e2eClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error {
time.Sleep(time.Second)

return e.Client.DeleteAllOf(ctx, obj, opts...)
}
9 changes: 6 additions & 3 deletions e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ var _ = BeforeSuite(func() {

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

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
ctrlClient, err := client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).ToNot(HaveOccurred())
Expect(k8sClient).ToNot(BeNil())
Expect(ctrlClient).ToNot(BeNil())

k8sClient = e2eClient{Client: ctrlClient}
})

var _ = AfterSuite(func() {
Expand All @@ -70,5 +72,6 @@ func ownerClient(owner capsulev1beta2.OwnerSpec) (cs kubernetes.Interface) {
c.Impersonate.UserName = owner.Name
cs, err = kubernetes.NewForConfig(c)
Expect(err).ToNot(HaveOccurred())
return

return cs
}

0 comments on commit 5bf1887

Please sign in to comment.