Skip to content

Commit

Permalink
rebase new resource against existing res on cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Kalinin committed Dec 14, 2020
1 parent 94318ad commit 5d0909d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/kapp/diff/change_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@ func NewChangeFactory(rebaseMods []ctlres.ResourceModWithMultiple,
}

func (f ChangeFactory) NewChangeAgainstLastApplied(existingRes, newRes ctlres.Resource) (Change, error) {
// Retain original copy of existing resource and use it
// for rebasing last applied resource and new resource.
existingResForRebasing := existingRes

if existingRes != nil {
// If we have copy of last applied resource (assuming it's still "valid"),
// use it as an existing resource to provide "smart" diff instead of
// diffing against resource that is actually stored on cluster.
lastAppliedRes := f.NewResourceWithHistory(existingRes).LastAppliedResource()
if lastAppliedRes != nil {
rebasedLastAppliedRes, err := NewRebasedResource(existingRes, lastAppliedRes, f.rebaseMods).Resource()
rebasedLastAppliedRes, err := NewRebasedResource(existingResForRebasing, lastAppliedRes, f.rebaseMods).Resource()
if err != nil {
return nil, err
}
Expand All @@ -46,7 +53,7 @@ func (f ChangeFactory) NewChangeAgainstLastApplied(existingRes, newRes ctlres.Re
newRes = historylessNewRes
}

rebasedNewRes, err := NewRebasedResource(existingRes, newRes, f.rebaseMods).Resource()
rebasedNewRes, err := NewRebasedResource(existingResForRebasing, newRes, f.rebaseMods).Resource()
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/kapp/diff/resource_with_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func (r ResourceWithHistory) HistorylessResource() (ctlres.Resource, error) {
return resourceWithoutHistory{r.resource}.Resource()
}

// LastAppliedResource will return "last applied" resource that was saved
// iff it still matches actually saved resource on the cluster (noted at the time of saving).
func (r ResourceWithHistory) LastAppliedResource() ctlres.Resource {
recalculatedLastAppliedChanges, expectedDiffMD5, expectedDiff := r.recalculateLastAppliedChange()

Expand Down

0 comments on commit 5d0909d

Please sign in to comment.