-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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-3937] KubernetesPodOperator support for envFrom configMapRef… #4772
[AIRFLOW-3937] KubernetesPodOperator support for envFrom configMapRef… #4772
Conversation
86ec479
to
1ecbe7d
Compare
PTAL @dimberman |
airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
Outdated
Show resolved
Hide resolved
@feng-tao what date this should be ready so it can land in 1.10.3 ? I'm asking so I could know what priority this PR should be for me. |
@ashb may know better for the date. |
airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
Outdated
Show resolved
Hide resolved
airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
Outdated
Show resolved
Hide resolved
fc971bb
to
c1b6c72
Compare
@feng-tao @ashb @pgagnon this PR is ready for review, I've incorporated most of the requested changes here. Tests are finally passing, I've added documentation. PS. I don't know how to setup unit testing locally with K8S, on my macOS, so it took me a while debugging with TravisCI. It was kinda annoying but not sure how can I fix that for future so I can run all tests locally on macOS... |
airflow/contrib/kubernetes/kubernetes_request_factory/kubernetes_request_factory.py
Outdated
Show resolved
Hide resolved
5845c4b
to
2674ede
Compare
3448241
to
d6de6ce
Compare
@ashb I've applied Your feedback, and made unittest mocked rather than calling k8s and checking values back |
@galuszkak sorry - that example wasn't so great - we now aren't actually testing the behaviour of the pod factory functions. Somewhere in the tests I'd like to see something like self.assertEqual(
SOMETHING['spec']['containers'][0]['envFrom'],
{ 'secretRef': { 'name': 'secret-name' } },
) or similar. Maybe we can do this like this: @mock.patch("airflow.contrib.kubernetes.pod_launcher.PodLauncher._monitor_pod")
@mock.patch("airflow.contrib.kubernetes.kube_client.get_kube_client")
def test_envs_from_secrets(self, client_mock, _):
# GIVEN
from airflow.utils.state import State
secrets = [Secret('env', None, "secret_name")]
mock_resp = MagicMock()
mock_resp.status.start_time = datetime.now()
client_mock.create_namespaced_pod.return_value = mock_resp
# WHEN
k = KubernetesPodOperator(
namespace='default',
image="ubuntu:16.04",
cmds=["bash", "-cx"],
arguments=["echo 10"],
secrets=secrets,
labels={"foo": "bar"},
name="test",
task_id="task",
)
k.execute(None)
# THEN
req = client_mock.create_namespaced_pod.call_args[0][1]['req']
self.assertEqual(
req['spec']['containers'][0]['envFrom'],
{ 'secretRef': { 'name': 'secret-name' } },
) Note: this is untested, and we may need to mock some extra methods |
d6de6ce
to
ab17857
Compare
@ashb can I understand reasoning behind that, why we want to test that now? None of the tests were testing output of KubernetesRequestFactory before, only classes like Pod/PodLauncher to check if fields there are correct. If we want to start testing that, I believe there should be separate ticket to make sure we cover most of the cases of outputs of KubernetesRequestFactory that is actually producing what we want in every case. Because for now there isn't single assertion on product of that class, only abstraction on top of it. |
@dimberman Final thoughts? I'm okay leaving my requested test change to #4952. |
2927aac
to
3c26b94
Compare
@ashb @dimberman hope now it's good to go! I've applied requested changes. |
709a8d0
to
32bb442
Compare
@ashb I've rebase Your changes. |
Thanks - if I was paying more attention I could have merged it (and squashed it) on Github. The reason Why I changed it from |
For me But I get Your point, I think this is just part of preference, how to think about API design. |
Oh I didn't know that |
@ashb I agree, I just take literally what @dimberman wanted as he would like this as Thanks for hard work, and a lot of those code review. It was a really good experience for me, although a little longer than expected ;). Again thank You! |
Thanks for merging it! Big thanks for support and help for @FlyrInc ! |
… and secretRef
Make sure you have checked all steps below.
Jira
Description
Tests
Documentation
Code Quality
flake8