Skip to content

Commit

Permalink
Handle list merges where items have been added elsewhere (#371)
Browse files Browse the repository at this point in the history
For example, a Pod has its service account token mounted as
a volume - we don't want to later try and remove it.

Other examples are likely available

Co-authored-by: Will Thames <[email protected]>
  • Loading branch information
openshift-cherrypick-robot and willthames authored Jun 6, 2020
1 parent 43a072d commit e2e6989
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions openshift/dynamic/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ def list_merge(last_applied, actual, desired, position):
else:
patch = merge(last_applied_dict[key], desired_dict[key], actual_dict[key], position)
result.append(dict_merge(actual_dict[key], patch))
for key in actual_dict:
if key not in desired_dict and key not in last_applied_dict:
result.append(actual_dict[key])
return result
else:
return desired
Expand Down
38 changes: 38 additions & 0 deletions test/unit/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
),
expected = dict(metadata=dict(annotations=None), data=dict(two=None, three="3"))
),

dict(
last_applied = dict(
kind="Service",
Expand Down Expand Up @@ -165,6 +166,43 @@
expected=dict(spec=dict(containers=[dict(name="busybox", image="busybox",
resources=dict(requests=dict(cpu="50m", memory="50Mi"), limits=dict(cpu=None, memory="50Mi")))]))
),
dict(
desired = dict(kind='Pod',
spec=dict(containers=[
dict(name='hello',
volumeMounts=[dict(name="test", mountPath="/test")])
],
volumes=[
dict(name="test", configMap=dict(name="test")),
])),
last_applied = dict(kind='Pod',
spec=dict(containers=[
dict(name='hello',
volumeMounts=[dict(name="test", mountPath="/test")])
],
volumes=[
dict(name="test", configMap=dict(name="test")),
])),
actual = dict(kind='Pod',
spec=dict(containers=[
dict(name='hello',
volumeMounts=[dict(name="test", mountPath="/test"),
dict(mountPath="/var/run/secrets/kubernetes.io/serviceaccount", name="default-token-xyz")])
],
volumes=[
dict(name="test", configMap=dict(name="test")),
dict(name="default-token-xyz", secret=dict(secretName="default-token-xyz")),
])),
expected = dict(spec=dict(containers=[
dict(name='hello',
volumeMounts=[dict(name="test", mountPath="/test"),
dict(mountPath="/var/run/secrets/kubernetes.io/serviceaccount", name="default-token-xyz")])
],
volumes=[
dict(name="test", configMap=dict(name="test")),
dict(name="default-token-xyz", secret=dict(secretName="default-token-xyz")),
])),
),

# This next one is based on a real world case where definition was mostly
# str type and everything else was mostly unicode type (don't ask me how)
Expand Down

0 comments on commit e2e6989

Please sign in to comment.