dimberman commented on a change in pull request #6834: [AIRFLOW-5413] Refactor
worker config
URL: https://github.com/apache/airflow/pull/6834#discussion_r358902501
##########
File path: airflow/kubernetes/pod_generator.py
##########
@@ -290,51 +338,120 @@ def reconcile_pods(base_pod: k8s.V1Pod, client_pod:
k8s.V1Pod) -> k8s.V1Pod:
:type client_pod: k8s.V1Pod
:return: the merged pods
- This can't be done recursively as certain fields are preserved,
- some overwritten, and some concatenated, e.g. The command
- should be preserved from base, the volumes appended to and
- the other fields overwritten.
+ This can't be done recursively as certain fields some overwritten, and
some concatenated.
"""
+ if client_pod is None:
+ return base_pod
+
client_pod_cp = copy.deepcopy(client_pod)
def merge_objects(base_obj, client_obj):
+ if not base_obj:
+ return client_obj
+ if not client_obj:
+ return base_obj
+
+ client_obj_cp = copy.deepcopy(client_obj)
+
for base_key in base_obj.to_dict().keys():
base_val = getattr(base_obj, base_key, None)
if not getattr(client_obj, base_key, None) and base_val:
- setattr(client_obj, base_key, base_val)
+ setattr(client_obj_cp, base_key, base_val)
+ return client_obj_cp
def extend_object_field(base_obj, client_obj, field_name):
+ client_obj_cp = copy.deepcopy(client_obj)
base_obj_field = getattr(base_obj, field_name, None)
client_obj_field = getattr(client_obj, field_name, None)
if not base_obj_field:
- return
+ return client_obj_cp
if not client_obj_field:
- setattr(client_obj, field_name, base_obj_field)
- return
+ setattr(client_obj_cp, field_name, base_obj_field)
+ return client_obj_cp
appended_fields = base_obj_field + client_obj_field
- setattr(client_obj, field_name, appended_fields)
-
- # Values at the pod and metadata should be overwritten where they
exist,
- # but certain values at the spec and container level must be conserved.
- base_container = base_pod.spec.containers[0]
- client_container = client_pod_cp.spec.containers[0]
-
- extend_object_field(base_container, client_container, 'volume_mounts')
- extend_object_field(base_container, client_container, 'env')
- extend_object_field(base_container, client_container, 'env_from')
- extend_object_field(base_container, client_container, 'ports')
- extend_object_field(base_container, client_container, 'volume_devices')
- client_container.command = base_container.command
- client_container.args = base_container.args
- merge_objects(base_pod.spec.containers[0],
client_pod_cp.spec.containers[0])
- # Just append any additional containers from the base pod
- client_pod_cp.spec.containers.extend(base_pod.spec.containers[1:])
-
- merge_objects(base_pod.metadata, client_pod_cp.metadata)
-
- extend_object_field(base_pod.spec, client_pod_cp.spec, 'volumes')
- merge_objects(base_pod.spec, client_pod_cp.spec)
- merge_objects(base_pod, client_pod_cp)
+ setattr(client_obj_cp, field_name, appended_fields)
+ return client_obj_cp
+
+ if base_pod.spec and not client_pod.spec:
+ client_pod_cp.spec = base_pod.spec
+ elif client_pod_cp.spec and base_pod.spec:
+ client_container = client_pod_cp.spec.containers[0]
+ base_container = base_pod.spec.containers[0]
+ cc1 = extend_object_field(base_container, client_container,
'volume_mounts')
Review comment:
Yeah using the same variable would make sense here. You don't need any of
the middle ones.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services