Skip to content
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/onsi/ginkgo/v2 v2.20.1
github.com/onsi/gomega v1.34.2
github.com/operator-framework/api v0.27.0
github.com/operator-framework/catalogd v0.21.0
github.com/operator-framework/catalogd v0.22.0
github.com/operator-framework/helm-operator-plugins v0.5.0
github.com/operator-framework/operator-registry v1.46.0
github.com/spf13/pflag v1.0.5
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11 h1:eT
github.com/openshift/crd-schema-checker v0.0.0-20240404194209-35a9033b1d11/go.mod h1:EmVJt97N+pfWFsli/ipXTBZqSG5F5KGQhm3c3IsGq1o=
github.com/operator-framework/api v0.27.0 h1:OrVaGKZJvbZo58HTv2guz7aURkhVKYhFqZ/6VpifiXI=
github.com/operator-framework/api v0.27.0/go.mod h1:lg2Xx+S8NQWGYlEOvFwQvH46E5EK5IrAIL7HWfAhciM=
github.com/operator-framework/catalogd v0.21.0 h1:j5C19Aw3u3PpFgJGE1DF0lajS+pEX5FNlDKkocCKrAM=
github.com/operator-framework/catalogd v0.21.0/go.mod h1:PTMUO/oi7mgXX60U9hDsd23EUwNm1mycnGXAa2hnMsE=
github.com/operator-framework/catalogd v0.22.0 h1:P03HimAAxMdLLVL4+TYYBE+cFpMNW9jfQbqMfQJ+Hg4=
github.com/operator-framework/catalogd v0.22.0/go.mod h1:uZYW3dpbsvdxD+ScznAeHclubqd5sU6GNDtdqiydBxU=
github.com/operator-framework/helm-operator-plugins v0.5.0 h1:qph2OoECcI9mpuUBtOsWOMgvpx52mPTTSvzVxICsT04=
github.com/operator-framework/helm-operator-plugins v0.5.0/go.mod h1:yVncrZ/FJNqedMil+055fk6sw8aMKRrget/AqGM0ig0=
github.com/operator-framework/operator-lib v0.15.0 h1:0QeRM4PMtThqINpcFGCEBnIV3Z8u7/8fYLEx6mUtdcM=
Expand Down
36 changes: 28 additions & 8 deletions internal/resolve/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"slices"
"sort"

mmsemver "github.com/Masterminds/semver/v3"
bsemver "github.com/blang/semver/v4"
Expand Down Expand Up @@ -50,9 +51,14 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1alpha1.ClusterEx
}
}

type foundBundle struct {
bundle *declcfg.Bundle
catalog string
priority int32
}

resolvedBundles := []foundBundle{}
var (
resolvedBundles []*declcfg.Bundle
matchedCatalogs []string
priorDeprecation *declcfg.Deprecation
)

Expand Down Expand Up @@ -114,33 +120,47 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1alpha1.ClusterEx
if len(resolvedBundles) != 0 {
// We've already found one or more package candidates
currentIsDeprecated := isDeprecated(thisBundle, thisDeprecation)
priorIsDeprecated := isDeprecated(*resolvedBundles[len(resolvedBundles)-1], priorDeprecation)
priorIsDeprecated := isDeprecated(*resolvedBundles[len(resolvedBundles)-1].bundle, priorDeprecation)
if currentIsDeprecated && !priorIsDeprecated {
// Skip this deprecated package and retain the non-deprecated package(s)
return nil
} else if !currentIsDeprecated && priorIsDeprecated {
// Our package candidates so far were deprecated and this one is not; clear the lists
resolvedBundles = []*declcfg.Bundle{}
matchedCatalogs = []string{}
resolvedBundles = []foundBundle{}
}
}
// The current bundle shares deprecation status with prior bundles or
// there are no prior bundles. Add it to the list.
resolvedBundles = append(resolvedBundles, &thisBundle)
matchedCatalogs = append(matchedCatalogs, cat.GetName())
resolvedBundles = append(resolvedBundles, foundBundle{&thisBundle, cat.GetName(), cat.Spec.Priority})
priorDeprecation = thisDeprecation
return nil
}, listOptions...); err != nil {
return nil, nil, nil, fmt.Errorf("error walking catalogs: %w", err)
}

// Resolve for priority
if len(resolvedBundles) > 1 {
// Want highest first (reverse sort)
sort.Slice(resolvedBundles, func(i, j int) bool { return resolvedBundles[i].priority > resolvedBundles[j].priority })
// If the top two bundles do not have the same priority, then priority breaks the tie
// Reduce resolvedBundles to just the first item (highest priority)
if resolvedBundles[0].priority != resolvedBundles[1].priority {
resolvedBundles = []foundBundle{resolvedBundles[0]}
}
}

// Check for ambiguity
if len(resolvedBundles) != 1 {
errPrefix := ""
if installedBundle != nil {
errPrefix = fmt.Sprintf("error upgrading from currently installed version %q: ", installedBundle.Version)
}
switch {
case len(resolvedBundles) > 1:
matchedCatalogs := []string{}
for _, r := range resolvedBundles {
matchedCatalogs = append(matchedCatalogs, r.catalog)
}
slices.Sort(matchedCatalogs) // sort for consistent error message
return nil, nil, nil, fmt.Errorf("%smatching packages found in multiple catalogs: %v", errPrefix, matchedCatalogs)
case versionRange != "" && channelName != "":
Expand All @@ -153,7 +173,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1alpha1.ClusterEx
return nil, nil, nil, fmt.Errorf("%sno package %q found", errPrefix, packageName)
}
}
resolvedBundle := resolvedBundles[0]
resolvedBundle := resolvedBundles[0].bundle
resolvedBundleVersion, err := bundleutil.GetVersion(*resolvedBundle)
if err != nil {
return nil, nil, nil, fmt.Errorf("error getting resolved bundle version for bundle %q: %w", resolvedBundle.Name, err)
Expand Down
Loading