Skip to content
Merged
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
12 changes: 12 additions & 0 deletions airflow/providers/cncf/kubernetes/operators/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ class KubernetesPodOperator(BaseOperator):
:param security_context: security options the pod should run with (PodSecurityContext).
:param container_security_context: security options the container should run with.
:param dnspolicy: dnspolicy for the pod.
:param dns_config: dns configuration (ip addresses, searches, options) for the pod.
:param hostname: hostname for the pod.
:param subdomain: subdomain for the pod.
:param schedulername: Specify a schedulername for the pod
:param full_pod_spec: The complete podSpec
:param init_containers: init container for the launched Pod
Expand Down Expand Up @@ -282,6 +285,9 @@ def __init__(
security_context: dict | None = None,
container_security_context: dict | None = None,
dnspolicy: str | None = None,
dns_config: k8s.V1PodDNSConfig | None = None,
hostname: str | None = None,
subdomain: str | None = None,
Comment on lines +288 to +290
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add these parameters to the docstring above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I had forgotten to add them. I have added them now.

schedulername: str | None = None,
full_pod_spec: k8s.V1Pod | None = None,
init_containers: list[k8s.V1Container] | None = None,
Expand Down Expand Up @@ -351,6 +357,9 @@ def __init__(
self.security_context = security_context or {}
self.container_security_context = container_security_context
self.dnspolicy = dnspolicy
self.dns_config = dns_config
self.hostname = hostname
self.subdomain = subdomain
self.schedulername = schedulername
self.full_pod_spec = full_pod_spec
self.init_containers = init_containers or []
Expand Down Expand Up @@ -812,8 +821,11 @@ def build_pod_request_obj(self, context: Context | None = None) -> k8s.V1Pod:
image_pull_secrets=self.image_pull_secrets,
service_account_name=self.service_account_name,
host_network=self.hostnetwork,
hostname=self.hostname,
subdomain=self.subdomain,
security_context=self.security_context,
dns_policy=self.dnspolicy,
dns_config=self.dns_config,
scheduler_name=self.schedulername,
restart_policy="Never",
priority_class_name=self.priority_class_name,
Expand Down
35 changes: 35 additions & 0 deletions tests/providers/cncf/kubernetes/operators/test_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,41 @@ def test_find_pod_labels(self):
"already_checked!=True,!airflow-worker"
)

@patch(HOOK_CLASS, new=MagicMock)
def test_pod_dns_options(self):
dns_config = k8s.V1PodDNSConfig(
nameservers=["192.0.2.1", "192.0.2.3"],
searches=["ns1.svc.cluster-domain.example", "my.dns.search.suffix"],
options=[
k8s.V1PodDNSConfigOption(
name="ndots",
value="2",
)
],
)
hostname = "busybox-2"
subdomain = "busybox-subdomain"

k = KubernetesPodOperator(
namespace="default",
image="ubuntu:16.04",
cmds=["bash", "-cx"],
labels={"foo": "bar"},
name="test",
task_id="task",
in_cluster=False,
do_xcom_push=False,
dns_config=dns_config,
hostname=hostname,
subdomain=subdomain,
)

self.run_pod(k)
pod_spec = k.pod.spec
assert pod_spec.dns_config == dns_config
assert pod_spec.subdomain == subdomain
assert pod_spec.hostname == hostname

@pytest.mark.parametrize(
"val",
[
Expand Down