Skip to content

Commit de1a8a9

Browse files
authored
Handle list merges where items have been added elsewhere (openshift#367)
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
1 parent 61c81f9 commit de1a8a9

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

openshift/dynamic/apply.py

+3
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def list_merge(last_applied, actual, desired, position):
178178
else:
179179
patch = merge(last_applied_dict[key], desired_dict[key], actual_dict[key], position)
180180
result.append(dict_merge(actual_dict[key], patch))
181+
for key in actual_dict:
182+
if key not in desired_dict and key not in last_applied_dict:
183+
result.append(actual_dict[key])
181184
return result
182185
else:
183186
return desired

test/unit/test_apply.py

+38
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
),
5454
expected = dict(metadata=dict(annotations=None), data=dict(two=None, three="3"))
5555
),
56+
5657
dict(
5758
last_applied = dict(
5859
kind="Service",
@@ -165,6 +166,43 @@
165166
expected=dict(spec=dict(containers=[dict(name="busybox", image="busybox",
166167
resources=dict(requests=dict(cpu="50m", memory="50Mi"), limits=dict(cpu=None, memory="50Mi")))]))
167168
),
169+
dict(
170+
desired = dict(kind='Pod',
171+
spec=dict(containers=[
172+
dict(name='hello',
173+
volumeMounts=[dict(name="test", mountPath="/test")])
174+
],
175+
volumes=[
176+
dict(name="test", configMap=dict(name="test")),
177+
])),
178+
last_applied = dict(kind='Pod',
179+
spec=dict(containers=[
180+
dict(name='hello',
181+
volumeMounts=[dict(name="test", mountPath="/test")])
182+
],
183+
volumes=[
184+
dict(name="test", configMap=dict(name="test")),
185+
])),
186+
actual = dict(kind='Pod',
187+
spec=dict(containers=[
188+
dict(name='hello',
189+
volumeMounts=[dict(name="test", mountPath="/test"),
190+
dict(mountPath="/var/run/secrets/kubernetes.io/serviceaccount", name="default-token-xyz")])
191+
],
192+
volumes=[
193+
dict(name="test", configMap=dict(name="test")),
194+
dict(name="default-token-xyz", secret=dict(secretName="default-token-xyz")),
195+
])),
196+
expected = dict(spec=dict(containers=[
197+
dict(name='hello',
198+
volumeMounts=[dict(name="test", mountPath="/test"),
199+
dict(mountPath="/var/run/secrets/kubernetes.io/serviceaccount", name="default-token-xyz")])
200+
],
201+
volumes=[
202+
dict(name="test", configMap=dict(name="test")),
203+
dict(name="default-token-xyz", secret=dict(secretName="default-token-xyz")),
204+
])),
205+
),
168206

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

0 commit comments

Comments
 (0)