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

Remove references to deepcopied object attributes #20318

Merged
merged 1 commit into from Dec 15, 2021

Conversation

BasPH
Copy link
Contributor

@BasPH BasPH commented Dec 15, 2021

Encountered a nasty bug where somebody basically implemented their own KubernetesPodSensor, which failed after more than one attempt when using mode="poke" + a volume + a secret.

Root cause turned out to be in secret.attach_to_pod(). In here, a volume and volumemount is created to mount the secret. A deepcopy() is made of the given Pod spec. In order to avoid appending to None, there is this line: cp_pod.spec.volumes = pod.spec.volumes or []. In case a volume is set on the Pod spec, a reference is created to the original pod spec volumes, which in turn was a reference to self.volumes. As a result, each secret resulted in a volume added to self.volumes, which resulted in an error when running the sensor a second time because the secret volume was already mounted during the first sensor attempt.

This PR references the deepcopied object instead, and creates a new list if pod.spec.volumes is None.


^ 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.

@boring-cyborg boring-cyborg bot added the provider:cncf-kubernetes Kubernetes provider related issues label Dec 15, 2021
@github-actions
Copy link

The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the full tests needed We need to run full set of tests for this PR to merge label Dec 15, 2021
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Nice One.

@kaxil kaxil merged commit 2409760 into apache:main Dec 15, 2021
@BasPH BasPH deleted the dont-set-references-to-deepcopied-object branch December 16, 2021 07:28
@jedcunningham jedcunningham added this to the Airflow 2.2.4 milestone Dec 21, 2021
@jedcunningham jedcunningham added the type:bug-fix Changelog: Bug Fixes label Dec 21, 2021
jedcunningham pushed a commit that referenced this pull request Jan 21, 2022
)

Encountered a nasty bug where somebody basically implemented their own KubernetesPodSensor, which failed after more than one attempt when using mode="poke" + a volume + a secret.

Root cause turned out to be in `secret.attach_to_pod()`. In here, a volume and volumemount is created to mount the secret. A deepcopy() is made of the given Pod spec. In order to avoid appending to None, there is this line: `cp_pod.spec.volumes = pod.spec.volumes or []`. In case a volume is set on the Pod spec, a reference is created to the original pod spec volumes, which in turn was a reference to `self.volumes`. As a result, each secret resulted in a volume added to `self.volumes`, which resulted in an error when running the sensor a second time because the secret volume was already mounted during the first sensor attempt.

This PR references the deepcopied object instead, and creates a new list if pod.spec.volumes is None.

Co-authored-by: Bas Harenslak <bas@astronomer.io>
(cherry picked from commit 2409760)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full tests needed We need to run full set of tests for this PR to merge provider:cncf-kubernetes Kubernetes provider related issues type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants