Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-0.11] Handle list merges where items have been added elsewhere #371

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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