Skip to content

Commit fdb30bd

Browse files
committed
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.
1 parent beeaf09 commit fdb30bd

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pkg/cli/admin/prune/images/images.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ func (o PruneImagesOptions) Run() error {
413413

414414
ctx := context.TODO()
415415
allImages := map[string]*imagev1.Image{}
416+
var acceptableErrors []error
416417
err = pager.New(func(ctx context.Context, opts metav1.ListOptions) (runtime.Object, error) {
417418
return o.ImageClient.Images().List(ctx, opts)
418419
}).EachListItem(ctx, metav1.ListOptions{Limit: 5000}, func(obj runtime.Object) error {
@@ -421,7 +422,12 @@ func (o PruneImagesOptions) Run() error {
421422
return nil
422423
})
423424
if err != nil {
424-
return err
425+
if len(allImages) > 0 {
426+
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", len(allImages), err)
427+
acceptableErrors = append(acceptableErrors, err)
428+
} else {
429+
return err
430+
}
425431
}
426432

427433
var (
@@ -528,6 +534,9 @@ func (o PruneImagesOptions) Run() error {
528534
imageDeleter,
529535
)
530536
fmt.Fprintf(o.Out, "Summary: %s\n", stats)
537+
if errs == nil {
538+
errs = kutilerrors.NewAggregate(acceptableErrors)
539+
}
531540
return errs
532541
}
533542

0 commit comments

Comments
 (0)