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

add charmcraft purge or charmcraft cleanall command to clean all instances #1042

Open
sed-i opened this issue Mar 6, 2023 · 15 comments
Open
Labels
blocked Waiting on a third party to finish something before this can be further processed Enhancement New feature or request

Comments

@sed-i
Copy link
Contributor

sed-i commented Mar 6, 2023

I ran out of space because /var/snap/lxd/common/lxd/storage-pools/default/containers/charmcraft* had a lot of stuff in it.

$ sudo ls /var/snap/lxd/common/lxd/storage-pools/default/containers
charmcraft_base-instance-charmcraft-buildd-base-v00-36b64d8a932634714eb2  charmcraft_charmcraft-grafana-agent-22-0-0-amd64	charmcraft_charmcraft-prometheus-k8s-36-0-0-amd64
charmcraft_base-instance-charmcraft-buildd-base-v00-f36807e72ea445fd8492  charmcraft_charmcraft-grafana-agent-k8s-2-0-0-amd64	charmcraft_charmcraft-pusher-54-0-0-amd64
charmcraft_charmcraft-alertmanager-k8s-5-0-0-amd64			 charmcraft_charmcraft-grafana-agent-k8s-22-0-0-amd64	juju-0728c2-2
charmcraft_charmcraft-application-307288-0-0-amd64			 charmcraft_charmcraft-kafka-292835-0-0-amd64		juju-0728c2-4
charmcraft_charmcraft-avalanche-k8s-8-0-0-amd64				 charmcraft_charmcraft-mimir-k8s-28-0-0-amd64		juju-541575-0

I wonder if it makes sense to add a --all flag to clean so it will run the equivalent of:

sudo bash -c "rm -rf /var/snap/lxd/common/lxd/storage-pools/default/containers/charmcraft*"

More precisely,

for instance in $(lxc list --project=charmcraft --format json | jq -r '.[] | select(.name | startswith("charmcraft-")) | .name');
do
    lxc --project=charmcraft delete $instance
done

Or, in nushell,

(lxc list --project=charmcraft --format json
| from json
| get name
| where { |it| $it | str starts-with 'charmcraft-' }
| each { |it| lxc --project=charmcraft delete $it }
)
@mr-cal
Copy link
Contributor

mr-cal commented Mar 7, 2023

Thanks for the suggestion! I've been in this same scenario before too.

charmcraft clean is a lifecycle command that only operates on the current charmcraft project. I think that adding a flag to clean that affects other projects wouldn't follow the "principle of least surprise". It would probably need to be a separate command.

Rockcraft recently got a new feature. When you uninstall rockcraft, it removes all rockcraft images and instances in lxd. If we added this to charmcraft, then uninstalling and re-installing charmcraft would solve your problem. However, that isn't a great user experience either.

@mr-cal mr-cal added the Enhancement New feature or request label Mar 7, 2023
@sed-i
Copy link
Contributor Author

sed-i commented Mar 8, 2023

If it's just about naming then purge, reset, destroy may be less surprising.
Or, because the action is very similar to clean, perhaps cleanall or cleanup?

Not sure about cleanup on uninstall. Would be nice have charms continue to repack quickly across snap refresh.

@mr-cal
Copy link
Contributor

mr-cal commented Mar 8, 2023

I like those ideas, I think something like charmcraft purge would be good. Thanks!

For what it's worth, the remove hook doesn't run on a snap refresh, so the LXD instances are retained when updating.

@mr-cal mr-cal changed the title charmcraft clean --all? add charmcraft purge or charmcraft cleanall command to clean all instances Mar 8, 2023
@lengau
Copy link
Collaborator

lengau commented Mar 29, 2023

Perhaps a reset-system subcommand with a big (default aborting) warning message about how this will affect all charmcraft build environments on this system. (We can offer a --force or similar to non-interactively allow the command to proceed)

@mkalcok
Copy link

mkalcok commented Apr 6, 2023

I just want to voice support for this feature (In any form) as having to manually delete bunch of containers every once in a while is just no fun.

@jnsgruk
Copy link
Member

jnsgruk commented Apr 6, 2023

Docker has a docker image prune command and docker system prune - perhaps we could follow suit

That said, multipass uses multipass purge so maybe that's more appropriate?

@sergiusens
Copy link
Collaborator

Did not give it much thought, but something like snap set charmcraft provider.lxd=purge could work. I might also be butchering the system here

Copy link

Thank you for reporting us your feedback!

The internal ticket has been created: https://warthogs.atlassian.net/browse/CRAFT-2551.

This message was autogenerated

@lengau
Copy link
Collaborator

lengau commented Feb 29, 2024

With fresh eyes I think charmcraft purge is probably the way to go with this.

There are several things we might want to clean up in this:

  1. Shared pip cache
  2. Build containers that are STOPPED
  3. Build containers in any state (probably behind an additional flag)
  4. Base images (behind its own flag)

Since the pip cache is attached to a specific base image, removing a base image can automatically remove its pip cache. However, I've personally come across use cases where I want to clear the pip cache without removing any build images, so I'd like that to be possible too.

@paulomach
Copy link

With fresh eyes I think charmcraft purge is probably the way to go with this.
...
Since the pip cache is attached to a specific base image, removing a base image can automatically remove its pip cache. However, I've personally come across use cases where I want to clear the pip cache without removing any build images, so I'd like that to be possible too.

So how about just prompting with a [Y/n] per artifact category?

@sed-i
Copy link
Contributor Author

sed-i commented Mar 20, 2024

cases where I want to clear the pip cache without removing any build images

I imagine 80%+ of the time users would want to wipe it all, so personally I'd like the plain purge to wipe it all.
In any case, a cheatsheet style doc could help a lot with special cases.

@lengau
Copy link
Collaborator

lengau commented Apr 4, 2024

@sed-i I think with the purge command 1 and 2 would be the most common needs, since #3 may interfere with another ongoing build and #4 would purge things that get automatically managed and cleaned up, but which are also far less likely to get into an unusable state. Something like:

  • charmcraft purge - removes pip cache and build containers that are stopped (or maybe in any state other than running)
  • charmcraft purge --include-running gets rid of all non base containers
  • charmcraft purge --all gets rid of the shared pip cache and any runner VMs/containers, including bases.

Then to limit further we could have:

  • charmcraft purge --only-cache to clear only the pip cache
  • charmcraft purge --only-builders to clear only (stopped) build containers/VMs

@lengau
Copy link
Collaborator

lengau commented Apr 4, 2024

@paulomach that's a possibility too, as long as we provide a way to do it non-interactively as well. I'd want [Y/n] for "common" categories (1 and 2) and [y/N] for the others.

I'll need to talk with the rest of the team though, as whatever gets decided for Charmcraft will likely become the standard for all craft applications (with obviously the relevant changes), so whatever we decide should be done carefully.

@sed-i
Copy link
Contributor Author

sed-i commented Apr 5, 2024

If it helps, we could start with just purge and purge --all for now.

But I wonder if the inverse is easier to grok and extend:

charmcraft purge  # all purged
charmcraft purge --keep-cache --keep-running --keep-builders  # nothing purged

@lengau lengau added the blocked Waiting on a third party to finish something before this can be further processed label Aug 26, 2024
@lengau
Copy link
Collaborator

lengau commented Aug 26, 2024

Blocked by canonical/craft-providers#639

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Waiting on a third party to finish something before this can be further processed Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants