From f1e8f2933fca60ce13ba706c1a8076b0eab40ab4 Mon Sep 17 00:00:00 2001 From: Jordan Keister Date: Thu, 23 Feb 2023 09:41:53 -0600 Subject: [PATCH 1/4] impose order on maps Signed-off-by: Jordan Keister --- pkg/cache/json.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/cache/json.go b/pkg/cache/json.go index 47a54952b..cfb6bfc24 100644 --- a/pkg/cache/json.go +++ b/pkg/cache/json.go @@ -14,6 +14,7 @@ import ( "github.com/operator-framework/operator-registry/alpha/declcfg" "github.com/operator-framework/operator-registry/pkg/api" "github.com/operator-framework/operator-registry/pkg/registry" + "k8s.io/apimachinery/pkg/util/sets" ) var _ Cache = &JSON{} @@ -58,8 +59,19 @@ func (q *JSON) ListBundles(ctx context.Context) ([]*api.Bundle, error) { func (q *JSON) SendBundles(_ context.Context, s registry.BundleSender) error { for _, pkg := range q.packageIndex { - for _, ch := range pkg.Channels { - for _, b := range ch.Bundles { + cList := sets.NewString() + for chName, _ := range pkg.Channels { + cList.Insert(chName) + } + for _, chName := range cList.List() { + ch := pkg.Channels[chName] + + bList := sets.NewString() + for bName, _ := range ch.Bundles { + bList.Insert(bName) + } + for _, bName := range bList.List() { + b := ch.Bundles[bName] apiBundle, err := q.loadAPIBundle(apiBundleKey{pkg.Name, ch.Name, b.Name}) if err != nil { return fmt.Errorf("convert bundle %q: %v", b.Name, err) From f848fd1da0887cb02be7bf545cd3911040343d48 Mon Sep 17 00:00:00 2001 From: Jordan Keister Date: Thu, 23 Feb 2023 11:37:27 -0600 Subject: [PATCH 2/4] now modding GetBundle Signed-off-by: Jordan Keister --- pkg/cache/json.go | 4 ++-- pkg/cache/pkgs.go | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/cache/json.go b/pkg/cache/json.go index cfb6bfc24..ae6e57ed8 100644 --- a/pkg/cache/json.go +++ b/pkg/cache/json.go @@ -60,14 +60,14 @@ func (q *JSON) ListBundles(ctx context.Context) ([]*api.Bundle, error) { func (q *JSON) SendBundles(_ context.Context, s registry.BundleSender) error { for _, pkg := range q.packageIndex { cList := sets.NewString() - for chName, _ := range pkg.Channels { + for chName := range pkg.Channels { cList.Insert(chName) } for _, chName := range cList.List() { ch := pkg.Channels[chName] bList := sets.NewString() - for bName, _ := range ch.Bundles { + for bName := range ch.Bundles { bList.Insert(bName) } for _, bName := range bList.List() { diff --git a/pkg/cache/pkgs.go b/pkg/cache/pkgs.go index d387ddbd0..af24c397c 100644 --- a/pkg/cache/pkgs.go +++ b/pkg/cache/pkgs.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "sort" + "strings" "github.com/operator-framework/operator-registry/alpha/declcfg" "github.com/operator-framework/operator-registry/alpha/model" @@ -34,6 +35,7 @@ func (pkgs packageIndex) GetPackage(_ context.Context, name string) (*registry.P CurrentCSVName: ch.Head, }) } + sort.Slice(channels, func(i, j int) bool { return strings.Compare(channels[i].Name, channels[j].Name) < 0 }) return ®istry.PackageManifest{ PackageName: pkg.Name, Channels: channels, From b8c0c58b45e84b730744550fd81880c9be4ce729 Mon Sep 17 00:00:00 2001 From: Jordan Keister Date: Fri, 31 Mar 2023 18:13:33 -0500 Subject: [PATCH 3/4] more terse Signed-off-by: Jordan Keister --- pkg/cache/json.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/cache/json.go b/pkg/cache/json.go index ae6e57ed8..9e99b135d 100644 --- a/pkg/cache/json.go +++ b/pkg/cache/json.go @@ -59,11 +59,8 @@ func (q *JSON) ListBundles(ctx context.Context) ([]*api.Bundle, error) { func (q *JSON) SendBundles(_ context.Context, s registry.BundleSender) error { for _, pkg := range q.packageIndex { - cList := sets.NewString() - for chName := range pkg.Channels { - cList.Insert(chName) - } - for _, chName := range cList.List() { + channels := sets.KeySet(pkg.Channels) + for _, chName := range sets.List(channels) { ch := pkg.Channels[chName] bList := sets.NewString() From e04391ed4279b7882cad8d3950c2615ad328e5b1 Mon Sep 17 00:00:00 2001 From: Jordan Keister Date: Fri, 31 Mar 2023 18:23:45 -0500 Subject: [PATCH 4/4] forgot bundles Signed-off-by: Jordan Keister --- pkg/cache/json.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pkg/cache/json.go b/pkg/cache/json.go index 9e99b135d..f1e90d9a7 100644 --- a/pkg/cache/json.go +++ b/pkg/cache/json.go @@ -63,11 +63,8 @@ func (q *JSON) SendBundles(_ context.Context, s registry.BundleSender) error { for _, chName := range sets.List(channels) { ch := pkg.Channels[chName] - bList := sets.NewString() - for bName := range ch.Bundles { - bList.Insert(bName) - } - for _, bName := range bList.List() { + bundles := sets.KeySet(ch.Bundles) + for _, bName := range sets.List(bundles) { b := ch.Bundles[bName] apiBundle, err := q.loadAPIBundle(apiBundleKey{pkg.Name, ch.Name, b.Name}) if err != nil {