Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix KubernetesJobOperator.on_kill() #130

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ def on_kill(self) -> None:
kwargs = {
"name": job.metadata.name,
"namespace": job.metadata.namespace,
"job": self.hook.batch_v1_client.api_client.sanitize_for_serialization(self.job),
}
if self.termination_grace_period is not None:
kwargs.update(grace_period_seconds=self.termination_grace_period)
Expand Down
14 changes: 2 additions & 12 deletions providers/tests/cncf/kubernetes/operators/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,10 @@ def test_execute_complete_fail(self):

@pytest.mark.non_db_test_override
@patch(JOB_OPERATORS_PATH.format("KubernetesJobOperator.job_client"))
@patch(HOOK_CLASS)
def test_on_kill(self, mock_hook, mock_client):
def test_on_kill(self, mock_client):
mock_job = mock.MagicMock()
mock_job.metadata.name = JOB_NAME
mock_job.metadata.namespace = JOB_NAMESPACE
mock_serialize = mock_hook.return_value.batch_v1_client.api_client.sanitize_for_serialization
mock_serialized_job = mock_serialize.return_value

op = KubernetesJobOperator(task_id="test_task_id")
op.job = mock_job
Expand All @@ -701,19 +698,14 @@ def test_on_kill(self, mock_hook, mock_client):
mock_client.delete_namespaced_job.assert_called_once_with(
name=JOB_NAME,
namespace=JOB_NAMESPACE,
job=mock_serialized_job,
)
mock_serialize.assert_called_once_with(mock_job)

@pytest.mark.non_db_test_override
@patch(JOB_OPERATORS_PATH.format("KubernetesJobOperator.job_client"))
@patch(HOOK_CLASS)
def test_on_kill_termination_grace_period(self, mock_hook, mock_client):
def test_on_kill_termination_grace_period(self, mock_client):
mock_job = mock.MagicMock()
mock_job.metadata.name = JOB_NAME
mock_job.metadata.namespace = JOB_NAMESPACE
mock_serialize = mock_hook.return_value.batch_v1_client.api_client.sanitize_for_serialization
mock_serialized_job = mock_serialize.return_value
mock_termination_grace_period = mock.MagicMock()

op = KubernetesJobOperator(
Expand All @@ -725,10 +717,8 @@ def test_on_kill_termination_grace_period(self, mock_hook, mock_client):
mock_client.delete_namespaced_job.assert_called_once_with(
name=JOB_NAME,
namespace=JOB_NAMESPACE,
job=mock_serialized_job,
grace_period_seconds=mock_termination_grace_period,
)
mock_serialize.assert_called_once_with(mock_job)

@pytest.mark.non_db_test_override
@patch(JOB_OPERATORS_PATH.format("KubernetesJobOperator.client"))
Expand Down
Loading