cmd/config/docs/api-conventions/merge2.md
2-way merges fields from a source to a destination, overriding the destination fields where they differ.
Fields are recursively merged using the following rules:
scalars
null, clear it5, dest: 3 => result: 5non-associative lists -- lists without a merge key
null, clear it[1, 2, 3], dest: [a, b, c] => result: [1, 2, 3]map keys and fields -- paired by the map-key / field-name
null, the field is removed from the dest{'key1': 'value1', 'key2': 'value2'},
dest: {'key2': 'value0', 'key3': 'value3'}
=> result: {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}associative list elements -- paired by the associative key
Associative keys are used to identify "same" elements within 2 different lists, and merge them. The following fields are recognized as associative keys:
[mountPath, devicePath, ip, type, topologyKey, name, containerPort]
Any lists where all of the elements contain associative keys will be merged as associative lists.
Source
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 3 # scalar
template:
spec:
containers: # associative list -- (name)
- name: nginx
image: nginx:1.7
command: ['new_run.sh', 'arg1'] # non-associative list
- name: sidecar2
image: sidecar2:v1
Destination
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 1
template:
spec:
containers:
- name: nginx
image: nginx:1.6
command: ['old_run.sh', 'arg0']
- name: sidecar1
image: sidecar1:v1
Result
apiVersion: apps/v1
kind: Deployment
spec:
replicas: 3 # scalar
template:
spec:
containers: # associative list -- (name)
- name: nginx
image: nginx:1.7
command: ['new_run.sh', 'arg1'] # non-associative list
- name: sidecar1
image: sidecar1:v1
- name: sidecar2
image: sidecar2:v1