-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplifying the error handling on manifest delete/remove command
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
- Loading branch information
1 parent
b974278
commit 12cbadf
Showing
10 changed files
with
45 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
) | ||
import "errors" | ||
|
||
// DeleteManifest implements commands.PackClient. | ||
func (c *Client) DeleteManifest(ctx context.Context, names []string) (errs []error) { | ||
func (c *Client) DeleteManifest(names []string) error { | ||
var allErrors error | ||
for _, name := range names { | ||
imgIndex, err := c.indexFactory.LoadIndex(name) | ||
if err != nil { | ||
errs = append(errs, err) | ||
allErrors = errors.Join(allErrors, err) | ||
continue | ||
} | ||
|
||
if err := imgIndex.DeleteDir(); err != nil { | ||
errs = append(errs, err) | ||
allErrors = errors.Join(allErrors, err) | ||
} | ||
} | ||
|
||
if len(errs) == 0 { | ||
if allErrors == nil { | ||
c.logger.Info("Successfully deleted manifest list(s) from local storage") | ||
} | ||
return errs | ||
return allErrors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,39 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
gccrName "github.com/google/go-containerregistry/pkg/name" | ||
) | ||
|
||
// RemoveManifest implements commands.PackClient. | ||
func (c *Client) RemoveManifest(ctx context.Context, name string, images []string) (errs []error) { | ||
func (c *Client) RemoveManifest(name string, images []string) error { | ||
var allErrors error | ||
|
||
imgIndex, err := c.indexFactory.LoadIndex(name) | ||
if err != nil { | ||
return append(errs, err) | ||
return err | ||
} | ||
|
||
for _, image := range images { | ||
ref, err := gccrName.NewDigest(image, gccrName.WeakValidation, gccrName.Insecure) | ||
if err != nil { | ||
errs = append(errs, fmt.Errorf("invalid instance '%s': %w", image, err)) | ||
allErrors = errors.Join(allErrors, fmt.Errorf("invalid instance '%s': %w", image, err)) | ||
} | ||
|
||
if err = imgIndex.RemoveManifest(ref); err != nil { | ||
errs = append(errs, err) | ||
allErrors = errors.Join(allErrors, err) | ||
} | ||
|
||
if err = imgIndex.SaveDir(); err != nil { | ||
errs = append(errs, err) | ||
allErrors = errors.Join(allErrors, err) | ||
} | ||
} | ||
|
||
if len(errs) == 0 { | ||
if allErrors == nil { | ||
c.logger.Infof("Successfully removed image(s) from index: '%s'", name) | ||
} | ||
|
||
return errs | ||
return allErrors | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters