Skip to content

Commit

Permalink
feature(main): registry list repo fix (#2821)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu authored Mar 16, 2023
1 parent 7a89ce3 commit ebefb19
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/registry/cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newRegistryListImageCmd() *cobra.Command {
%[1]s registry images --filter tag=*1.1*
%[1]s registry images --filter tag=*sec
%[1]s registry images --filter name=public,tag=v1.1.1
%[1]s registry images --filter tag=<none>`, rootCmd.CommandPath()),
%[1]s registry images --filter tag=\<none\>`, rootCmd.CommandPath()),
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
is.ListImages(flagsResults.registryName, flagsResults.filter, flagsResults.json)
Expand Down
22 changes: 16 additions & 6 deletions pkg/registry/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ package registry
import (
"fmt"

"k8s.io/apimachinery/pkg/util/sets"

"github.com/modood/table"
"github.com/opencontainers/go-digest"
"k8s.io/apimachinery/pkg/util/json"
Expand Down Expand Up @@ -57,20 +55,33 @@ func (is *DefaultImage) ListImages(registryName, search string, enableJSON bool)
}

var imageVersionList bool
repoLens := sets.NewString()
defer func() {
if !enableJSON {
logger.Info("Image count %d", repoLens.Len())
logger.Info("Repo count %d", len(repos))
if imageVersionList {
logger.Info("Images Version count %d", len(listImage))
}
}
}()
emptyTag := func(repo string) {
listImage = append(listImage, imageOutputParams{
RegistryName: registryName,
ImageName: repo,
Tag: none,
ImageID: none,
ImageIDShort: none,
ImageDigest: none,
})
}
for _, repo := range repos {
if filter.tagStrategy == FilterStrategyNone {
emptyTag(repo)
continue
}
tags, _ := reg.Tags(repo)
tags = filter.Run(tags, FilterTypeTag)
if len(tags) == 0 {
continue
emptyTag(repo)
} else {
imageVersionList = true
for _, tag := range tags {
Expand Down Expand Up @@ -98,7 +109,6 @@ func (is *DefaultImage) ListImages(registryName, search string, enableJSON bool)
ImageIDShort: imageIDShortStr,
ImageDigest: imageDigestStr,
})
repoLens = repoLens.Insert(repo)
}
}
}
Expand Down

0 comments on commit ebefb19

Please sign in to comment.