Skip to content

Commit

Permalink
fix linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: everettraven <everettraven@gmail.com>
  • Loading branch information
everettraven committed Jan 31, 2024
1 parent 08996d5 commit 71fe718
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 40 deletions.
83 changes: 62 additions & 21 deletions cmd/resolutioncli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@ import (
"context"

"github.com/operator-framework/operator-registry/alpha/action"
"github.com/operator-framework/operator-registry/alpha/declcfg"

"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/internal/controllers"
)

type indexRefClient struct {
renderer action.Render
bundlesCache []*catalogmetadata.Bundle
renderer action.Render
bundlesCache []*catalogmetadata.Bundle
channelsCache []*catalogmetadata.Channel
packagesCache []*catalogmetadata.Package
}

var _ controllers.CatalogProvider = &indexRefClient{}

func newIndexRefClient(indexRef string) *indexRefClient {
return &indexRefClient{
renderer: action.Render{
Expand All @@ -38,47 +45,81 @@ func newIndexRefClient(indexRef string) *indexRefClient {
}
}

func (c *indexRefClient) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error) {
if c.bundlesCache == nil {
func (c *indexRefClient) CatalogContents(ctx context.Context) (*client.Contents, error) {
if c.bundlesCache == nil || c.channelsCache == nil || c.packagesCache == nil {
cfg, err := c.renderer.Run(ctx)
if err != nil {
return nil, err
}

var (
channels []*catalogmetadata.Channel
bundles []*catalogmetadata.Bundle
deprecations []*catalogmetadata.Deprecation
channels []*catalogmetadata.Channel
bundles []*catalogmetadata.Bundle
packages []*catalogmetadata.Package
)

// TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
catalogName := "offline-catalog"

for i := range cfg.Packages {
packages = append(packages, &catalogmetadata.Package{
Package: cfg.Packages[i],
Catalog: catalogName,
})
}

for i := range cfg.Channels {
channels = append(channels, &catalogmetadata.Channel{
Channel: cfg.Channels[i],
Catalog: catalogName,
})
}

for i := range cfg.Bundles {
bundles = append(bundles, &catalogmetadata.Bundle{
Bundle: cfg.Bundles[i],
Bundle: cfg.Bundles[i],
Catalog: catalogName,
})
}

for i := range cfg.Deprecations {
deprecations = append(deprecations, &catalogmetadata.Deprecation{
Deprecation: cfg.Deprecations[i],
})
for _, deprecation := range cfg.Deprecations {
for _, entry := range deprecation.Entries {
switch entry.Reference.Schema {
case declcfg.SchemaPackage:
for _, pkg := range packages {
if pkg.Name == deprecation.Package {
pkg.Deprecation = &declcfg.DeprecationEntry{
Reference: entry.Reference,
Message: entry.Message,
}
}
}
case declcfg.SchemaChannel:
for _, channel := range channels {
if channel.Package == deprecation.Package && channel.Name == entry.Reference.Name {
channel.Deprecation = &declcfg.DeprecationEntry{
Reference: entry.Reference,
Message: entry.Message,
}
}
}
case declcfg.SchemaBundle:
for _, bundle := range bundles {
if bundle.Package == deprecation.Package && bundle.Name == entry.Reference.Name {
bundle.Deprecation = &declcfg.DeprecationEntry{
Reference: entry.Reference,
Message: entry.Message,
}
}
}
}
}
}

// TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
// catalogName := "offline-catalog"

// bundles, err = client.PopulateExtraFields(catalogName, channels, bundles, deprecations)
// if err != nil {
// return nil, err
// }

c.bundlesCache = bundles
c.channelsCache = channels
c.packagesCache = packages
}

return c.bundlesCache, nil
return &client.Contents{}, nil
}
5 changes: 2 additions & 3 deletions cmd/resolutioncli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import (

ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/internal/controllers"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
)
Expand Down Expand Up @@ -151,7 +150,7 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,

cl := clientBuilder.Build()
catalogClient := newIndexRefClient(indexRef)
allBundles, err := catalogClient.Bundles(ctx)
contents, err := catalogClient.CatalogContents(ctx)
if err != nil {
return err
}
Expand All @@ -163,7 +162,7 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
if err := cl.List(ctx, &bundleDeploymentList); err != nil {
return err
}
variables, err := controllers.GenerateVariables(&client.Contents{Bundles: allBundles}, clusterExtensionList.Items, bundleDeploymentList.Items)
variables, err := controllers.GenerateVariables(contents, clusterExtensionList.Items, bundleDeploymentList.Items)
if err != nil {
return err
}
Expand Down
19 changes: 9 additions & 10 deletions internal/resolution/variablesources/installed_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
"github.com/operator-framework/operator-controller/pkg/features"
Expand Down Expand Up @@ -62,9 +61,9 @@ func MakeInstalledPackageVariables(
bundleImage := sourceImage.Ref

// find corresponding bundle for the installed content
resultSet := catalogfilter.Filter(allBundles, catalogfilter.And(
catalogfilter.WithPackageName(clusterExtension.Spec.PackageName),
catalogfilter.WithImage(bundleImage),
resultSet := filter.Filter(allBundles, filter.And(
filter.WithPackageName(clusterExtension.Spec.PackageName),
filter.WithImage(bundleImage),
))
if len(resultSet) == 0 {
return nil, fmt.Errorf("bundle with image %q for package %q not found in available catalogs but is currently installed via BundleDeployment %q", bundleImage, clusterExtension.Spec.PackageName, bundleDeployment.Name)
Expand Down Expand Up @@ -110,9 +109,9 @@ type successorsFunc func(allBundles []*catalogmetadata.Bundle, installedBundle *
func legacySemanticsSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *catalogmetadata.Bundle, channels []*catalogmetadata.Channel) ([]*catalogmetadata.Bundle, error) {
// find the bundles that replace the bundle provided
// TODO: this algorithm does not yet consider skips and skipRange
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
catalogfilter.WithPackageName(installedBundle.Package),
catalogfilter.Replaces(installedBundle.Name, channels),
upgradeEdges := filter.Filter(allBundles, filter.And(
filter.WithPackageName(installedBundle.Package),
filter.Replaces(installedBundle.Name, channels),
))
sort.SliceStable(upgradeEdges, func(i, j int) bool {
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])
Expand All @@ -138,9 +137,9 @@ func semverSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *cat
return nil, err
}

upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
catalogfilter.WithPackageName(installedBundle.Package),
catalogfilter.InMastermindsSemverRange(wantedVersionRangeConstraint),
upgradeEdges := filter.Filter(allBundles, filter.And(
filter.WithPackageName(installedBundle.Package),
filter.InMastermindsSemverRange(wantedVersionRangeConstraint),
))
sort.SliceStable(upgradeEdges, func(i, j int) bool {
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])
Expand Down
11 changes: 5 additions & 6 deletions internal/resolution/variablesources/required_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
"github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
)
Expand All @@ -36,23 +35,23 @@ func MakeRequiredPackageVariables(allBundles []*catalogmetadata.Bundle, allChann
},
)

predicates := []catalogfilter.Predicate[catalogmetadata.Bundle]{
catalogfilter.WithPackageName(packageName),
predicates := []filter.Predicate[catalogmetadata.Bundle]{
filter.WithPackageName(packageName),
}

if channelName != "" {
predicates = append(predicates, catalogfilter.InChannel(channelName, channels))
predicates = append(predicates, filter.InChannel(channelName, channels))
}

if versionRange != "" {
vr, err := mmsemver.NewConstraint(versionRange)
if err != nil {
return nil, fmt.Errorf("invalid version range %q: %w", versionRange, err)
}
predicates = append(predicates, catalogfilter.InMastermindsSemverRange(vr))
predicates = append(predicates, filter.InMastermindsSemverRange(vr))
}

resultSet := catalogfilter.Filter(allBundles, catalogfilter.And(predicates...))
resultSet := filter.Filter(allBundles, filter.And(predicates...))
if len(resultSet) == 0 {
if versionRange != "" && channelName != "" {
return nil, fmt.Errorf("no package %q matching version %q found in channel %q", packageName, versionRange, channelName)
Expand Down

0 comments on commit 71fe718

Please sign in to comment.