Skip to content

Commit 0bb9472

Browse files
authored
Refactor job and daemonset resources (RedHatQE#1101)
- Add args to the docstring. - Allow background propagation policy in delete(). - Refactor daemonset.py delete() to return the result. Signed-off-by: Anat Wax <[email protected]>
1 parent 02e2bf1 commit 0bb9472

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

ocp_resources/daemonset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def delete(self, wait=False, timeout=TIMEOUT_4MINUTES, body=None):
5454
Returns:
5555
bool: True if delete succeeded, False otherwise.
5656
"""
57-
super().delete(
57+
return super().delete(
5858
wait=wait,
5959
timeout=timeout,
6060
body=kubernetes.client.V1DeleteOptions(propagation_policy="Foreground"),

ocp_resources/job.py

+39
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
import kubernetes
2+
13
from ocp_resources.constants import TIMEOUT_4MINUTES
24
from ocp_resources.resource import NamespacedResource
35

46

57
class Job(NamespacedResource):
68
"""
79
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
827
"""
928

1029
api_group = NamespacedResource.ApiGroup.BATCH
@@ -25,6 +44,7 @@ def __init__(
2544
restart_policy=None,
2645
service_account=None,
2746
containers=None,
47+
background_propagation_policy=None,
2848
**kwargs,
2949
):
3050
super().__init__(
@@ -41,6 +61,7 @@ def __init__(
4161
self.backoff_limit = backoff_limit
4262
self.service_account = service_account
4363
self.containers = containers
64+
self.background_propagation_policy = background_propagation_policy
4465

4566
def to_dict(self):
4667
super().to_dict()
@@ -63,3 +84,21 @@ def to_dict(self):
6384
self.res["spec"]["template"]["spec"][
6485
"restartPolicy"
6586
] = 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

Comments
 (0)