Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down