Skip to content

Commit

Permalink
Bugfix KubernetesJobOperator.on_kill()
Browse files Browse the repository at this point in the history
  • Loading branch information
moiseenkov committed Nov 15, 2024
1 parent 123dadd commit e750cd4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
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

0 comments on commit e750cd4

Please sign in to comment.