Skip to content

Commit 71fe718

Browse files
committed
fix linter errors
Signed-off-by: everettraven <[email protected]>
1 parent 08996d5 commit 71fe718

File tree

4 files changed

+78
-40
lines changed

4 files changed

+78
-40
lines changed

cmd/resolutioncli/client.go

+62-21
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,22 @@ import (
2020
"context"
2121

2222
"github.com/operator-framework/operator-registry/alpha/action"
23+
"github.com/operator-framework/operator-registry/alpha/declcfg"
2324

2425
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
26+
"github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
27+
"github.com/operator-framework/operator-controller/internal/controllers"
2528
)
2629

2730
type indexRefClient struct {
28-
renderer action.Render
29-
bundlesCache []*catalogmetadata.Bundle
31+
renderer action.Render
32+
bundlesCache []*catalogmetadata.Bundle
33+
channelsCache []*catalogmetadata.Channel
34+
packagesCache []*catalogmetadata.Package
3035
}
3136

37+
var _ controllers.CatalogProvider = &indexRefClient{}
38+
3239
func newIndexRefClient(indexRef string) *indexRefClient {
3340
return &indexRefClient{
3441
renderer: action.Render{
@@ -38,47 +45,81 @@ func newIndexRefClient(indexRef string) *indexRefClient {
3845
}
3946
}
4047

41-
func (c *indexRefClient) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error) {
42-
if c.bundlesCache == nil {
48+
func (c *indexRefClient) CatalogContents(ctx context.Context) (*client.Contents, error) {
49+
if c.bundlesCache == nil || c.channelsCache == nil || c.packagesCache == nil {
4350
cfg, err := c.renderer.Run(ctx)
4451
if err != nil {
4552
return nil, err
4653
}
4754

4855
var (
49-
channels []*catalogmetadata.Channel
50-
bundles []*catalogmetadata.Bundle
51-
deprecations []*catalogmetadata.Deprecation
56+
channels []*catalogmetadata.Channel
57+
bundles []*catalogmetadata.Bundle
58+
packages []*catalogmetadata.Package
5259
)
5360

61+
// TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
62+
catalogName := "offline-catalog"
63+
64+
for i := range cfg.Packages {
65+
packages = append(packages, &catalogmetadata.Package{
66+
Package: cfg.Packages[i],
67+
Catalog: catalogName,
68+
})
69+
}
70+
5471
for i := range cfg.Channels {
5572
channels = append(channels, &catalogmetadata.Channel{
5673
Channel: cfg.Channels[i],
74+
Catalog: catalogName,
5775
})
5876
}
5977

6078
for i := range cfg.Bundles {
6179
bundles = append(bundles, &catalogmetadata.Bundle{
62-
Bundle: cfg.Bundles[i],
80+
Bundle: cfg.Bundles[i],
81+
Catalog: catalogName,
6382
})
6483
}
6584

66-
for i := range cfg.Deprecations {
67-
deprecations = append(deprecations, &catalogmetadata.Deprecation{
68-
Deprecation: cfg.Deprecations[i],
69-
})
85+
for _, deprecation := range cfg.Deprecations {
86+
for _, entry := range deprecation.Entries {
87+
switch entry.Reference.Schema {
88+
case declcfg.SchemaPackage:
89+
for _, pkg := range packages {
90+
if pkg.Name == deprecation.Package {
91+
pkg.Deprecation = &declcfg.DeprecationEntry{
92+
Reference: entry.Reference,
93+
Message: entry.Message,
94+
}
95+
}
96+
}
97+
case declcfg.SchemaChannel:
98+
for _, channel := range channels {
99+
if channel.Package == deprecation.Package && channel.Name == entry.Reference.Name {
100+
channel.Deprecation = &declcfg.DeprecationEntry{
101+
Reference: entry.Reference,
102+
Message: entry.Message,
103+
}
104+
}
105+
}
106+
case declcfg.SchemaBundle:
107+
for _, bundle := range bundles {
108+
if bundle.Package == deprecation.Package && bundle.Name == entry.Reference.Name {
109+
bundle.Deprecation = &declcfg.DeprecationEntry{
110+
Reference: entry.Reference,
111+
Message: entry.Message,
112+
}
113+
}
114+
}
115+
}
116+
}
70117
}
71118

72-
// TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
73-
// catalogName := "offline-catalog"
74-
75-
// bundles, err = client.PopulateExtraFields(catalogName, channels, bundles, deprecations)
76-
// if err != nil {
77-
// return nil, err
78-
// }
79-
80119
c.bundlesCache = bundles
120+
c.channelsCache = channels
121+
c.packagesCache = packages
81122
}
82123

83-
return c.bundlesCache, nil
124+
return &client.Contents{}, nil
84125
}

cmd/resolutioncli/main.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import (
3636

3737
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
3838
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
39-
"github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
4039
"github.com/operator-framework/operator-controller/internal/controllers"
4140
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
4241
)
@@ -151,7 +150,7 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
151150

152151
cl := clientBuilder.Build()
153152
catalogClient := newIndexRefClient(indexRef)
154-
allBundles, err := catalogClient.Bundles(ctx)
153+
contents, err := catalogClient.CatalogContents(ctx)
155154
if err != nil {
156155
return err
157156
}
@@ -163,7 +162,7 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
163162
if err := cl.List(ctx, &bundleDeploymentList); err != nil {
164163
return err
165164
}
166-
variables, err := controllers.GenerateVariables(&client.Contents{Bundles: allBundles}, clusterExtensionList.Items, bundleDeploymentList.Items)
165+
variables, err := controllers.GenerateVariables(contents, clusterExtensionList.Items, bundleDeploymentList.Items)
167166
if err != nil {
168167
return err
169168
}

internal/resolution/variablesources/installed_package.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
1313
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
1414
"github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
15-
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
1615
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
1716
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
1817
"github.com/operator-framework/operator-controller/pkg/features"
@@ -62,9 +61,9 @@ func MakeInstalledPackageVariables(
6261
bundleImage := sourceImage.Ref
6362

6463
// find corresponding bundle for the installed content
65-
resultSet := catalogfilter.Filter(allBundles, catalogfilter.And(
66-
catalogfilter.WithPackageName(clusterExtension.Spec.PackageName),
67-
catalogfilter.WithImage(bundleImage),
64+
resultSet := filter.Filter(allBundles, filter.And(
65+
filter.WithPackageName(clusterExtension.Spec.PackageName),
66+
filter.WithImage(bundleImage),
6867
))
6968
if len(resultSet) == 0 {
7069
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)
@@ -110,9 +109,9 @@ type successorsFunc func(allBundles []*catalogmetadata.Bundle, installedBundle *
110109
func legacySemanticsSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *catalogmetadata.Bundle, channels []*catalogmetadata.Channel) ([]*catalogmetadata.Bundle, error) {
111110
// find the bundles that replace the bundle provided
112111
// TODO: this algorithm does not yet consider skips and skipRange
113-
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
114-
catalogfilter.WithPackageName(installedBundle.Package),
115-
catalogfilter.Replaces(installedBundle.Name, channels),
112+
upgradeEdges := filter.Filter(allBundles, filter.And(
113+
filter.WithPackageName(installedBundle.Package),
114+
filter.Replaces(installedBundle.Name, channels),
116115
))
117116
sort.SliceStable(upgradeEdges, func(i, j int) bool {
118117
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])
@@ -138,9 +137,9 @@ func semverSuccessors(allBundles []*catalogmetadata.Bundle, installedBundle *cat
138137
return nil, err
139138
}
140139

141-
upgradeEdges := catalogfilter.Filter(allBundles, catalogfilter.And(
142-
catalogfilter.WithPackageName(installedBundle.Package),
143-
catalogfilter.InMastermindsSemverRange(wantedVersionRangeConstraint),
140+
upgradeEdges := filter.Filter(allBundles, filter.And(
141+
filter.WithPackageName(installedBundle.Package),
142+
filter.InMastermindsSemverRange(wantedVersionRangeConstraint),
144143
))
145144
sort.SliceStable(upgradeEdges, func(i, j int) bool {
146145
return catalogsort.ByVersion(upgradeEdges[i], upgradeEdges[j])

internal/resolution/variablesources/required_package.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
ocv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
1010
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
1111
"github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
12-
catalogfilter "github.com/operator-framework/operator-controller/internal/catalogmetadata/filter"
1312
catalogsort "github.com/operator-framework/operator-controller/internal/catalogmetadata/sort"
1413
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
1514
)
@@ -36,23 +35,23 @@ func MakeRequiredPackageVariables(allBundles []*catalogmetadata.Bundle, allChann
3635
},
3736
)
3837

39-
predicates := []catalogfilter.Predicate[catalogmetadata.Bundle]{
40-
catalogfilter.WithPackageName(packageName),
38+
predicates := []filter.Predicate[catalogmetadata.Bundle]{
39+
filter.WithPackageName(packageName),
4140
}
4241

4342
if channelName != "" {
44-
predicates = append(predicates, catalogfilter.InChannel(channelName, channels))
43+
predicates = append(predicates, filter.InChannel(channelName, channels))
4544
}
4645

4746
if versionRange != "" {
4847
vr, err := mmsemver.NewConstraint(versionRange)
4948
if err != nil {
5049
return nil, fmt.Errorf("invalid version range %q: %w", versionRange, err)
5150
}
52-
predicates = append(predicates, catalogfilter.InMastermindsSemverRange(vr))
51+
predicates = append(predicates, filter.InMastermindsSemverRange(vr))
5352
}
5453

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

0 commit comments

Comments
 (0)