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

Adds option to disable mounting temporary folder in DockerOperator #16932

Merged
merged 3 commits into from
Jul 15, 2021

Conversation

potiuk
Copy link
Member

@potiuk potiuk commented Jul 11, 2021

The DockerOperator by default mounts temporary folder to inside
the container in order to allow to store files bigger than
default size of disk for the container, however this did not work
when remote Docker engine or Docker-In-Docker solution was used.

This worked before the #15843 change, because the /tmp has
been ignored, however when we change to "Mounts", the "/tmp"
mount fails when using remote docker engine.

This PR adds parameter that allows to disable this temporary
directory mounting (and adds a note that it can be replaced
with mounting existing volumes). Also it prints a warning
if the directory cannot be mounted and attempts to re-run
such failed attempt without mounting the temporary
directory which brings back backwards-compatible behaviour
for remote engines and docker-in-docker.

Fixes: #16803
Fixes: #16806


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

@potiuk
Copy link
Member Author

potiuk commented Jul 12, 2021

Hey @uranusjr @mik-laj @akki -> this turned out to be a bit of aftermath after #15843 - seems that remote docker engine or docker-in-docker case are broken in the new provider 2.0.0. I am not 100% sure if the fix I provided is good enough - it's essentially a breaking change for those cases. Not sure if we can do it more transparently ?

Copy link
Contributor

@akki akki left a comment

Choose a reason for hiding this comment

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

Added a suggestion.

airflow/providers/docker/operators/docker.py Show resolved Hide resolved
Copy link
Contributor

@akki akki left a comment

Choose a reason for hiding this comment

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

Oops, selected "requested changes" by mistake.
I don't have a strong opinion about the solution proposed in this PR yet.

@potiuk potiuk force-pushed the optional-temp-dir-mounting-in-docker branch from d8c96c7 to 812fb57 Compare July 14, 2021 11:04
@potiuk potiuk requested a review from ashb as a code owner July 14, 2021 11:04
@potiuk potiuk force-pushed the optional-temp-dir-mounting-in-docker branch from 812fb57 to e5738ec Compare July 14, 2021 12:59
@potiuk
Copy link
Member Author

potiuk commented Jul 14, 2021

Hey @uranusjr @akki - I think this version is a bit better.

In this version you can still disable the temporary mount, but also I brought in the fallback - in case we run the docker command and it fails (and from the message we suspect it is about this problem) we try again without mounting (and without setting the _TMP variable) - we also log warning in this case. I think that should brig the old behaviour back (with slight overhead/performance hit), while also adding flexibility to disable the /tmp mount and a warning when it should be disabled.

I'd love to merge this one rather quickly as this is the last 'serious' provider change I think is "urgent-ish" to merge before releasing the next wave of providers.

The DockerOperator by default mounts temporary folder to inside
the container in order to allow to store files bigger than
default size of disk for the container, however this did not work
when remote Docker engine or Docker-In-Docker solution was used.

This worked before the apache#15843 change, because the /tmp has
been ignored, however when we change to "Mounts", the "/tmp"
mount fails when using remote docker engine.

This PR adds parameter that allows to disable this temporary
directory mounting (and adds a note that it can be replaced
with mounting existing volumes). Also it prints a warning
if the directory cannot be mounted and attempts to re-run
such failed attempt without mounting the temporary
directory which brings back backwards-compatible behaviour
for remote engines and docker-in-docker.

Fixes: apache#16803
Fixes: apache#16806
@potiuk potiuk force-pushed the optional-temp-dir-mounting-in-docker branch from e5738ec to e36f703 Compare July 14, 2021 14:18
@raphaelauv
Copy link
Contributor

raphaelauv commented Jul 14, 2021

Since it's from 2.0.0 let's consider the mount of the tmp folder the default pattern and simply add an option to disable it in case of docker in docker

I prefer to keep the operator KISS, so it should not retry in case of bad configuration.

Thanks @potiuk for writing a fix 👍

@uranusjr
Copy link
Member

uranusjr commented Jul 15, 2021

The cause to the failure is that old binds thing automatically create an empty directory if the host path does not exist; the new mounts thing does not do that, but fails loudly (a delibrate decision made by Docker to prevent subtle bugs just like this). So the previous implementation isn’t really working either, but broken in a different way, the apparently-mounted temporary directory was actually not able to be used when used in the Docker-in-Docker setup. So in a way this is catching a subtle bug that went unnoticed previously.

So IMO your fix makes sense. The temporary directory thing won’t work for the Docker-in-Docker setup anyway, so an additional argument makes sense. This should also be recorded in the 2.0 changelog; not in the way proposed in #17008, but something like “previously the temporary directory mount was silently failing when [not sure what best to put here], now it will fail loudly and you must explicitly pass mount_tmp_dir=False when you don’t need the temporary directory”. And maybe we can also deprecate the implicit mount_tmp_dir=True behaviour and switch to not mount the temporary directory by default in 3.0.

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

Change is good as-is, the changelog addition can be done either here or in another PR.

@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Jul 15, 2021
@potiuk
Copy link
Member Author

potiuk commented Jul 15, 2021

Change is good as-is, the changelog addition can be done either here or in another PR.

Yep. I will add the changelog when preparing provider's release.

@potiuk
Copy link
Member Author

potiuk commented Jul 15, 2021

The cause to the failure is that old binds thing automatically create an empty directory if the host path does not exist; the new mounts thing does not do that, but fails loudly (a delibrate decision made by Docker to prevent subtle bugs just like this). So the previous implementation isn’t really working either, but broken in a different way, the apparently-mounted temporary directory was actually not able to be used when used in the Docker-in-Docker setup. So in a way this is catching a subtle bug that went unnoticed previously.

Make perfect sense :). And also I think in this case, it is much better to give the user an explicit decision on the mounting. With this approach, you can make your own decisions how to prepare the kind of "temporary" folder you want to use - you can use tmpfs volume if you have plenty of memory, you can use existing volume, or let the engine create the volume for you.

@potiuk potiuk merged commit bc00415 into apache:main Jul 15, 2021
@potiuk potiuk deleted the optional-temp-dir-mounting-in-docker branch July 15, 2021 04:35
@potiuk
Copy link
Member Author

potiuk commented Jul 15, 2021

I prefer to keep the operator KISS, so it should not retry in case of bad configuration.

I thought about it, and I think I prefer to have this retry mechanism for at least some time (until the next major version bump). The reason is that we really try hard to keep to the spirit of the SemVer, and we have a clear regression that was not the reason for the 2.0.0 bump and user should expect not to have to modify their dags. So 2.1.0 will come with a fix and then provider 2.1.0 will work 'same' way for vast majority of cases. The "temporary folder" approach was not needed by everyone (it seems to address a very specific case). And it was not really working as expected anyway in case of remote/dind. Here we have at least clear warning and indication that the parameters should be updated. Also the fact that the variable is not set in this case might make the container to fail, but in this case it is good, because it will reveal the subtle bug which was hidden before.

@potiuk
Copy link
Member Author

potiuk commented Jul 15, 2021

Release notes added: #17015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:providers okay to merge It's ok to merge this PR as it does not require more tests
Projects
None yet
4 participants