You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2023/03/08 13:18:00 UTC
[airflow] 05/12: add hostname argument to DockerOperator (#27822)
This is an automated email from the ASF dual-hosted git repository.
ephraimanierobi pushed a commit to branch v2-5-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 3784f2e25bda3c33b604212949d8bfca27924e94
Author: skabbit <sk...@gmail.com>
AuthorDate: Tue Nov 29 13:08:48 2022 +0400
add hostname argument to DockerOperator (#27822)
(cherry picked from commit 1aa3da543a3f9229527a5de2807053e15b2bfea7)
---
airflow/providers/docker/operators/docker.py | 4 ++++
tests/providers/docker/operators/test_docker.py | 7 +++++++
2 files changed, 11 insertions(+)
diff --git a/airflow/providers/docker/operators/docker.py b/airflow/providers/docker/operators/docker.py
index 509713680a..e02a813024 100644
--- a/airflow/providers/docker/operators/docker.py
+++ b/airflow/providers/docker/operators/docker.py
@@ -136,6 +136,7 @@ class DockerOperator(BaseOperator):
greater than 0. If omitted uses system default.
:param tty: Allocate pseudo-TTY to the container
This needs to be set see logs of the Docker container.
+ :param hostname: Optional hostname for the container.
:param privileged: Give extended privileges to this container.
:param cap_add: Include container capabilities
:param retrieve_output: Should this docker image consistently attempt to pull from and output
@@ -194,6 +195,7 @@ class DockerOperator(BaseOperator):
auto_remove: str = "never",
shm_size: int | None = None,
tty: bool = False,
+ hostname: str | None = None,
privileged: bool = False,
cap_add: Iterable[str] | None = None,
extra_hosts: dict[str, str] | None = None,
@@ -251,6 +253,7 @@ class DockerOperator(BaseOperator):
self.docker_conn_id = docker_conn_id
self.shm_size = shm_size
self.tty = tty
+ self.hostname = hostname
self.privileged = privileged
self.cap_add = cap_add
self.extra_hosts = extra_hosts
@@ -342,6 +345,7 @@ class DockerOperator(BaseOperator):
entrypoint=self.format_command(self.entrypoint),
working_dir=self.working_dir,
tty=self.tty,
+ hostname=self.hostname,
)
logstream = self.cli.attach(container=self.container["Id"], stdout=True, stderr=True, stream=True)
try:
diff --git a/tests/providers/docker/operators/test_docker.py b/tests/providers/docker/operators/test_docker.py
index f17c6a01eb..0430e0ae2c 100644
--- a/tests/providers/docker/operators/test_docker.py
+++ b/tests/providers/docker/operators/test_docker.py
@@ -101,6 +101,7 @@ class TestDockerOperator:
host_tmp_dir="/host/airflow",
container_name="test_container",
tty=True,
+ hostname="test.contrainer.host",
device_requests=[DeviceRequest(count=-1, capabilities=[["gpu"]])],
log_opts_max_file="5",
log_opts_max_size="10m",
@@ -127,6 +128,7 @@ class TestDockerOperator:
entrypoint=["sh", "-c"],
working_dir="/container/path",
tty=True,
+ hostname="test.contrainer.host",
)
self.client_mock.create_host_config.assert_called_once_with(
mounts=[
@@ -183,6 +185,7 @@ class TestDockerOperator:
shm_size=1000,
host_tmp_dir="/host/airflow",
container_name="test_container",
+ hostname="test.contrainer.host",
tty=True,
)
operator.execute(None)
@@ -201,6 +204,7 @@ class TestDockerOperator:
entrypoint=["sh", "-c"],
working_dir="/container/path",
tty=True,
+ hostname="test.contrainer.host",
)
self.client_mock.create_host_config.assert_called_once_with(
mounts=[
@@ -294,6 +298,7 @@ class TestDockerOperator:
entrypoint=["sh", "-c"],
working_dir="/container/path",
tty=True,
+ hostname=None,
),
call(
command="env",
@@ -305,6 +310,7 @@ class TestDockerOperator:
entrypoint=["sh", "-c"],
working_dir="/container/path",
tty=True,
+ hostname=None,
),
]
)
@@ -403,6 +409,7 @@ class TestDockerOperator:
entrypoint=["sh", "-c"],
working_dir="/container/path",
tty=True,
+ hostname=None,
)
stringio_mock.assert_called_once_with("UNIT=FILE\nPRIVATE=FILE\nVAR=VALUE")
self.dotenv_mock.assert_called_once_with(stream="UNIT=FILE\nPRIVATE=FILE\nVAR=VALUE")