| 1 | # Merge (3-way) |
| 2 | |
| 3 | 3-way merge identifies changes between an original source + updated source and merges the result |
| 4 | into a destination, overriding the destination fields where they have changed between |
| 5 | original and updated. |
| 6 | |
| 7 | ### Resource MergeRules |
| 8 | |
| 9 | - Resources present in the original and deleted from the update are deleted. |
| 10 | - Resources missing from the original and added in the update are added. |
| 11 | - Resources present only in the dest are kept without changes. |
| 12 | - Resources present in both the update and the dest have their fields merged with the destination. |
| 13 | |
| 14 | ### Field Merge Rules |
| 15 | |
| 16 | Fields are recursively merged using the following rules: |
| 17 | |
| 18 | - scalars |
| 19 | - if present in either dest or updated and `null`, clear the value |
| 20 | - if unchanged between original and updated, keep dest value |
| 21 | - if changed between original and updated (added, deleted, changed), take the updated value |
| 22 | |
| 23 | - non-associative lists -- lists without a merge key |
| 24 | - if present in either dest or updated and `null`, clear the value |
| 25 | - if unchanged between original and updated, keep dest value |
| 26 | - if changed between original and updated (added, deleted, changed), take the updated value |
| 27 | |
| 28 | - map keys and fields -- paired by the map-key / field-name |
| 29 | - if present in either dest or updated and `null`, clear the value |
| 30 | - if present only in the dest, it keeps its value |
| 31 | - if not-present in the dest, add the delta between original-updated as a field |
| 32 | - otherwise recursively merge the value between original, updated, dest |
| 33 | |
| 34 | - associative list elements -- paired by the associative key |
| 35 | - if present only in the dest, it keeps its value |
| 36 | - if not-present in the dest, add the delta between original-updated as a field |
| 37 | - otherwise recursively merge the value between original, updated, dest |
| 38 | |
| 39 | ### Associative Keys |
| 40 | |
| 41 | Associative keys are used to identify "same" elements within 2 different lists, and merge them. |
| 42 | The following fields are recognized as associative keys: |
| 43 | |
| 44 | [`mountPath`, `devicePath`, `ip`, `type`, `topologyKey`, `name`, `containerPort`] |
| 45 | |
| 46 | Any lists where all of the elements contain associative keys will be merged as associative lists. |