You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/12/17 15:59:17 UTC

[GitHub] [airflow] davlum commented on a change in pull request #6834: [AIRFLOW-5413] Refactor worker config

davlum commented on a change in pull request #6834: [AIRFLOW-5413] Refactor worker config
URL: https://github.com/apache/airflow/pull/6834#discussion_r358876146
 
 

 ##########
 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:
   I could use the same variable name.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services