From 9ffa3e6862ebfb7aa56be93d4a52a28c8aaf0022 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Tue, 16 Jan 2024 09:03:36 +0100 Subject: [PATCH] polish Signed-off-by: odubajDT --- common/flagdproxy/flagdproxy.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/common/flagdproxy/flagdproxy.go b/common/flagdproxy/flagdproxy.go index 447a0632f..b8a03a7a9 100644 --- a/common/flagdproxy/flagdproxy.go +++ b/common/flagdproxy/flagdproxy.go @@ -3,6 +3,7 @@ package flagdproxy import ( "context" "fmt" + "reflect" "github.com/go-logr/logr" "github.com/open-feature/open-feature-operator/common/types" @@ -186,14 +187,23 @@ func (f *FlagdProxyHandler) doesFlagdProxyExist(ctx context.Context) (bool, erro // does not exist, is not ready, is in error return false, err } - if !f.isFlagdProxyUpToDate(d) { - ownerReferences, err := f.getOwnerReference(ctx) - if err != nil { - return false, err - } - d = f.newFlagdProxyManifest([]metav1.OwnerReference{ownerReferences}) + // generate new Deployment struct + ownerReferences, err := f.getOwnerReference(ctx) + if err != nil { + return false, err + } + newDeployment := f.newFlagdProxyManifest([]metav1.OwnerReference{ownerReferences}) + + if !f.isFlagdProxyUpToDate(d, newDeployment) { + f.Log.Info("flagd-proxy Deployment changed, updating") + // copy new content + d.Spec = newDeployment.Spec + d.Labels = newDeployment.Labels + d.OwnerReferences = newDeployment.OwnerReferences + // update err = f.Client.Update(ctx, d) if err != nil { + f.Log.Error(err, "Could not update flagd-proxy Deployment") return false, err } } @@ -201,9 +211,8 @@ func (f *FlagdProxyHandler) doesFlagdProxyExist(ctx context.Context) (bool, erro return true, nil } -func (f *FlagdProxyHandler) isFlagdProxyUpToDate(d *appsV1.Deployment) bool { - img := fmt.Sprintf("%s:%s", f.config.Image, f.config.Tag) - return img == d.Spec.Template.Spec.Containers[0].Image +func (f *FlagdProxyHandler) isFlagdProxyUpToDate(old, new *appsV1.Deployment) bool { + return reflect.DeepEqual(old.Spec, new.Spec) } func (f *FlagdProxyHandler) getOwnerReference(ctx context.Context) (metav1.OwnerReference, error) {