forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pod.py
145 lines (136 loc) · 5.25 KB
/
pod.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# 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.
class Resources:
def __init__(
self,
request_memory=None,
request_cpu=None,
limit_memory=None,
limit_cpu=None,
limit_gpu=None):
self.request_memory = request_memory
self.request_cpu = request_cpu
self.limit_memory = limit_memory
self.limit_cpu = limit_cpu
self.limit_gpu = limit_gpu
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 or self.limit_gpu is not None
def has_requests(self):
return self.request_cpu is not None or self.request_memory is not None
class Port:
def __init__(
self,
name=None,
container_port=None):
self.name = name
self.container_port = container_port
class Pod:
"""
Represents a kubernetes pod and manages execution of a single pod.
:param image: The docker image
:type image: str
:param envs: A dict containing the environment variables
:type envs: dict
:param cmds: The command to be run on the pod
:type cmds: list[str]
:param secrets: Secrets to be launched to the pod
:type secrets: list[airflow.contrib.kubernetes.secret.Secret]
:param result: The result that will be returned to the operator after
successful execution of the pod
:type result: any
:param image_pull_policy: Specify a policy to cache or always pull an image
:type image_pull_policy: str
:param image_pull_secrets: Any image pull secrets to be given to the pod.
If more than one secret is required, provide a comma separated list:
secret_a,secret_b
:type image_pull_secrets: str
:param affinity: A dict containing a group of affinity scheduling rules
:type affinity: dict
:param hostnetwork: If True enable host networking on the pod
:type hostnetwork: bool
:param tolerations: A list of kubernetes tolerations
:type tolerations: list
:param security_context: A dict containing the security context for the pod
:type security_context: dict
:param configmaps: A list containing names of configmaps object
mounting env variables to the pod
:type configmaps: list[str]
:param pod_runtime_info_envs: environment variables about
pod runtime information (ip, namespace, nodeName, podName)
:type pod_runtime_info_envs: list[PodRuntimeEnv]
:param dnspolicy: Specify a dnspolicy for the pod
:type dnspolicy: str
"""
def __init__(
self,
image,
envs,
cmds,
args=None,
secrets=None,
labels=None,
node_selectors=None,
name=None,
ports=None,
volumes=None,
volume_mounts=None,
namespace='default',
result=None,
image_pull_policy='IfNotPresent',
image_pull_secrets=None,
init_containers=None,
service_account_name=None,
resources=None,
annotations=None,
affinity=None,
hostnetwork=False,
tolerations=None,
security_context=None,
configmaps=None,
pod_runtime_info_envs=None,
dnspolicy=None,
priority_class=None
):
self.image = image
self.envs = envs or {}
self.cmds = cmds
self.args = args or []
self.secrets = secrets or []
self.result = result
self.labels = labels or {}
self.name = name
self.ports = ports or []
self.volumes = volumes or []
self.volume_mounts = volume_mounts or []
self.node_selectors = node_selectors or {}
self.namespace = namespace
self.image_pull_policy = image_pull_policy
self.image_pull_secrets = image_pull_secrets
self.init_containers = init_containers
self.service_account_name = service_account_name
self.resources = resources or Resources()
self.annotations = annotations or {}
self.affinity = affinity or {}
self.hostnetwork = hostnetwork or False
self.tolerations = tolerations or []
self.security_context = security_context
self.configmaps = configmaps or []
self.pod_runtime_info_envs = pod_runtime_info_envs or []
self.dnspolicy = dnspolicy
self.priority_class = priority_class