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

DockerOperator extra_hosts argument support added #10546

Merged
merged 2 commits into from
Aug 27, 2020

Conversation

bryzgaloff
Copy link
Contributor

Added support for extra_hosts argument (docs) which is equivalent to --add-host flag for docker run command (docs).

Covered with tests. Also includes minor enhancements to DockerOperator tests: common code is moved to a setUp method which makes code cleaner and reduces duplication.

@boring-cyborg
Copy link

boring-cyborg bot commented Aug 25, 2020

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: [email protected]
    Slack: https://apache-airflow-slack.herokuapp.com/

@bryzgaloff bryzgaloff changed the title Feature/docker operator extra hosts DockerOperator extra_hosts argument support added Aug 25, 2020
Copy link
Member

@kaxil kaxil left a comment

Choose a reason for hiding this comment

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

Can you rebase your PR on latest master please

@bryzgaloff bryzgaloff force-pushed the feature/docker-operator-extra-hosts branch from 7265839 to 0093e7f Compare August 26, 2020 10:49
@bryzgaloff
Copy link
Contributor Author

@kaxil rebased. I have also fixed up codereview-related commit. So the code is now ready to be merged.

@bryzgaloff bryzgaloff force-pushed the feature/docker-operator-extra-hosts branch from 0093e7f to 22b561c Compare August 26, 2020 11:28
Comment on lines 254 to 263
hosts_obj = mock.Mock()
operator = \
DockerOperator(task_id='test', image='test', extra_hosts=hosts_obj)
operator.execute(None)
self.client_mock.create_container.assert_called_once()
self.assertIn(
'host_config',
self.client_mock.create_container.call_args.kwargs,
)
self.assertIn(
'extra_hosts',
self.client_mock.create_host_config.call_args.kwargs,
)
self.assertIs(
hosts_obj,
self.client_mock.create_host_config.call_args.kwargs['extra_hosts'],
)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of passing mock object to hosts_obj why not pass a dictionary and check that it is used in mock_call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we do not need to know which type extra_hosts argument is of.just need to check that it is successfully passed to create_host_config call whatever the type is.

@bryzgaloff bryzgaloff force-pushed the feature/docker-operator-extra-hosts branch from 22b561c to 58dbd8e Compare August 27, 2020 04:09
@bryzgaloff
Copy link
Contributor Author

Rerun black to pass CI/CD check.

@bryzgaloff
Copy link
Contributor Author

@kaxil @mik-laj will you please leave your review or give an approval? All checks have passed, all the comments are resolved.

@kaxil kaxil merged commit 2e56ee7 into apache:master Aug 27, 2020
@boring-cyborg
Copy link

boring-cyborg bot commented Aug 27, 2020

Awesome work, congrats on your first merged pull request!

@bryzgaloff
Copy link
Contributor Author

Woooo, guys, thank you, it's an awesome experience ^_^

@kaxil
Copy link
Member

kaxil commented Aug 27, 2020

Good work @bryzgaloff , hope to see more of your contributions and thank you for this PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants