From eaa9af21d70ae1d4b3b25c37edd9cb6a44df97d2 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 09:32:57 -0400 Subject: [PATCH] fix: ensure appset don't attempt to remove application kind in patch requests (#16056) (#16073) Signed-off-by: Alexander Matyushentsev Co-authored-by: Alexander Matyushentsev --- applicationset/utils/createOrUpdate.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/applicationset/utils/createOrUpdate.go b/applicationset/utils/createOrUpdate.go index 096be5a9a97d3..274070c2ef5be 100644 --- a/applicationset/utils/createOrUpdate.go +++ b/applicationset/utils/createOrUpdate.go @@ -10,6 +10,7 @@ import ( "k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" @@ -78,6 +79,12 @@ func CreateOrUpdate(ctx context.Context, c client.Client, obj client.Object, f c return a.Namespace == b.Namespace && a.Name == b.Name && a.Server == b.Server }, ) + // make sure updated object has the same apiVersion & kind as original object + if objKind, ok := obj.(schema.ObjectKind); ok { + if existingKind, ok := existing.(schema.ObjectKind); ok { + existingKind.SetGroupVersionKind(objKind.GroupVersionKind()) + } + } if equality.DeepEqual(existing, obj) { return controllerutil.OperationResultNone, nil