Skip to content

Commit 1bd697a

Browse files
author
Antoine Pelisse
committed
merge: Apply returns nil object if unchanged
We need to know when the apply operation isn't changing the object, so that we can update the timestamp of the operation. The simplest way to do so it to return nil.
1 parent 333e024 commit 1bd697a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

internal/fixture/state.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ func (s *State) ApplyObject(tv *typed.TypedValue, version fieldpath.APIVersion,
150150
if err != nil {
151151
return err
152152
}
153-
s.Live = new
154153
s.Managers = managers
155-
154+
if new != nil {
155+
s.Live = new
156+
}
156157
return nil
157158
}
158159

merge/update.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ func (s *Updater) Update(liveObject, newObject *typed.TypedValue, version fieldp
148148

149149
// Apply should be called when Apply is run, given the current object as
150150
// well as the configuration that is applied. This will merge the object
151-
// and return it.
151+
// and return it. If the object hasn't changed, nil is returned (the
152+
// managers can still have changed though).
152153
func (s *Updater) Apply(liveObject, configObject *typed.TypedValue, version fieldpath.APIVersion, managers fieldpath.ManagedFields, manager string, force bool) (*typed.TypedValue, fieldpath.ManagedFields, error) {
153154
managers = shallowCopyManagers(managers)
154155
var err error
@@ -178,10 +179,13 @@ func (s *Updater) Apply(liveObject, configObject *typed.TypedValue, version fiel
178179
if err != nil {
179180
return nil, fieldpath.ManagedFields{}, fmt.Errorf("failed to prune fields: %v", err)
180181
}
181-
managers, _, err = s.update(liveObject, newObject, version, managers, manager, force)
182+
managers, compare, err := s.update(liveObject, newObject, version, managers, manager, force)
182183
if err != nil {
183184
return nil, fieldpath.ManagedFields{}, err
184185
}
186+
if compare.IsSame() {
187+
newObject = nil
188+
}
185189
return newObject, managers, nil
186190
}
187191

0 commit comments

Comments
 (0)