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

[AIRFLOW-3251] KubernetesPodOperator does not use 'image_pull_secrets… #4188

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions airflow/contrib/kubernetes/pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Pod:
:type result: any
:param image_pull_policy: Specify a policy to cache or always pull an image
:type image_pull_policy: str
:param image_pull_secrets: Any image pull secrets to be given to the pod.
If more than one secret is required, provide a
comma separated list: secret_a,secret_b
:type image_pull_secrets: str
:param affinity: A dict containing a group of affinity scheduling rules
:type affinity: dict
"""
Expand Down
7 changes: 7 additions & 0 deletions airflow/contrib/operators/kubernetes_pod_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class KubernetesPodOperator(BaseOperator):
:param arguments: arguments of to the entrypoint. (templated)
The docker image's CMD is used if this is not provided.
:type arguments: list of str
:param image_pull_policy: Specify a policy to cache or always pull an image
:type image_pull_policy: str
:param image_pull_secrets: Any image pull secrets to be given to the pod.
If more than one secret is required, provide a
comma separated list: secret_a,secret_b
:type image_pull_secrets: str
:param volume_mounts: volumeMounts for launched pod
:type volume_mounts: list of VolumeMount
:param volumes: volumes for launched pod. Includes ConfigMaps and PersistentVolumes
Expand Down Expand Up @@ -108,6 +114,7 @@ def execute(self, context):
pod.secrets = self.secrets
pod.envs = self.env_vars
pod.image_pull_policy = self.image_pull_policy
pod.image_pull_secrets = self.image_pull_secrets
pod.annotations = self.annotations
pod.resources = self.resources
pod.affinity = self.affinity
Expand Down
23 changes: 23 additions & 0 deletions tests/contrib/minikube/test_kubernetes_pod_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ def test_config_path(self, client_mock, launcher_mock):
cluster_context='default',
config_file=file_path)

@mock.patch("airflow.contrib.kubernetes.pod_launcher.PodLauncher.run_pod")
@mock.patch("airflow.contrib.kubernetes.kube_client.get_kube_client")
def test_image_pull_secrets_correctly_set(self, client_mock, launcher_mock):
from airflow.utils.state import State

fake_pull_secrets = "fakeSecret"
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
labels={"foo": "bar"},
name="test",
task_id="task",
image_pull_secrets=fake_pull_secrets,
in_cluster=False,
cluster_context='default'
)
launcher_mock.return_value = (State.SUCCESS, None)
k.execute(None)
self.assertEqual(launcher_mock.call_args[0][0].image_pull_secrets,
fake_pull_secrets)

@staticmethod
def test_working_pod():
k = KubernetesPodOperator(
Expand Down