1
+ import kubernetes
2
+
1
3
from ocp_resources .constants import TIMEOUT_4MINUTES
2
4
from ocp_resources .resource import NamespacedResource
3
5
4
6
5
7
class Job (NamespacedResource ):
6
8
"""
7
9
Job object.
10
+
11
+ Args:
12
+ name (str): Job name.
13
+ namespace (str): Namespace name.
14
+ client (DynamicClient): Dynamic client for connecting to a remote cluster.
15
+ teardown (bool): Indicates if this resource would need to be deleted.
16
+ privileged_client (DynamicClient): Instance of Dynamic client.
17
+ yaml_file (str): Yaml file for the resource.
18
+ delete_timeout (int): Timeout associated with delete action.
19
+ backoff_limit (int): The number of retries for a job.
20
+ restart_policy (str): The restart policy of the pod.
21
+ service_account (str): Optional. Service account name.
22
+ containers (list): List of containers belonging to the pod that the job will create.
23
+ background_propagation_policy (str): Control how object dependents will be deleted when an object is
24
+ deleted (for example the pods left behind when you delete a Job). Options are: "Background",
25
+ "Foreground" and "Orphan". Read more here:
26
+ https://kubernetes.io/docs/concepts/architecture/garbage-collection/#cascading-deletion
8
27
"""
9
28
10
29
api_group = NamespacedResource .ApiGroup .BATCH
@@ -25,6 +44,7 @@ def __init__(
25
44
restart_policy = None ,
26
45
service_account = None ,
27
46
containers = None ,
47
+ background_propagation_policy = None ,
28
48
** kwargs ,
29
49
):
30
50
super ().__init__ (
@@ -41,6 +61,7 @@ def __init__(
41
61
self .backoff_limit = backoff_limit
42
62
self .service_account = service_account
43
63
self .containers = containers
64
+ self .background_propagation_policy = background_propagation_policy
44
65
45
66
def to_dict (self ):
46
67
super ().to_dict ()
@@ -63,3 +84,21 @@ def to_dict(self):
63
84
self .res ["spec" ]["template" ]["spec" ][
64
85
"restartPolicy"
65
86
] = self .restart_policy
87
+
88
+ def delete (self , wait = False , timeout = TIMEOUT_4MINUTES , body = None ):
89
+ """
90
+ Delete Job object
91
+
92
+ Args:
93
+ wait (bool): True to wait for Job to be deleted.
94
+ timeout (int): Time to wait for resource deletion.
95
+ body (dict): Content to send to delete().
96
+
97
+ Returns:
98
+ bool: True if delete succeeded, False otherwise.
99
+ """
100
+ if not body and self .background_propagation_policy :
101
+ body = kubernetes .client .V1DeleteOptions (
102
+ propagation_policy = self .background_propagation_policy
103
+ )
104
+ return super ().delete (wait = wait , timeout = timeout , body = body )
0 commit comments