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/04/01 18:05:21 UTC

[GitHub] [airflow] davlum commented on a change in pull request #4952: [AIRFLOW-4008] add envFrom for Kubernetes Executor

davlum commented on a change in pull request #4952: [AIRFLOW-4008] add envFrom for Kubernetes Executor
URL: https://github.com/apache/airflow/pull/4952#discussion_r270986335
 
 

 ##########
 File path: tests/contrib/kubernetes/kubernetes_request_factory/test_kubernetes_request_factory.py
 ##########
 @@ -0,0 +1,384 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from airflow.contrib.kubernetes.kubernetes_request_factory.\
+    kubernetes_request_factory import KubernetesRequestFactory
+from airflow.contrib.kubernetes.pod import Pod, Resources
+from airflow.contrib.kubernetes.secret import Secret
+import unittest
+
+
+class TestKubernetesRequestFactory(unittest.TestCase):
+
+    def setUp(self) -> None:
+        self.kubernetes_request_factory = KubernetesRequestFactory()
+
+        self.req = {
+            'apiVersion': 'v1',
+            'kind': 'Pod',
+            'metadata': {
+                'name': 'name'
+            },
+            'spec': {
+                'restartPolicy': 'Never',
+                'containers': [{
+                    'name': 'base',
+                    'image': 'airflow-worker:latest',
+                    'command': [
+                        "/usr/local/airflow/entrypoint.sh",
+                        "/bin/bash sleep 25"
+                    ],
+                }]
+            }
+        }
+
+    def test_extract_image(self):
+        input_req = self.req.copy()
+        reference = self.req.copy()
+        image = 'v3.14'
+        pod = Pod(image, {}, [])
+        self.kubernetes_request_factory.extract_image(pod, input_req)
+        reference['spec']['containers'][0]['image'] = image
+        self.assertDictEqual(input_req, reference)
+
+    def test_extract_image_pull_policy(self):
 
 Review comment:
   So I had implemented the tests using `@parameterized.expand` as suggested (good suggestion btw), testing essentially that if the default argument was given that the function would be identity, the `Pod` would remain unaltered. The issue is that methods in `pod_request_factory` aren't uniform in how they approaches default arguments. Some apply the arguments anyway, even though the key is optional and the value is empty. Example; 
   
   ```
       @staticmethod
       def extract_labels(pod, req):
           req['metadata']['labels'] = req['metadata'].get('labels', {})
           for k, v in six.iteritems(pod.labels):
               req['metadata']['labels'][k] = v
   ```
   vs
   ```
       @staticmethod
       def extract_init_containers(pod, req):
           if pod.init_containers:
               req['spec']['initContainers'] = pod.init_containers
   ```
   
   I originally removed the tests for consistency, but I'll add them back in for cases where the function checks if the argument is truthy.

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