From 6097a9b3a1a02141f7789cb744717d1fb2005886 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 16 Apr 2025 16:10:35 -0700 Subject: [PATCH] pkg/cli/admin/prune/images: Allow partial image retrieval When Image counts get absurdly large (hundreds of thousands), pruning can fail with errors like: Error from server (Expired): The provided continue parameter is too old to display a consistent list result. You can start a new list without the continue parameter, or use the continue token in this response to retrieve the remainder of the results. Continuing with the provided token results in an inconsistent list - objects that were created, modified, or deleted between the time the first chunk was returned and now may show up in the list. With this commit, I'm still printing that warning message, but if we got any Images back before the error, I'm still going to try and prune those, because maybe some progress in pruning will get the Image count down low enough that a future invocation will go through cleanly. --- pkg/cli/admin/prune/images/images.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/cli/admin/prune/images/images.go b/pkg/cli/admin/prune/images/images.go index a2a686fe8f..f37b274ac5 100644 --- a/pkg/cli/admin/prune/images/images.go +++ b/pkg/cli/admin/prune/images/images.go @@ -413,6 +413,7 @@ func (o PruneImagesOptions) Run() error { ctx := context.TODO() allImages := map[string]*imagev1.Image{} + var acceptableErrors []error err = pager.New(func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) { return o.ImageClient.Images().List(ctx, opts) }).EachListItem(ctx, metav1.ListOptions{Limit: 5000}, func(obj runtime.Object) error { @@ -421,7 +422,12 @@ func (o PruneImagesOptions) Run() error { return nil }) if err != nil { - return err + if len(allImages) > 0 { + fmt.Fprintf(o.ErrOut, "warning: error retrieving images, but we got %d, so keep going to see if we can prune any of those: %s\n", len(allImages), err) + acceptableErrors = append(acceptableErrors, err) + } else { + return err + } } var ( @@ -528,6 +534,9 @@ func (o PruneImagesOptions) Run() error { imageDeleter, ) fmt.Fprintf(o.Out, "Summary: %s\n", stats) + if errs == nil { + errs = kutilerrors.NewAggregate(acceptableErrors) + } return errs }