Skip to content

Commit a747143

Browse files
Mikalai Radchukm1kola
authored andcommitted
Changes the structure of resolution packages
Signed-off-by: Mikalai Radchuk <[email protected]>
1 parent 9a1a15d commit a747143

21 files changed

+189
-211
lines changed

cmd/manager/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
3838
"github.com/operator-framework/operator-controller/internal/controllers"
3939
"github.com/operator-framework/operator-controller/internal/resolution/entitysources"
40-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
40+
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
4141
"github.com/operator-framework/operator-controller/pkg/features"
4242
)
4343

@@ -105,7 +105,7 @@ func main() {
105105
Scheme: mgr.GetScheme(),
106106
Resolver: solver.NewDeppySolver(
107107
entitysources.NewCatalogdEntitySource(mgr.GetClient()),
108-
olm.NewOLMVariableSource(mgr.GetClient()),
108+
variablesources.NewOperatorVariableSource(mgr.GetClient()),
109109
),
110110
}).SetupWithManager(mgr); err != nil {
111111
setupLog.Error(err, "unable to create controller", "controller", "Operator")

internal/controllers/operator_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import (
4141

4242
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
4343
"github.com/operator-framework/operator-controller/internal/controllers/validators"
44-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundlesanddependencies"
45-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
44+
"github.com/operator-framework/operator-controller/internal/resolution/entities"
45+
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
4646
)
4747

4848
// OperatorReconciler reconciles a Operator object
@@ -244,10 +244,10 @@ func mapBDStatusToInstalledCondition(existingTypedBundleDeployment *rukpakv1alph
244244
}
245245
}
246246

