Skip to content

Commit 52a1e28

Browse files
dtfranzMikalai Radchuk
andauthored
Remove Entities and EntitySources (#413)
* Updates codebase to use `catalogmetadata` package Signed-off-by: Mikalai Radchuk <[email protected]> Signed-off-by: Daniel Franz<[email protected]> * Updates resolutioncli to remove entity source Signed-off-by: Mikalai Radchuk <[email protected]> * Removes entity sources and GVK related code * Removes provides+required GVK and associated tests. GVK related code was a dead weight since were never set GVK properties on bundle entity. * Remove entity + entitysource and associated util pkgs Signed-off-by: dtfranz <[email protected]> * Deppy version bump, remove remaining entity/entitysource vestigials Signed-off-by: dtfranz <[email protected]> * Add interface for client mocking Signed-off-by: dtfranz <[email protected]> * Fix tests, bump catalogd, address comments. Signed-off-by: dtfranz <[email protected]> --------- Signed-off-by: Mikalai Radchuk <[email protected]> Signed-off-by: Daniel Franz<[email protected]> Signed-off-by: dtfranz <[email protected]> Co-authored-by: Mikalai Radchuk <[email protected]>
1 parent 6640aac commit 52a1e28

40 files changed

+1341
-2409
lines changed

cmd/manager/main.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
3636

3737
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
38+
catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
3839
"github.com/operator-framework/operator-controller/internal/controllers"
39-
"github.com/operator-framework/operator-controller/internal/resolution/entitysources"
4040
"github.com/operator-framework/operator-controller/pkg/features"
4141
)
4242

@@ -99,12 +99,14 @@ func main() {
9999
os.Exit(1)
100100
}
101101

102+
cl := mgr.GetClient()
103+
catalogClient := catalogclient.New(cl)
104+
102105
if err = (&controllers.OperatorReconciler{
103-
Client: mgr.GetClient(),
106+
Client: cl,
104107
Scheme: mgr.GetScheme(),
105108
Resolver: solver.NewDeppySolver(
106-
entitysources.NewCatalogdEntitySource(mgr.GetClient()),
107-
controllers.NewVariableSource(mgr.GetClient()),
109+
controllers.NewVariableSource(cl, catalogClient),
108110
),
109111
}).SetupWithManager(mgr); err != nil {
110112
setupLog.Error(err, "unable to create controller", "controller", "Operator")

cmd/resolutioncli/client.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package main
18+
19+
import (
20+
"context"
21+
22+
"github.com/operator-framework/operator-registry/alpha/action"
23+
24+
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
25+
"github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
26+
)
27+
28+
type indexRefClient struct {
29+
renderer action.Render
30+
bundlesCache []*catalogmetadata.Bundle
31+
}
32+
33+
func newIndexRefClient(indexRef string) *indexRefClient {
34+
return &indexRefClient{
35+
renderer: action.Render{
36+
Refs: []string{indexRef},
37+
AllowedRefMask: action.RefDCImage | action.RefDCDir,
38+
},
39+
}
40+
}
41+
42+
func (c *indexRefClient) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error) {
43+
if c.bundlesCache == nil {
44+
cfg, err := c.renderer.Run(ctx)
45+
if err != nil {
46+
return nil, err
47+
}
48+
49+
var (
50+
channels []*catalogmetadata.Channel
51+
bundles []*catalogmetadata.Bundle
52+
)
53+
54+
for i := range cfg.Channels {
55+
channels = append(channels, &catalogmetadata.Channel{
56+
Channel: cfg.Channels[i],
57+
})
58+
}
59+
60+
for i := range cfg.Bundles {
61+
bundles = append(bundles, &catalogmetadata.Bundle{
62+
Bundle: cfg.Bundles[i],
63+
})
64+
}
65+
66+
// TODO: update fake catalog name string to be catalog name once we support multiple catalogs in CLI
67+
catalogName := "offline-catalog"
68+
69+
bundles, err = client.PopulateExtraFields(catalogName, channels, bundles)
70+
if err != nil {
71+
return nil, err
72+
}
73+
74+
c.bundlesCache = bundles
75+
}
76+
77+
return c.bundlesCache, nil
78+
}

