Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve zarf tools registry prune messaging #2323

Merged
merged 15 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
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
Loading