airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject [13/16] incubator-airflow git commit: [AIRFLOW-1517] Restore authorship of resources
Date Fri, 12 Jan 2018 18:03:13 GMT
[AIRFLOW-1517] Restore authorship of resources

Collaboration authors got destroyed when splitting up a PR, this commit adds back in the code
which was be removed in the previous commit to restore authorship


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/28d9d7f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/28d9d7f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/28d9d7f0

Branch: refs/heads/master
Commit: 28d9d7f00f3789e02702db969c1b19fdc16ef968
Parents: 540b724
Author: GRANT NICHOLAS <gnicholas@homeaway.com>
Authored: Thu Dec 28 14:39:48 2017 -0600
Committer: Daniel Imberman <danielryan2430@gmail.com>
Committed: Thu Jan 11 15:29:17 2018 -0800

----------------------------------------------------------------------
 .../kubernetes_request_factory.py               | 33 ++++++++++++++++++--
 airflow/contrib/kubernetes/pod.py               | 19 +++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/28d9d7f0/airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
----------------------------------------------------------------------
diff --git a/airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
b/airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
index 0324781..cbf3fce 100644
--- a/airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
+++ b/airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
@@ -40,6 +40,10 @@ class KubernetesRequestFactory:
     def extract_image(pod, req):
         req['spec']['containers'][0]['image'] = pod.image
 
+    @staticmethod
+    def extract_image_pull_policy(pod, req):
+        if pod.image_pull_policy:
+            req['spec']['containers'][0]['imagePullPolicy'] = pod.image_pull_policy
 
     @staticmethod
     def add_secret_to_env(env, secret):
@@ -72,7 +76,9 @@ class KubernetesRequestFactory:
         if len(pod.node_selectors) > 0:
             req['spec']['nodeSelector'] = pod.node_selectors
 
-
+    @staticmethod
+    def attach_volumes(pod, req):
+        req['spec']['volumes'] = pod.volumes
 
     @staticmethod
     def attach_volume_mounts(pod, req):
@@ -116,7 +122,30 @@ class KubernetesRequestFactory:
                 KubernetesRequestFactory.add_secret_to_env(env, secret)
             req['spec']['containers'][0]['env'] = env
 
-
+    @staticmethod
+    def extract_resources(pod, req):
+        if not pod.resources or pod.resources.is_empty_resource_request():
+            return
+
+        req['spec']['containers'][0]['resources'] = {}
+
+        if pod.resources.has_requests():
+            req['spec']['containers'][0]['resources']['requests'] = {}
+            if pod.resources.request_memory:
+                req['spec']['containers'][0]['resources']['requests'][
+                    'memory'] = pod.resources.request_memory
+            if pod.resources.request_cpu:
+                req['spec']['containers'][0]['resources']['requests'][
+                    'cpu'] = pod.resources.request_cpu
+
+        if pod.resources.has_limits():
+            req['spec']['containers'][0]['resources']['limits'] = {}
+            if pod.resources.request_memory:
+                req['spec']['containers'][0]['resources']['limits'][
+                    'memory'] = pod.resources.limit_memory
+            if pod.resources.request_cpu:
+                req['spec']['containers'][0]['resources']['limits'][
+                    'cpu'] = pod.resources.limit_cpu
 
     @staticmethod
     def extract_init_containers(pod, req):

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/28d9d7f0/airflow/contrib/kubernetes/pod.py
----------------------------------------------------------------------
diff --git a/airflow/contrib/kubernetes/pod.py b/airflow/contrib/kubernetes/pod.py
index ba6ac06..d80b626 100644
--- a/airflow/contrib/kubernetes/pod.py
+++ b/airflow/contrib/kubernetes/pod.py
@@ -16,7 +16,26 @@
 # under the License.
 
 
+class Resources:
+    def __init__(
+            self,
+            request_memory=None,
+            request_cpu=None,
+            limit_memory=None,
+            limit_cpu=None):
+        self.request_memory = request_memory
+        self.request_cpu = request_cpu
+        self.limit_memory = limit_memory
+        self.limit_cpu = limit_cpu
+
+    def is_empty_resource_request(self):
+        return not self.has_limits() and not self.has_requests()
+
+    def has_limits(self):
+        return self.limit_cpu is not None or self.limit_memory is not None
 
+    def has_requests(self):
+        return self.request_cpu is not None or self.request_memory is not None
 
 
 class Pod:


Mime
View raw message