ashb commented on a change in pull request #6230: [AIRFLOW-5413] Allow K8S 
worker pod to be configured from JSON/YAML file
URL: https://github.com/apache/airflow/pull/6230#discussion_r374559844
 
 

 ##########
 File path: airflow/kubernetes/pod_generator.py
 ##########
 @@ -301,36 +310,14 @@ def from_obj(obj) -> Optional[k8s.V1Pod]:
                     limits=limits
                 )
 
-        pod_spec_generator = PodGenerator(
-            image=namespaced.get('image'),
-            envs=namespaced.get('env'),
-            cmds=namespaced.get('cmds'),
-            args=namespaced.get('args'),
-            labels=namespaced.get('labels'),
-            node_selectors=namespaced.get('node_selectors'),
-            name=namespaced.get('name'),
-            ports=namespaced.get('ports'),
-            volumes=namespaced.get('volumes'),
-            volume_mounts=namespaced.get('volume_mounts'),
-            namespace=namespaced.get('namespace'),
-            image_pull_policy=namespaced.get('image_pull_policy'),
-            restart_policy=namespaced.get('restart_policy'),
-            image_pull_secrets=namespaced.get('image_pull_secrets'),
-            init_containers=namespaced.get('init_containers'),
-            service_account_name=namespaced.get('service_account_name'),
-            resources=resources,
-            annotations=namespaced.get('annotations'),
-            affinity=namespaced.get('affinity'),
-            hostnetwork=namespaced.get('hostnetwork'),
-            tolerations=namespaced.get('tolerations'),
-            security_context=namespaced.get('security_context'),
-            configmaps=namespaced.get('configmaps'),
-            dnspolicy=namespaced.get('dnspolicy'),
-            schedulername=namespaced.get('schedulername'),
-            pod=namespaced.get('pod'),
-            extract_xcom=namespaced.get('extract_xcom'),
-        )
+        pod_args = list(inspect.signature(PodGenerator).parameters)
 
+        def reducer(d: dict, arg: str):
+            return {**d, arg: namespaced.get(arg)}
+
+        pod_kwargs = reduce(reducer, pod_args, {})
 
 Review comment:
   This is ... odd/slower than it needs to be. A dict comprehension would be 
more-pythonic:
   
   ```suggestion
           pod_kwargs= { k: namespaced.get(k) for k in pod_args }
   ```
   
   I think. That said: Is there any reason why we don't just do this:
   
   ```python
       namespaced['resources'] = resources
       pod_spec_generator = PodGenerator(**namespaced)
   ```
   
   No need to build a new dict, no need to call inspect at run time (which is 
often a sign something 'clever' is going on, and clever is usually hard to 
read.)

----------------------------------------------------------------
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

Reply via email to