Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ocp_resources/daemonset.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def delete(self, wait=False, timeout=TIMEOUT_4MINUTES, body=None):
Returns:
bool: True if delete succeeded, False otherwise.
"""
super().delete(
return super().delete(
wait=wait,
timeout=timeout,
body=kubernetes.client.V1DeleteOptions(propagation_policy="Foreground"),
Expand Down
39 changes: 39 additions & 0 deletions ocp_resources/job.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import kubernetes

from ocp_resources.constants import TIMEOUT_4MINUTES
from ocp_resources.resource import NamespacedResource


class Job(NamespacedResource):
"""
Job object.

Args:
name (str): Job name.
namespace (str): Namespace name.
client (DynamicClient): Dynamic client for connecting to a remote cluster.
teardown (bool): Indicates if this resource would need to be deleted.
privileged_client (DynamicClient): Instance of Dynamic client.
yaml_file (str): Yaml file for the resource.
delete_timeout (int): Timeout associated with delete action.
backoff_limit (int): The number of retries for a job.
restart_policy (str): The restart policy of the pod.
service_account (str): Optional. Service account name.
containers (list): List of containers belonging to the pod that the job will create.
background_propagation_policy (str): Control how object dependents will be deleted when an object is
deleted (for example the pods left behind when you delete a Job). Options are: "Background",
"Foreground" and "Orphan". Read more here:
https://kubernetes.io/docs/concepts/architecture/garbage-collection/#cascading-deletion
"""

api_group = NamespacedResource.ApiGroup.BATCH
Expand All @@ -25,6 +44,7 @@ def __init__(
restart_policy=None,
service_account=None,
containers=None,
background_propagation_policy=None,
**kwargs,
):
super().__init__(
Expand All @@ -41,6 +61,7 @@ def __init__(
self.backoff_limit = backoff_limit
self.service_account = service_account
self.containers = containers
self.background_propagation_policy = background_propagation_policy

def to_dict(self):
super().to_dict()
Expand All @@ -63,3 +84,21 @@ def to_dict(self):
self.res["spec"]["template"]["spec"][
"restartPolicy"
] = self.restart_policy

def delete(self, wait=False, timeout=TIMEOUT_4MINUTES, body=None):
"""
Delete Job object

Args:
wait (bool): True to wait for Job to be deleted.
timeout (int): Time to wait for resource deletion.
body (dict): Content to send to delete().

Returns:
bool: True if delete succeeded, False otherwise.
"""
if not body and self.background_propagation_policy:
body = kubernetes.client.V1DeleteOptions(
propagation_policy=self.background_propagation_policy
)
return super().delete(wait=wait, timeout=timeout, body=body)