Skip to content

pkg/client: Pass ctx to typedClient requests #166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions pkg/client/typed_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type typedClient struct {
}

// Create implements client.Client
func (c *typedClient) Create(_ context.Context, obj runtime.Object) error {
func (c *typedClient) Create(ctx context.Context, obj runtime.Object) error {
o, err := c.cache.getObjMeta(obj)
if err != nil {
return err
Expand All @@ -39,12 +39,13 @@ func (c *typedClient) Create(_ context.Context, obj runtime.Object) error {
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).
Resource(o.resource()).
Body(obj).
Context(ctx).
Do().
Into(obj)
}

// Update implements client.Client
func (c *typedClient) Update(_ context.Context, obj runtime.Object) error {
func (c *typedClient) Update(ctx context.Context, obj runtime.Object) error {
o, err := c.cache.getObjMeta(obj)
if err != nil {
return err
Expand All @@ -54,12 +55,13 @@ func (c *typedClient) Update(_ context.Context, obj runtime.Object) error {
Resource(o.resource()).
Name(o.GetName()).
Body(obj).
Context(ctx).
Do().
Into(obj)
}

// Delete implements client.Client
func (c *typedClient) Delete(_ context.Context, obj runtime.Object, opts ...DeleteOptionFunc) error {
func (c *typedClient) Delete(ctx context.Context, obj runtime.Object, opts ...DeleteOptionFunc) error {
o, err := c.cache.getObjMeta(obj)
if err != nil {
return err
Expand All @@ -71,24 +73,26 @@ func (c *typedClient) Delete(_ context.Context, obj runtime.Object, opts ...Dele
Resource(o.resource()).
Name(o.GetName()).
Body(deleteOpts.ApplyOptions(opts).AsDeleteOptions()).
Context(ctx).
Do().
Error()
}

// Get implements client.Client
func (c *typedClient) Get(_ context.Context, key ObjectKey, obj runtime.Object) error {
func (c *typedClient) Get(ctx context.Context, key ObjectKey, obj runtime.Object) error {
r, err := c.cache.getResource(obj)
if err != nil {
return err
}
return r.Get().
NamespaceIfScoped(key.Namespace, r.isNamespaced()).
Resource(r.resource()).
Context(ctx).
Name(key.Name).Do().Into(obj)
}

// List implements client.Client
func (c *typedClient) List(_ context.Context, opts *ListOptions, obj runtime.Object) error {
func (c *typedClient) List(ctx context.Context, opts *ListOptions, obj runtime.Object) error {
r, err := c.cache.getResource(obj)
if err != nil {
return err
Expand All @@ -102,12 +106,13 @@ func (c *typedClient) List(_ context.Context, opts *ListOptions, obj runtime.Obj
Resource(r.resource()).
Body(obj).
VersionedParams(opts.AsListOptions(), c.paramCodec).
Context(ctx).
Do().
Into(obj)
}

// UpdateStatus used by StatusWriter to write status.
func (c *typedClient) UpdateStatus(_ context.Context, obj runtime.Object) error {
func (c *typedClient) UpdateStatus(ctx context.Context, obj runtime.Object) error {
o, err := c.cache.getObjMeta(obj)
if err != nil {
return err
Expand All @@ -122,6 +127,7 @@ func (c *typedClient) UpdateStatus(_ context.Context, obj runtime.Object) error
Name(o.GetName()).
SubResource("status").
Body(obj).
Context(ctx).
Do().
Into(obj)
}