Skip to content

Commit

Permalink
Send resource version in patches
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Olshevski committed Dec 13, 2023
1 parent 6998da2 commit 7a949fe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/controllers/reconciliation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ func (c *Controller) buildPatch(ctx context.Context, prev, resource *reconstitut
prevManifest = []byte(prev.Manifest)
}

// TODO: Don't bother storing the json blob on the manifest struct
var resourceManifest []byte
if resource != nil {
resource.Object.SetResourceVersion(current.GetResourceVersion())
resourceManifest, _ = resource.Object.MarshalJSON()
}

currentJS, err := current.MarshalJSON()
if err != nil {
return nil, "", fmt.Errorf("building json representation of desired state: %w", err)
Expand All @@ -173,11 +180,11 @@ func (c *Controller) buildPatch(ctx context.Context, prev, resource *reconstitut
return nil, "", fmt.Errorf("getting merge metadata: %w", err)
}
if model == nil {
patch, err := jsonmergepatch.CreateThreeWayJSONMergePatch(prevManifest, []byte(resource.Manifest), currentJS)
patch, err := jsonmergepatch.CreateThreeWayJSONMergePatch(prevManifest, []byte(resourceManifest), currentJS)
return patch, types.MergePatchType, err
}

patchmeta := strategicpatch.NewPatchMetaFromOpenAPI(model)
patch, err := strategicpatch.CreateThreeWayMergePatch(prevManifest, []byte(resource.Manifest), currentJS, patchmeta, true)
patch, err := strategicpatch.CreateThreeWayMergePatch(prevManifest, []byte(resourceManifest), currentJS, patchmeta, true)
return patch, types.StrategicMergePatchType, err
}

0 comments on commit 7a949fe

Please sign in to comment.