cmd/resolutioncli/entity_source.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

cmd/resolutioncli/main.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ import (
3434
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
3535

3636
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
37+
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
3738
"github.com/operator-framework/operator-controller/internal/controllers"
38-
olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities"
3939
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
4040
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
4141
)
@@ -108,7 +108,7 @@ func validateFlags(packageName, indexRef string) error {
108108
return nil
109109
}
110110

111-
func run(ctx context.Context, packageName, packageVersion, packageChannel, catalogRef, inputDir string) error {
111+
func run(ctx context.Context, packageName, packageVersion, packageChannel, indexRef, inputDir string) error {
112112
clientBuilder := fake.NewClientBuilder().WithScheme(scheme)
113113

114114
if inputDir != "" {
@@ -121,11 +121,12 @@ func run(ctx context.Context, packageName, packageVersion, packageChannel, catal
121121
}
122122

123123
cl := clientBuilder.Build()
124+
catalogClient := newIndexRefClient(indexRef)
125+
124126
resolver := solver.NewDeppySolver(
125-
newIndexRefEntitySourceEntitySource(catalogRef),
126127
append(
127-
variablesources.NestedVariableSource{newPackageVariableSource(packageName, packageVersion, packageChannel)},
128-
controllers.NewVariableSource(cl)...,
128+
variablesources.NestedVariableSource{newPackageVariableSource(catalogClient, packageName, packageVersion, packageChannel)},
129+
controllers.NewVariableSource(cl, catalogClient)...,
129130
),
130131
)
131132

@@ -144,32 +145,24 @@ func resolve(ctx context.Context, resolver *solver.DeppySolver, packageName stri
144145
return "", err
145146
}
146147

147-
bundleEntity, err := getBundleEntityFromSolution(solution, packageName)
148+
bundle, err := bundleFromSolution(solution, packageName)
148149
if err != nil {
149150
return "", err
150151
}
151152

152153
// Get the bundle image reference for the bundle
153-
bundleImage, err := bundleEntity.BundlePath()
154-
if err != nil {
155-
return "", err
156-
}
157-
158-
return bundleImage, nil
154+
return bundle.Image, nil
159155
}
160156

161-
func getBundleEntityFromSolution(solution *solver.Solution, packageName string) (*olmentity.BundleEntity, error) {
157+
func bundleFromSolution(solution *solver.Solution, packageName string) (*catalogmetadata.Bundle, error) {
162158
for _, variable := range solution.SelectedVariables() {
163159
switch v := variable.(type) {
164160
case *olmvariables.BundleVariable:
165-
entityPkgName, err := v.BundleEntity().PackageName()
166-
if err != nil {
167-
return nil, err
168-
}
169-
if packageName == entityPkgName {
170-
return v.BundleEntity(), nil
161+
bundlePkgName := v.Bundle().Package
162+
if packageName == bundlePkgName {
163+
return v.Bundle(), nil
171164
}
172165
}
173166
}
174-
return nil, fmt.Errorf("entity for package %q not found in solution", packageName)
167+
return nil, fmt.Errorf("bundle for package %q not found in solution", packageName)
175168
}

cmd/resolutioncli/variable_source.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import (
2222
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
2323
)
2424

25-
func newPackageVariableSource(packageName, packageVersion, packageChannel string) func(inputVariableSource input.VariableSource) (input.VariableSource, error) {
25+
func newPackageVariableSource(catalogClient *indexRefClient, packageName, packageVersion, packageChannel string) func(inputVariableSource input.VariableSource) (input.VariableSource, error) {
2626
return func(inputVariableSource input.VariableSource) (input.VariableSource, error) {
2727
pkgSource, err := variablesources.NewRequiredPackageVariableSource(
28+
catalogClient,
2829
packageName,
2930
variablesources.InVersionRange(packageVersion),
3031
variablesources.InChannel(packageChannel),

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ require (
66
github.com/Masterminds/semver/v3 v3.2.1
77
github.com/blang/semver/v4 v4.0.0
88
github.com/go-logr/logr v1.2.4
9-
github.com/google/go-cmp v0.5.9
109
github.com/onsi/ginkgo/v2 v2.12.1
1110
github.com/onsi/gomega v1.27.10
1211
github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42
1312
github.com/operator-framework/catalogd v0.6.0
14-
github.com/operator-framework/deppy v0.0.0-20230629133131-bb7b6ae7b266
13+
github.com/operator-framework/deppy v0.0.1
1514
github.com/operator-framework/operator-registry v1.28.0
1615
github.com/operator-framework/rukpak v0.13.0
1716
github.com/spf13/pflag v1.0.5
@@ -73,6 +72,7 @@ require (
7372
github.com/golang/protobuf v1.5.3 // indirect
7473
github.com/google/cel-go v0.12.6 // indirect
7574
github.com/google/gnostic v0.5.7-v3refs // indirect
75+
github.com/google/go-cmp v0.5.9 // indirect
7676
github.com/google/gofuzz v1.2.0 // indirect
7777
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
7878
github.com/google/uuid v1.3.0 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH
542542
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
543543
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
544544
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
545-
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
545+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
546546
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
547547
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
548548
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
@@ -704,8 +704,8 @@ github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42 h1:d/Pnr
704704
github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42/go.mod h1:l/cuwtPxkVUY7fzYgdust2m9tlmb8I4pOvbsUufRb24=
705705
github.com/operator-framework/catalogd v0.6.0 h1:dSZ54MVSHJ8hcoV7OCRxnk3x4O3ramlyPvvz0vsKYdk=
706706
github.com/operator-framework/catalogd v0.6.0/go.mod h1:I0n086a4a+nP1YZy742IrPaWvOlWu0Mj6qA6j4K96Vg=
707-
github.com/operator-framework/deppy v0.0.0-20230629133131-bb7b6ae7b266 h1:SQEUaAoRWNhr2poLH6z/RsEWZG7PppDWHsr5vAvJkJc=
708-
github.com/operator-framework/deppy v0.0.0-20230629133131-bb7b6ae7b266/go.mod h1:6kgHMeS5vQt3gqWGgJIig1yT5uflBUsCc1orP+I3nbk=
707+
github.com/operator-framework/deppy v0.0.1 h1:PLTtaFGwktPhKuKZkfUruTimrWpyaO3tghbsjs0uMjc=
708+
github.com/operator-framework/deppy v0.0.1/go.mod h1:EV6vnxRodSFRn2TFztfxFhMPGh5QufOhn3tpIP1Z8cc=
709709
github.com/operator-framework/operator-registry v1.28.0 h1:vtmd2WgJxkx7vuuOxW4k5Le/oo0SfonSeJVMU3rKIfk=
710710
github.com/operator-framework/operator-registry v1.28.0/go.mod h1:UYw3uaZyHwHgnczLRYmUqMpgRgP2EfkqOsaR+LI+nK8=
711711
github.com/operator-framework/rukpak v0.13.0 h1:QP0P9ybwtkFpfVOMY9z5v4+vRyBdoqAotv8RP/SZ0hw=
@@ -801,7 +801,7 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
801801
github.com/spf13/cobra v0.0.2-0.20171109065643-2da4a54c5cee/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
802802
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
803803
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
804-
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
804+
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
805805
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
806806
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
807807
github.com/spf13/pflag v1.0.1-0.20171106142849-4c012f6dcd95/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=

internal/catalogmetadata/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (c *Client) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error)
4141
return nil, err
4242
}
4343

44-
bundles, err = populateExtraFields(catalog.Name, channels, bundles)
44+
bundles, err = PopulateExtraFields(catalog.Name, channels, bundles)
4545
if err != nil {
4646
return nil, err
4747
}
@@ -67,7 +67,7 @@ func fetchCatalogMetadata[T catalogmetadata.Schemas](ctx context.Context, cl cli
6767
return content, nil
6868
}
6969

70-
func populateExtraFields(catalogName string, channels []*catalogmetadata.Channel, bundles []*catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
70+
func PopulateExtraFields(catalogName string, channels []*catalogmetadata.Channel, bundles []*catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
7171
bundlesMap := map[string]*catalogmetadata.Bundle{}
7272
for i := range bundles {
7373
bundleKey := fmt.Sprintf("%s-%s", bundles[i].Package, bundles[i].Name)

0 commit comments

Comments
 (0)