247-
func (r *OperatorReconciler) getBundleEntityFromSolution(solution *solver.Solution, packageName string) (*entity.BundleEntity, error) {
247+
func (r *OperatorReconciler) getBundleEntityFromSolution(solution *solver.Solution, packageName string) (*entities.BundleEntity, error) {
248248
for _, variable := range solution.SelectedVariables() {
249249
switch v := variable.(type) {
250-
case *bundlesanddependencies.BundleVariable:
250+
case *variablesources.BundleVariable:
251251
entityPkgName, err := v.BundleEntity().PackageName()
252252
if err != nil {
253253
return nil, err
@@ -358,13 +358,13 @@ func (r *OperatorReconciler) existingBundleDeploymentUnstructured(ctx context.Co
358358
// rukpak bundle provisioner class name that is capable of unpacking the bundle type
359359
func mapBundleMediaTypeToBundleProvisioner(mediaType string) (string, error) {
360360
switch mediaType {
361-
case entity.MediaTypePlain:
361+
case entities.MediaTypePlain:
362362
return "core-rukpak-io-plain", nil
363363
// To ensure compatibility with bundles created with OLMv0 where the
364364
// olm.bundle.mediatype property doesn't exist, we assume that if the
365365
// property is empty (i.e doesn't exist) that the bundle is one created
366366
// with OLMv0 and therefore should use the registry provisioner
367-
case entity.MediaTypeRegistry, "":
367+
case entities.MediaTypeRegistry, "":
368368
return "core-rukpak-io-registry", nil
369369
default:
370370
return "", fmt.Errorf("unknown bundle mediatype: %s", mediaType)

internal/controllers/operator_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
2323
"github.com/operator-framework/operator-controller/internal/conditionsets"
2424
"github.com/operator-framework/operator-controller/internal/controllers"
25-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
25+
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
2626
)
2727

2828
var _ = Describe("Operator Controller Test", func() {
@@ -35,7 +35,7 @@ var _ = Describe("Operator Controller Test", func() {
3535
reconciler = &controllers.OperatorReconciler{
3636
Client: cl,
3737
Scheme: sch,
38-
Resolver: solver.NewDeppySolver(testEntitySource, olm.NewOLMVariableSource(cl)),
38+
Resolver: solver.NewDeppySolver(testEntitySource, variablesources.NewOperatorVariableSource(cl)),
3939
}
4040
})
4141
When("the operator does not exist", func() {

internal/resolution/variable_sources/entity/bundle_entity.go renamed to internal/resolution/entities/bundle_entity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package entity
1+
package entities
22

33
import (
44
"encoding/json"

internal/resolution/variable_sources/entity/bundle_entity_test.go renamed to internal/resolution/entities/bundle_entity_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package entity_test
1+
package entities_test
22

33
import (
44
"fmt"
@@ -10,7 +10,7 @@ import (
1010
"github.com/operator-framework/deppy/pkg/deppy/input"
1111
"github.com/operator-framework/operator-registry/alpha/property"
1212

13-
olmentity "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
13+
olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities"
1414
)
1515

1616
func TestBundleEntity(t *testing.T) {

internal/resolution/entitysources/catalogdsource.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/operator-framework/operator-registry/alpha/property"
1212
"sigs.k8s.io/controller-runtime/pkg/client"
1313

14-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
14+
"github.com/operator-framework/operator-controller/internal/resolution/entities"
1515
)
1616

1717
// CatalogdEntitySource is a source for(/collection of) deppy defined input.Entity, built from content
@@ -72,7 +72,7 @@ func (es *CatalogdEntitySource) Iterate(ctx context.Context, fn input.IteratorFu
7272
}
7373

7474
func getEntities(ctx context.Context, client client.Client) (input.EntityList, error) {
75-
entities := input.EntityList{}
75+
entityList := input.EntityList{}
7676
bundleMetadatas, packageMetdatas, err := fetchMetadata(ctx, client)
7777
if err != nil {
7878
return nil, err
@@ -88,16 +88,16 @@ func getEntities(ctx context.Context, client client.Client) (input.EntityList, e
8888
// this is already a json marshalled object, so it doesn't need to be marshalled
8989
// like the other ones
9090
props[property.TypePackage] = string(prop.Value)
91-
case entity.PropertyBundleMediaType:
92-
props[entity.PropertyBundleMediaType] = string(prop.Value)
91+
case entities.PropertyBundleMediaType:
92+
props[entities.PropertyBundleMediaType] = string(prop.Value)
9393
}
9494
}
9595

9696
imgValue, err := json.Marshal(bundle.Spec.Image)
9797
if err != nil {
9898
return nil, err
9999
}
100-
props[entity.PropertyBundlePath] = string(imgValue)
100+
props[entities.PropertyBundlePath] = string(imgValue)
101101
catalogScopedPkgName := fmt.Sprintf("%s-%s", bundle.Spec.Catalog.Name, bundle.Spec.Package)
102102
bundlePkg := packageMetdatas[catalogScopedPkgName]
103103
for _, ch := range bundlePkg.Spec.Channels {
@@ -110,12 +110,12 @@ func getEntities(ctx context.Context, client client.Client) (input.EntityList, e
110110
ID: deppy.IdentifierFromString(fmt.Sprintf("%s%s%s", bundle.Name, bundle.Spec.Package, ch.Name)),
111111
Properties: props,
112112
}
113-
entities = append(entities, entity)
113+
entityList = append(entityList, entity)
114114
}
115115
}
116116
}
117117
}
118-
return entities, nil
118+
return entityList, nil
119119
}
120120

121121
func fetchMetadata(ctx context.Context, client client.Client) (catalogd.BundleMetadataList, map[string]catalogd.Package, error) {

internal/resolution/resolver_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1717

1818
"github.com/operator-framework/operator-controller/api/v1alpha1"
19-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
19+
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
2020
)
2121

2222
func TestOperatorResolver(t *testing.T) {
@@ -75,7 +75,7 @@ var _ = Describe("OperatorResolver", func() {
7575
}
7676
client := FakeClient(resources...)
7777
entitySource := input.NewCacheQuerier(testEntityCache)
78-
variableSource := olm.NewOLMVariableSource(client)
78+
variableSource := variablesources.NewOperatorVariableSource(client)
7979
resolver := solver.NewDeppySolver(entitySource, variableSource)
8080
solution, err := resolver.Solve(context.Background())
8181
Expect(err).ToNot(HaveOccurred())
@@ -95,7 +95,7 @@ var _ = Describe("OperatorResolver", func() {
9595
var resources []client.Object
9696
client := FakeClient(resources...)
9797
entitySource := input.NewCacheQuerier(testEntityCache)
98-
variableSource := olm.NewOLMVariableSource(client)
98+
variableSource := variablesources.NewOperatorVariableSource(client)
9999
resolver := solver.NewDeppySolver(entitySource, variableSource)
100100
solution, err := resolver.Solve(context.Background())
101101
Expect(err).ToNot(HaveOccurred())
@@ -113,7 +113,7 @@ var _ = Describe("OperatorResolver", func() {
113113
}
114114
client := FakeClient(resource)
115115
entitySource := FailEntitySource{}
116-
variableSource := olm.NewOLMVariableSource(client)
116+
variableSource := variablesources.NewOperatorVariableSource(client)
117117
resolver := solver.NewDeppySolver(entitySource, variableSource)
118118
solution, err := resolver.Solve(context.Background())
119119
Expect(solution).To(BeNil())
@@ -123,7 +123,7 @@ var _ = Describe("OperatorResolver", func() {
123123
It("should return an error if the client throws an error", func() {
124124
client := NewFailClientWithError(fmt.Errorf("something bad happened"))
125125
entitySource := input.NewCacheQuerier(testEntityCache)
126-
variableSource := olm.NewOLMVariableSource(client)
126+
variableSource := variablesources.NewOperatorVariableSource(client)
127127
resolver := solver.NewDeppySolver(entitySource, variableSource)
128128
solution, err := resolver.Solve(context.Background())
129129
Expect(solution).To(BeNil())

internal/resolution/variable_sources/util/predicates/predicates.go renamed to internal/resolution/util/predicates/predicates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"github.com/blang/semver/v4"
55
"github.com/operator-framework/deppy/pkg/deppy/input"
66

7-
olmentity "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
7+
olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities"
88
)
99

1010
func WithPackageName(packageName string) input.Predicate {

internal/resolution/variable_sources/util/predicates/predicates_test.go renamed to internal/resolution/util/predicates/predicates_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99
"github.com/operator-framework/deppy/pkg/deppy/input"
1010
"github.com/operator-framework/operator-registry/alpha/property"
1111

12-
olmentity "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
13-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/util/predicates"
12+
olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities"
13+
"github.com/operator-framework/operator-controller/internal/resolution/util/predicates"
1414
)
1515

1616
func TestPredicates(t *testing.T) {

internal/resolution/variable_sources/util/sort/sort.go renamed to internal/resolution/util/sort/sort.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import (
55

66
"github.com/operator-framework/deppy/pkg/deppy/input"
77

8-
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
8+
"github.com/operator-framework/operator-controller/internal/resolution/entities"
99
)
1010

1111
// ByChannelAndVersion is an entity sort function that orders the entities in
1212
// package, channel (default channel at the head), and inverse version (higher versions on top)
1313
// if a property does not exist for one of the entities, the one missing the property is pushed down
1414
// if both entities are missing the same property they are ordered by id
1515
func ByChannelAndVersion(entity1 *input.Entity, entity2 *input.Entity) bool {
16-
e1 := entity.NewBundleEntity(entity1)
17-
e2 := entity.NewBundleEntity(entity2)
16+
e1 := entities.NewBundleEntity(entity1)
17+
e2 := entities.NewBundleEntity(entity2)
1818

1919
// first sort package lexical order
2020
pkgOrder := packageOrder(e1, e2)
@@ -44,7 +44,7 @@ func compareErrors(err1 error, err2 error) int {
4444
return 0
4545
}
4646

47-
func packageOrder(e1, e2 *entity.BundleEntity) int {
47+
func packageOrder(e1, e2 *entities.BundleEntity) int {
4848
name1, err1 := e1.PackageName()
4949
name2, err2 := e2.PackageName()
5050
errComp := compareErrors(err1, err2)
@@ -54,7 +54,7 @@ func packageOrder(e1, e2 *entity.BundleEntity) int {
5454
return strings.Compare(name1, name2)
5555
}
5656

57-
func channelOrder(e1, e2 *entity.BundleEntity) int {
57+
func channelOrder(e1, e2 *entities.BundleEntity) int {
5858
channelProperties1, err1 := e1.ChannelProperties()
5959
channelProperties2, err2 := e2.ChannelProperties()
6060
errComp := compareErrors(err1, err2)
@@ -67,7 +67,7 @@ func channelOrder(e1, e2 *entity.BundleEntity) int {
6767
return strings.Compare(channelProperties1.ChannelName, channelProperties2.ChannelName)
6868
}
6969

70-
func versionOrder(e1, e2 *entity.BundleEntity) int {
70+
func versionOrder(e1, e2 *entities.BundleEntity) int {
7171
ver1, err1 := e1.Version()
7272
ver2, err2 := e2.Version()
7373
errComp := compareErrors(err1, err2)

0 commit comments

Comments
 (0)