-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjob.py
More file actions
44 lines (37 loc) · 1.59 KB
/
job.py
File metadata and controls
44 lines (37 loc) · 1.59 KB
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
from scheduler.resources import Resource
from scheduler.exceptions import KubeHTTPException
class Job(Resource):
api_prefix = 'apis'
api_version = 'batch/v1'
def manifest(self, namespace, name, image, entrypoint, command, **kwargs):
manifest = {
"apiVersion": "batch/v1",
"kind": "Job",
"metadata": {
"name": name,
'labels': {
'app': namespace,
'type': kwargs.get('app_type', 'run'),
'heritage': 'drycc',
},
},
"spec": {
"backoffLimit": kwargs.get('backoff_limit', 0),
"activeDeadlineSeconds": kwargs.get('active_deadline_seconds', 3600),
"ttlSecondsAfterFinished": kwargs.get('ttl_seconds_after_finished', 86400),
}
}
# tell pod how to execute the process
kwargs['command'] = entrypoint
kwargs['args'] = command
# pod manifest spec
manifest['spec']['template'] = self.pod.manifest(namespace, name, image, **kwargs)
return manifest
def create(self, namespace, name, image, entrypoint,
command, ignore_exception=False, **kwargs):
data = self.manifest(namespace, name, image, entrypoint, command, **kwargs)
url = self.api("/namespaces/{}/jobs", namespace)
response = self.http_post(url, json=data)
if not ignore_exception and self.unhealthy(response.status_code):
raise KubeHTTPException(response, "create Job {}".format(namespace))
return response