Skip to content

Commit

Permalink
Only run update logic if objects are actually different
Browse files Browse the repository at this point in the history
Fixes SDN-387
  • Loading branch information
rcarrillocruz committed Apr 30, 2019
1 parent 433e5a3 commit 0a41a55
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/pkg/errors"

"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
uns "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -48,18 +49,17 @@ func ApplyObject(ctx context.Context, client k8sclient.Client, obj *uns.Unstruct
return errors.Wrapf(err, "could not retrieve existing %s", objDesc)
}

// Merge the desired object with what actually exists
if err := MergeObjectForUpdate(existing, obj); err != nil {
return errors.Wrapf(err, "could not merge object %s with existing", objDesc)
}
if !equality.Semantic.DeepEqual(existing, obj) {
// Merge the desired object with what actually exists
if err := MergeObjectForUpdate(existing, obj); err != nil {
return errors.Wrapf(err, "could not merge object %s with existing", objDesc)
}

if err := client.Update(ctx, obj); err != nil {
return errors.Wrapf(err, "could not update object %s", objDesc)
}
if existing.GetResourceVersion() == obj.GetResourceVersion() {
log.Printf("update was noop")
} else {
log.Printf("update was successful")
if err := client.Update(ctx, obj); err != nil {
return errors.Wrapf(err, "could not update object %s", objDesc)
} else {
log.Printf("update was successful")
}
}

return nil
Expand Down

0 comments on commit 0a41a55

Please sign in to comment.