Skip to content

Commit

Permalink
Package sort for deterministic ordering in ListBundles API (operator-…
Browse files Browse the repository at this point in the history
…framework#1084)

* impose order on maps

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>

* now modding GetBundle

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>

* more terse

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>

* forgot bundles

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>

---------

Signed-off-by: Jordan Keister <jordan@nimblewidget.com>
  • Loading branch information
grokspawn committed Apr 19, 2023
1 parent 49eae7b commit f0f637c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/cache/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -58,8 +59,13 @@ 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 {
channels := sets.KeySet(pkg.Channels)
for _, chName := range sets.List(channels) {
ch := pkg.Channels[chName]

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 {
return fmt.Errorf("convert bundle %q: %v", b.Name, err)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cache/pkgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 &registry.PackageManifest{
PackageName: pkg.Name,
Channels: channels,
Expand Down

0 comments on commit f0f637c

Please sign in to comment.