From f18087994daf9d5d629ea07bce66993aa647cf65 Mon Sep 17 00:00:00 2001 From: Vince Prignano Date: Tue, 26 May 2020 12:51:10 -0700 Subject: [PATCH] :sparkles: Add controllerutil.ServerSideApply utility function Signed-off-by: Vince Prignano --- pkg/controller/controllerutil/controllerutil.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/controller/controllerutil/controllerutil.go b/pkg/controller/controllerutil/controllerutil.go index 1207ee6cd8..6f46afd8a1 100644 --- a/pkg/controller/controllerutil/controllerutil.go +++ b/pkg/controller/controllerutil/controllerutil.go @@ -288,3 +288,9 @@ type Object interface { metav1.Object runtime.Object } + +// ServerSideApply peforms a Patch using client.Apply as strategy and forcing ownership in case of conflicts. +func ServerSideApply(ctx context.Context, c client.Client, owner client.FieldOwner, obj Object, opts ...client.PatchOption) error { + opts = append([]client.PatchOption{client.ForceOwnership, owner}, opts...) + return c.Patch(ctx, obj, client.Apply, opts...) +}