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

CLOUD-861: Automate operator release #320

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add more versions from docker hub
  • Loading branch information
pooknull committed Oct 28, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 53a8acd2de79eefc125a7b1822a065ff16d8e238
44 changes: 43 additions & 1 deletion tools/operator-tool/cmd/filler.go
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (
"strings"

vsAPI "github.com/Percona-Lab/percona-version-service/versionpb/api"
gover "github.com/hashicorp/go-version"

"operator-tool/registry"
)
@@ -20,9 +21,13 @@ type VersionMapFiller struct {
errs []error
}

func (f *VersionMapFiller) addErr(err error) {
f.errs = append(f.errs, err)
}

func (f *VersionMapFiller) exec(vm map[string]*vsAPI.Version, err error) map[string]*vsAPI.Version {
if err != nil {
f.errs = append(f.errs, err)
f.addErr(err)
return nil
}

@@ -50,11 +55,48 @@ func (f *VersionMapFiller) setRecommended(vm map[string]*vsAPI.Version) {
}
}

// addVersionsFromRegistry searches Docker Hub for all tags associated with the specified image
// and appends any missing tags that match the MAJOR.MINOR.PATCH version format to the returned versions slice.
//
// Tags with a "-debug" suffix are excluded.
func (f *VersionMapFiller) addVersionsFromRegistry(image string, versions []string) []string {
wantedVerisons := make(map[string]struct{}, len(versions))
coreVersions := make(map[string]struct{})
for _, v := range versions {
wantedVerisons[v] = struct{}{}
coreVersions[goversion(v).Core().String()] = struct{}{}
}

tags, err := f.RegistryClient.GetTags(image)
if err != nil {
f.addErr(err)
return nil
}

for _, tag := range tags {
if strings.HasSuffix(tag, "-debug") {
continue
}
if _, err := gover.NewVersion(tag); err != nil {
continue
}
if _, ok := coreVersions[goversion(tag).Core().String()]; !ok {
continue
}
if _, ok := wantedVerisons[tag]; ok {
continue
}
versions = append(versions, tag)
}
return versions
}

// Normal returns a map[string]*Version for the specified image by filtering tags
// with the given list of versions.
//
// The map may include image tags with the following suffixes: "", "-amd64", "-arm64", and "-multi".
func (f *VersionMapFiller) Normal(image string, versions []string) map[string]*vsAPI.Version {
versions = f.addVersionsFromRegistry(image, versions)
return f.exec(getVersionMap(f.RegistryClient, image, versions))
}

16 changes: 16 additions & 0 deletions tools/operator-tool/registry/registry.go
Original file line number Diff line number Diff line change
@@ -145,6 +145,22 @@ func (r *RegistryClient) GetLatestImage(imageName string) (Image, error) {
return Image{}, errors.New("image not found")
}

func (r *RegistryClient) GetTags(imageName string) ([]string, error) {
tags := []string{}
for page := 1; ; page++ {
resp, err := r.get(imageName, page)
if err != nil {
return nil, fmt.Errorf("failed to get page %d: %w", page, err)
}
for _, result := range resp.Results {
tags = append(tags, result.Name)
}
if resp.NextPage == "" || len(resp.Results) < defaultPageSize {
return tags, nil
}
}
}

func (r *RegistryClient) GetImages(imageName string, filterFunc func(tag string) bool) ([]Image, error) {
images := []Image{}
for page := 1; ; page++ {