def stop(backend_job_id, asynchronous=True): """Stop Kubernetes job execution. :param backend_job_id: Kubernetes job id. :param asynchronous: Whether the function waits for the action to be performed or does it asynchronously. """ try: propagation_policy = 'Background' if asynchronous else 'Foreground' delete_options = V1DeleteOptions( propagation_policy=propagation_policy) current_k8s_batchv1_api_client.delete_namespaced_job( backend_job_id, K8S_DEFAULT_NAMESPACE, body=delete_options) except ApiException as e: logging.error( 'An error has occurred while connecting to Kubernetes API ' 'Server \n {}'.format(e)) raise ComputingBackendSubmissionError(e.reason)
def k8s_delete_job(job, asynchronous=True): """Delete Kubernetes job. :param job: The :class:`kubernetes.client.models.v1_job.V1Job` to be deleted. :param asynchronous: Whether the function waits for the action to be performed or does it asynchronously. """ try: propagation_policy = 'Background' if asynchronous else 'Foreground' delete_options = V1DeleteOptions(propagation_policy=propagation_policy) current_k8s_batchv1_api_client.delete_namespaced_job( job.metadata.name, job.metadata.namespace, delete_options) except ApiException as e: logging.error( 'An error has occurred while connecting to Kubernetes API Server' ' \n {}'.format(e)) raise ComputingBackendSubmissionError(e.reason)