From 2b11491d9c9a0cbb7e676885d9b33f2df80facf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Puczyn=CC=81ski?= Date: Thu, 20 Nov 2025 00:21:24 +0100 Subject: [PATCH 1/2] Add FieldOwner field to client.Options --- pkg/client/client.go | 7 +++++++ pkg/client/client_test.go | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/client/client.go b/pkg/client/client.go index 39050de457..f1972d00b0 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -52,6 +52,9 @@ type Options struct { // DryRun instructs the client to only perform dry run requests. DryRun *bool + + // FieldOwner, if provided, instructs the client to be wrapped with WithFieldOwner function + FieldOwner string } // CacheOptions are options for creating a cache-backed client. @@ -99,6 +102,10 @@ func New(config *rest.Config, options Options) (c Client, err error) { if err == nil && options.DryRun != nil && *options.DryRun { c = NewDryRunClient(c) } + if fo := options.FieldOwner; fo != "" { + c = WithFieldOwner(c, fo) + } + return c, err } diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go index 079458f527..c32b78f775 100644 --- a/pkg/client/client_test.go +++ b/pkg/client/client_test.go @@ -365,6 +365,19 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC Expect(cl.List(ctx, &corev1.NamespaceList{})).To(Succeed()) Expect(cache.Called).To(Equal(0)) }) + + It("should use the provided FieldOwner if provided", func(ctx SpecContext) { + cl, err := client.New(cfg, client.Options{FieldOwner: "test-owner"}) + Expect(err).NotTo(HaveOccurred()) + Expect(cl).NotTo(BeNil()) + // no explicit FieldOwner option set on Apply method call + err = cl.Apply(ctx, corev1applyconfigurations.ConfigMap("test-cm", "default").WithData(map[string]string{"foo": "bar"})) + Expect(err).NotTo(HaveOccurred()) + actual, err := clientset.CoreV1().ConfigMaps("default").Get(ctx, "test-cm", metav1.GetOptions{}) + Expect(err).NotTo(HaveOccurred()) + Expect(actual.ManagedFields).To(HaveLen(1)) + Expect(actual.ManagedFields[0].Manager).To(Equal("test-owner")) + }) }) Describe("Create", func() { From 389d0093d2d8c7076128e26a85f75094472ca521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Puczyn=CC=81ski?= Date: Fri, 21 Nov 2025 09:48:39 +0100 Subject: [PATCH 2/2] Update client.Options.FieldOwner documentation --- pkg/client/client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/client/client.go b/pkg/client/client.go index f1972d00b0..1a14fcc5e2 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -53,7 +53,13 @@ type Options struct { // DryRun instructs the client to only perform dry run requests. DryRun *bool - // FieldOwner, if provided, instructs the client to be wrapped with WithFieldOwner function + // FieldOwner, if provided, sets the default field manager for all write operations + // (Create, Update, Patch, Apply) performed by this client. The field manager is used by + // the server for Server-Side Apply to track field ownership. + // For more details, see: https://kubernetes.io/docs/reference/using-api/server-side-apply/#field-management + // + // This default can be overridden for a specific call by passing a [FieldOwner] option + // to the method. FieldOwner string }