-
Notifications
You must be signed in to change notification settings - Fork 612
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
Make cache pruning more flexible #1409
base: master
Are you sure you want to change the base?
Conversation
Should we maybe keep also the images that are included in the current template versions, not only instances ? |
I have no strong opinion on this.. my case is to cleanup images I've downloaded for some tests and which are not used (doesn't exists) anymore.. Though I'd like to keep the images I'm still using as internet in some countries (Indonesia e.g.) is not that great to redownload few gigabytes frequently. |
I added an issue (#1410) for the discussion - there's also Slack, if we want to keep this PR for the implementation review |
limactl prune downloads
I've simplified things and removed the
|
Updates:
|
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.
Thanks
I think this PR is good, but have run out of time right now (will finish tomorrow). I found it useful to add a --- cmd/limactl/prune.go
+++ cmd/limactl/prune.go
@@ -21,12 +21,17 @@ func newPruneCommand() *cobra.Command {
ValidArgsFunction: cobra.NoFileCompletions,
}
+ pruneCommand.Flags().Bool("dry-run", false, "Show which images would be deleted, but don't really delete them")
pruneCommand.Flags().Bool("no-digest-only", false, "Only prune images without a digest specified (\"fallback\" images usually)")
pruneCommand.Flags().Bool("unreferenced-only", false, "Only prune downloads not referenced in any VM")
return pruneCommand
}
func pruneAction(cmd *cobra.Command, args []string) error {
+ dryRun, err := cmd.Flags().GetBool("dry-run")
+ if err != nil {
+ return err
+ }
pruneWithoutDigest, err := cmd.Flags().GetBool("no-digest-only")
if err != nil {
return err
@@ -68,20 +73,24 @@ func pruneAction(cmd *cobra.Command, args []string) error {
if pruneWithoutDigest && refFile.Digest == "" {
// delete the fallback image entry (entry w/o digest) even if referenced
logrus.WithFields(entryFields).Infof("Deleting fallback entry")
- if err := os.RemoveAll(entry.Path); err != nil {
- logrus.WithError(err).WithFields(logrus.Fields{
- "path": entry.Path,
- }).Errorf("Cannot delete directory. Skipping...")
+ if !dryRun {
+ if err := os.RemoveAll(entry.Path); err != nil {
+ logrus.WithError(err).WithFields(logrus.Fields{
+ "path": entry.Path,
+ }).Errorf("Cannot delete directory. Skipping...")
+ }
}
}
} else {
if pruneUnreferenced {
// delete the unreferenced cached entry
logrus.WithFields(entryFields).Infof("Deleting unreferenced entry")
- if err := os.RemoveAll(entry.Path); err != nil {
- logrus.WithError(err).WithFields(logrus.Fields{
- "path": entry.Path,
- }).Errorf("Cannot delete directory. Skipping...")
+ if !dryRun {
+ if err := os.RemoveAll(entry.Path); err != nil {
+ logrus.WithError(err).WithFields(logrus.Fields{
+ "path": entry.Path,
+ }).Errorf("Cannot delete directory. Skipping...")
+ }
}
}
}
@@ -96,6 +105,9 @@ func pruneAction(cmd *cobra.Command, args []string) error {
}
cacheDir := filepath.Join(ucd, "lima")
logrus.Infof("Pruning everything in %q", cacheDir)
+ if dryRun {
+ return nil
+ }
return os.RemoveAll(cacheDir)
} |
Shall we merge this and discuss dry-run in another issue/PR? |
If there is no release expected in 2 next days I'd like to add dry run because I like the idea. I'll add it tomorrow. |
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.
- Downloads referenced by a template are dropped from the PR scope
I somehow missed this. What is the reason for that?
I just noticed that when I deleted all my current instances, then limactl prune --unreferenced-only
will delete everything in the cache (including the current nerdctl-full
archives).
That seems like a major breakage.
If this is the functionality you want, then you should add a different option name for it. Like --all-except-currently-in-use
(but a better name).
Just for illustration, assuming my cache looks like this:
I would expect
I guess for backwards compatibility we need to keep the existing behaviour, but I feel like we should require an |
I'm running out of time again, but I also think the
Maybe I made a mistake, will need to take a look again on the weekend. |
Let me move this to v0.17 |
This commit implements 2 more CLI flags: * --no-digest-only Only prune images without a digest specified ("fallback" images usually) * --unreferenced-only Only prune downloads not referenced in any VM Signed-off-by: Yury Bushmelev <[email protected]>
The reason was to remove the point of the conflict and merge things which everyone is ok with (except @AkihiroSuda maybe 😄 )
This is expected as there is nothing referencing the downloads. Which is the default behavior of |
Well.. you're right :( I just found it's broken.. I've over-optimized things a bit.. let me fix it |
Do you plan to update this PR? |
Yes, I'll continue to work on this later. @jandubois created pretty good definition of the process in #1409. My plan is to follow it. Though this requires some thinking.. Let me change the PR to draft again. |
This command deletes only those cached downloads which are not referenced by any existing VM configs.