Skip to content

Commit

Permalink
polish
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Jan 16, 2024
1 parent f2379e6 commit 9ffa3e6
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions common/flagdproxy/flagdproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package flagdproxy
import (
"context"
"fmt"
"reflect"

"github.com/go-logr/logr"
"github.com/open-feature/open-feature-operator/common/types"
Expand Down Expand Up @@ -186,24 +187,32 @@ 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
}
}
// exists, at least one replica ready with correct version, no error
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) {
Expand Down

0 comments on commit 9ffa3e6

Please sign in to comment.