Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pkg/cli/admin/prune/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 (
Expand Down Expand Up @@ -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)
}
Comment on lines +537 to +539
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Aggregate both error sets to preserve all error context.

The current logic only returns acceptableErrors when pruning succeeds (errs == nil). If pruning fails, the acceptableErrors from image listing are lost, hiding important diagnostic information from users.

Apply this diff to aggregate both error sets:

 	fmt.Fprintf(o.Out, "Summary: %s\n", stats)
-	if errs == nil {
-		errs = kutilerrors.NewAggregate(acceptableErrors)
+	if len(acceptableErrors) > 0 {
+		allErrors := append(acceptableErrors, errs)
+		errs = kutilerrors.NewAggregate(allErrors)
 	}
 	return errs

Note: kutilerrors.NewAggregate handles nil errors gracefully, so this preserves existing behavior while ensuring acceptableErrors are never lost.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if errs == nil {
errs = kutilerrors.NewAggregate(acceptableErrors)
}
if errs == nil {
errs = kutilerrors.NewAggregate(acceptableErrors)
} else if len(acceptableErrors) > 0 {
allErrors := make([]error, 0, len(acceptableErrors)+1)
allErrors = append(allErrors, acceptableErrors...)
allErrors = append(allErrors, errs)
errs = kutilerrors.NewAggregate(allErrors)
}
🤖 Prompt for AI Agents
In pkg/cli/admin/prune/images/images.go around lines 537 to 539, the current
code replaces errs with only acceptableErrors when errs is nil, losing
acceptableErrors when errs is non-nil; modify this so both error sets are
aggregated into a single error (using kutilerrors.NewAggregate) regardless of
whether errs is nil, ensuring acceptableErrors are appended/combined with errs
and assigned back to errs so no error context is lost.

return errs
}

Expand Down