def test_pending_pod_timeout_multi_namespace_mode( self, mock_kubescheduler, mock_get_kube_client, mock_kubernetes_job_watcher): mock_delete_pod = mock_kubescheduler.return_value.delete_pod mock_kube_client = mock_get_kube_client.return_value now = timezone.utcnow() pending_pods = [ k8s.V1Pod(metadata=k8s.V1ObjectMeta( name="foo90", labels={"airflow-worker": "123"}, creation_timestamp=now - timedelta(seconds=500), namespace="anothernamespace", )), ] mock_kube_client.list_pod_for_all_namespaces.return_value.items = pending_pods config = { ('kubernetes', 'namespace'): 'mynamespace', ('kubernetes', 'multi_namespace_mode'): 'true', ('kubernetes', 'kube_client_request_args'): '{"sentinel": "foo"}', } with conf_vars(config): executor = KubernetesExecutor() executor.job_id = "123" executor.start() executor._check_worker_pods_pending_timeout() mock_kube_client.list_pod_for_all_namespaces.assert_called_once_with( field_selector='status.phase=Pending', label_selector='airflow-worker=123', limit=100, sentinel='foo', ) mock_delete_pod.assert_called_once_with('foo90', 'anothernamespace')
def test_delete_pod_successfully(self, mock_watcher, mock_client, mock_kube_client): # pylint: disable=unused-argument pod_id = "my-pod-1" namespace = "my-namespace-1" mock_delete_namespace = mock.MagicMock() mock_kube_client.return_value.delete_namespaced_pod = mock_delete_namespace kube_executor = KubernetesExecutor() kube_executor.job_id = "test-job-id" kube_executor.start() kube_executor.kube_scheduler.delete_pod(pod_id, namespace) mock_delete_namespace.assert_called_with( pod_id, namespace, body=mock_client.V1DeleteOptions())
def test_delete_pod_404_not_raised(self, mock_watcher, mock_client, mock_kube_client): # pylint: disable=unused-argument pod_id = "my-pod-1" namespace = "my-namespace-3" mock_delete_namespace = mock.MagicMock() mock_kube_client.return_value.delete_namespaced_pod = mock_delete_namespace # ApiException not raised because the status is 404 mock_kube_client.return_value.delete_namespaced_pod.side_effect = ApiException( status=404) kube_executor = KubernetesExecutor() kube_executor.job_id = "test-job-id" kube_executor.start() kube_executor.kube_scheduler.delete_pod(pod_id, namespace) mock_delete_namespace.assert_called_with( pod_id, namespace, body=mock_client.V1DeleteOptions())