Skip to content

Commit 3f7c4ba

Browse files
authored
Merge pull request #166 from darkowlzz/40-pkg/client-respect-context
pkg/client: Pass ctx to typedClient requests
2 parents 5bccddb + 11794f8 commit 3f7c4ba

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

pkg/client/typed_client.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type typedClient struct {
3030
}
3131

3232
// Create implements client.Client
33-
func (c *typedClient) Create(_ context.Context, obj runtime.Object) error {
33+
func (c *typedClient) Create(ctx context.Context, obj runtime.Object) error {
3434
o, err := c.cache.getObjMeta(obj)
3535
if err != nil {
3636
return err
@@ -39,12 +39,13 @@ func (c *typedClient) Create(_ context.Context, obj runtime.Object) error {
3939
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
4040
Resource(o.resource()).
4141
Body(obj).
42+
Context(ctx).
4243
Do().
4344
Into(obj)
4445
}
4546

4647
// Update implements client.Client
47-
func (c *typedClient) Update(_ context.Context, obj runtime.Object) error {
48+
func (c *typedClient) Update(ctx context.Context, obj runtime.Object) error {
4849
o, err := c.cache.getObjMeta(obj)
4950
if err != nil {
5051
return err
@@ -54,12 +55,13 @@ func (c *typedClient) Update(_ context.Context, obj runtime.Object) error {
5455
Resource(o.resource()).
5556
Name(o.GetName()).
5657
Body(obj).
58+
Context(ctx).
5759
Do().
5860
Into(obj)
5961
}
6062

6163
// Delete implements client.Client
62-
func (c *typedClient) Delete(_ context.Context, obj runtime.Object, opts ...DeleteOptionFunc) error {
64+
func (c *typedClient) Delete(ctx context.Context, obj runtime.Object, opts ...DeleteOptionFunc) error {
6365
o, err := c.cache.getObjMeta(obj)
6466
if err != nil {
6567
return err
@@ -71,24 +73,26 @@ func (c *typedClient) Delete(_ context.Context, obj runtime.Object, opts ...Dele
7173
Resource(o.resource()).
7274
Name(o.GetName()).
7375
Body(deleteOpts.ApplyOptions(opts).AsDeleteOptions()).
76+
Context(ctx).
7477
Do().
7578
Error()
7679
}
7780

7881
// Get implements client.Client
79-
func (c *typedClient) Get(_ context.Context, key ObjectKey, obj runtime.Object) error {
82+
func (c *typedClient) Get(ctx context.Context, key ObjectKey, obj runtime.Object) error {
8083
r, err := c.cache.getResource(obj)
8184
if err != nil {
8285
return err
8386
}
8487
return r.Get().
8588
NamespaceIfScoped(key.Namespace, r.isNamespaced()).
8689
Resource(r.resource()).
90+
Context(ctx).
8791
Name(key.Name).Do().Into(obj)
8892
}
8993

9094
// List implements client.Client
91-
func (c *typedClient) List(_ context.Context, opts *ListOptions, obj runtime.Object) error {
95+
func (c *typedClient) List(ctx context.Context, opts *ListOptions, obj runtime.Object) error {
9296
r, err := c.cache.getResource(obj)
9397
if err != nil {
9498
return err
@@ -102,12 +106,13 @@ func (c *typedClient) List(_ context.Context, opts *ListOptions, obj runtime.Obj
102106
Resource(r.resource()).
103107
Body(obj).
104108
VersionedParams(opts.AsListOptions(), c.paramCodec).
109+
Context(ctx).
105110
Do().
106111
Into(obj)
107112
}
108113

109114
// UpdateStatus used by StatusWriter to write status.
110-
func (c *typedClient) UpdateStatus(_ context.Context, obj runtime.Object) error {
115+
func (c *typedClient) UpdateStatus(ctx context.Context, obj runtime.Object) error {
111116
o, err := c.cache.getObjMeta(obj)
112117
if err != nil {
113118
return err
@@ -122,6 +127,7 @@ func (c *typedClient) UpdateStatus(_ context.Context, obj runtime.Object) error
122127
Name(o.GetName()).
123128
SubResource("status").
124129
Body(obj).
130+
Context(ctx).
125131
Do().
126132
Into(obj)
127133
}

0 commit comments

Comments
 (0)