-
Notifications
You must be signed in to change notification settings - Fork 59
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
fix: include parent directories when listing archive members #435
Conversation
Zip archives can omit files' parent directories, as they will be automatically created during extraction. When listing members from a zip archive, ensure that all parent directories are included. This guarantees that during charm cleanup, directories are not missed.
1 similar comment
I'm supportive of this idea, as it makes charms act the way zip and juju would create those .zip files. I have not done the actual validation of the patch, but the mechanism that was discussed I agree with. |
If this was how things always had been I'd like this mechanism a lot. But as someone who has charms deployed in the field right now that are affected by this bug, this gives me pause:
I'd prefer if possible a fix (either here, or separately) that fixes the issue for charms that are already deployed (like something that could detect during refresh some of these unmanaged directories and "do the right thing" to clean them up). As is with this fix, I don't know how to help people that have charms they've already deployed. Even with the newly patched juju, they're going to |
The situation here is that, let's assume a charm has rev1, rev2, and rev3 installed with the affected Juju. With the current fix rolled out to Juju, we can ensure that future refreshes like rev4 will completely clean up their files. With the approach I mentioned in the description (updating the Another reason I am somewhat reluctant to modify For fixing the charm that's already deployed, based on the cause, we know that the residual files are all empty directories. This can be fixed manually by running a command: juju exec --application the-charm "find /var/lib/juju/agents/unit-*/charm -type d -empty -delete" What do you think? |
To see if I understand correctly, is this correct?
In other words, any refresh that occurs in the patched juju will clean up empty packages from the pre-refresh revision and prevent future revisions from creating more, but wont be able to find any leftover directories from the distant past. Does that sound right? |
Just to be clear, I'm not saying the perfect solution exists :) It might be the current solution is as good as can be implemented - I'm just making sure we know the pitfalls. The main issue I worry about is that, once a charm hits this error, there's no automated way out of it. But rather than speculate about that, can you try these two concrete test cases and see how they go? If they both pass, I'm not worried case 1 - patching before the error occurs# With unpatched juju
juju bootstrap lxd lxd
juju add-model test1
juju deploy ubuntu
juju deploy grafana-agent --channel latest/stable --revision 134
juju relate ubuntu grafana-agent
# wait for grafana-agent to deploy and go to Blocked
# patch juju
juju refresh grafana-agent --revision 164
# wait for grafana-agent to refresh and go to Blocked. It should not go to error. Blocked here means everything worked case 2 - patching after the error occurs# With unpatched juju
juju bootstrap lxd lxd
juju add-model test1
juju deploy ubuntu
juju deploy grafana-agent --channel latest/stable --revision 134
juju relate ubuntu grafana-agent
# wait for grafana-agent to deploy and go to Blocked
juju refresh grafana-agent --revision 164
# wait for grafana-agent to refresh - it will go to Error because of the leftover package
# patch juju
juju refresh grafana-agent --revision 164
# wait for grafana-agent to refresh and go to Blocked. It should not go to error. Blocked here means everything worked |
fyi, the case I've seen leaves nested empty directories, eg:
The suggested human intervention of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank-you.
#17939 Updates juju/charm/v12 to v12.1.1 to include fix for charm upgrade without leaving old directories. juju/charm#435 ## QA steps ``` # bootstrap lxd and add a model $ juju deploy github-runner --revision 130 --channel latest/stable # wait for deploy and charm to get blocked $ juju refresh github-runner --revision 131 # wait for upgrade $ juju ssh 0 ubuntu@juju-32b4eb-0:/var/lib/juju/agents/unit-github-runner-0/charm/venv$ ls | grep openstacksdk openstacksdk-3.0.0.dist-info # there should only be one directory with the prefix openstacksdk ``` ## Documentation changes N/A ## Links **Launchpad bug:** https://bugs.launchpad.net/juju/+bug/2058335 **Jira card:** JUJU-
Zip archives may not include parent directories of files, as these are usually automatically created during extraction. This is exactly what charmcraft does when packing the charm (https://github.com/canonical/charmcraft/blob/b48ef739df4732bb3ed35d67893574b260417a04/charmcraft/utils/file.py#L68-L69). And, when Juju creates the charm manifest from this kind of charm zip file, certain directories are omitted from the manifest. This omission can result in directories from previous charm revisions not being removed during an upgrade. And the residual empty directories may cause problems, for example, an empty python package
dist-info
directory may cause the package metadata to malfunction.In this pull request, updating the
ArchiveMembers
function to add the parent directory to the member list if it does not already exist in the zip archive. This ensures complete cleanup of directories during a charm upgrade.It is important to note that this change will only ensure the proper cleanup of files for charms that are newly deployed, as charms that are already deployed have their manifests written to the manifest files on disk. While it is possible to modify the
manifestDeployer
'sloadManifest
function to include the missing directory entries, this adjustment would only remove residual empty directories from the most recent deployment and would not address problems in older deployments, which seems not worthy it.Fix: https://bugs.launchpad.net/juju/+bug/2058335
QA Steps
This issue only affects charms deployed from charmhub, as locally uploaded charms are repacked by Juju, which adds the missing directories during this process.
Directories such as
openstacksdk-2.1.0.dist-info
andopenstacksdk-3.0.0.dist-info
from two different revisions both exist, causing problem foropenstacksdk
: