-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
🌱Add a Client wrapper that sets the field owner #1474
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package fieldowner | ||
|
||
import ( | ||
"context" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
// Wrap wraps a Client with one that sets the field owner. | ||
func Wrap(upstream client.Client, owner string) client.Client { | ||
return &clientWithOwner{Client: upstream, owner: client.FieldOwner(owner)} | ||
} | ||
|
||
type clientWithOwner struct { | ||
client.Client | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer not to embedd the Client, because should we extend the Client in the future with a method that needs wrapping, the |
||
owner client.FieldOwner | ||
} | ||
|
||
func (c *clientWithOwner) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error { | ||
return c.Client.Create(ctx, obj, append(opts, c.owner)...) | ||
} | ||
|
||
func (c *clientWithOwner) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error { | ||
return c.Client.Update(ctx, obj, append(opts, c.owner)...) | ||
} | ||
|
||
func (c *clientWithOwner) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, me too, but the I wonder if @DirectXMan12 who seems to have authored that in #435 has a view? |
||
return c.Client.Patch(ctx, obj, patch, append(opts, c.owner)...) | ||
} | ||
|
||
func (c *clientWithOwner) Status() client.StatusWriter { | ||
return &statusWriterWithOwner{StatusWriter: c.Client.Status(), owner: c.owner} | ||
} | ||
|
||
type statusWriterWithOwner struct { | ||
client.StatusWriter | ||
owner client.FieldOwner | ||
} | ||
|
||
func (s *statusWriterWithOwner) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error { | ||
return s.StatusWriter.Update(ctx, obj, append(opts, s.owner)...) | ||
} | ||
|
||
func (s *statusWriterWithOwner) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error { | ||
return s.StatusWriter.Patch(ctx, obj, patch, append(opts, s.owner)...) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be better in pkg/client, ppl might not find it here