Skip to content

Commit

Permalink
feat: improve zarf tools registry prune messaging (#2323)
Browse files Browse the repository at this point in the history
## Description

This PR fixes the `zarf tools registry prune` messaging to be more
verbose.

## Related Issue

Fixes #N/A

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [X] Other (security config, docs update, etc)

## Checklist before merging

- [X] Test, docs, adr added or updated as needed
- [X] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
Racer159 committed Feb 21, 2024
1 parent 5e1c6df commit 714f7c0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/cmd/tools/crane.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ func pruneImages(_ *cobra.Command, _ []string) error {
func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.DeployedPackage, registryEndpoint string) error {
authOption := config.GetCraneAuthOption(zarfState.RegistryInfo.PushUsername, zarfState.RegistryInfo.PushPassword)

spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneLookup)
defer spinner.Stop()

// Determine which image digests are currently used by Zarf packages
pkgImages := map[string]bool{}
for _, pkg := range zarfPackages {
Expand Down Expand Up @@ -273,6 +276,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}

spinner.Updatef(lang.CmdToolsRegistryPruneCatalog)

// Find which images and tags are in the registry currently
imageCatalog, err := crane.Catalog(registryEndpoint, authOption)
if err != nil {
Expand All @@ -295,6 +300,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}

spinner.Updatef(lang.CmdToolsRegistryPruneCalculate)

// Figure out which images are in the registry but not needed by packages
imageDigestsToPrune := map[string]bool{}
for digestRef, digest := range referenceToDigest {
Expand All @@ -308,6 +315,8 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}

spinner.Success()

if len(imageDigestsToPrune) > 0 {
message.Note(lang.CmdToolsRegistryPruneImageList)

Expand All @@ -328,13 +337,18 @@ func doPruneImagesForPackages(zarfState *types.ZarfState, zarfPackages []types.D
}
}
if confirm {
spinner := message.NewProgressSpinner(lang.CmdToolsRegistryPruneDelete)
defer spinner.Stop()

// Delete the digest references that are to be pruned
for digestRef := range imageDigestsToPrune {
err = crane.Delete(digestRef, authOption)
if err != nil {
return err
}
}

spinner.Success()
}
} else {
message.Note(lang.CmdToolsRegistryPruneNoImages)
Expand Down
4 changes: 4 additions & 0 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ $ zarf tools registry digest reg.example.com/stefanprodan/podinfo:6.4.0
CmdToolsRegistryPruneFlagConfirm = "Confirm the image prune action to prevent accidental deletions"
CmdToolsRegistryPruneImageList = "The following image digests will be pruned from the registry:"
CmdToolsRegistryPruneNoImages = "There are no images to prune"
CmdToolsRegistryPruneLookup = "Looking up images within package definitions"
CmdToolsRegistryPruneCatalog = "Cataloging images in the registry"
CmdToolsRegistryPruneCalculate = "Calculating images to prune"
CmdToolsRegistryPruneDelete = "Deleting unused images"

CmdToolsRegistryInvalidPlatformErr = "Invalid platform '%s': %s"
CmdToolsRegistryFlagVerbose = "Enable debug logs"
Expand Down

0 comments on commit 714f7c0

Please sign in to comment.