Skip to content

Commit

Permalink
Changes the structure of resolution packages
Browse files Browse the repository at this point in the history
Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
  • Loading branch information
m1kola committed Jun 26, 2023
1 parent a946081 commit 5f27a87
Show file tree
Hide file tree
Showing 21 changed files with 189 additions and 211 deletions.
4 changes: 2 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import (
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/internal/resolution/entitysources"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
"github.com/operator-framework/operator-controller/pkg/features"
)

Expand Down Expand Up @@ -105,7 +105,7 @@ func main() {
Scheme: mgr.GetScheme(),
Resolver: solver.NewDeppySolver(
entitysources.NewCatalogdEntitySource(mgr.GetClient()),
olm.NewOLMVariableSource(mgr.GetClient()),
variablesources.NewOperatorVariableSource(mgr.GetClient()),
),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Operator")
Expand Down
12 changes: 6 additions & 6 deletions internal/controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import (

operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/controllers/validators"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundlesanddependencies"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
"github.com/operator-framework/operator-controller/internal/resolution/entities"
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
)

// OperatorReconciler reconciles a Operator object
Expand Down Expand Up @@ -244,10 +244,10 @@ func mapBDStatusToInstalledCondition(existingTypedBundleDeployment *rukpakv1alph
}
}

func (r *OperatorReconciler) getBundleEntityFromSolution(solution *solver.Solution, packageName string) (*entity.BundleEntity, error) {
func (r *OperatorReconciler) getBundleEntityFromSolution(solution *solver.Solution, packageName string) (*entities.BundleEntity, error) {
for _, variable := range solution.SelectedVariables() {
switch v := variable.(type) {
case *bundlesanddependencies.BundleVariable:
case *variablesources.BundleVariable:
entityPkgName, err := v.BundleEntity().PackageName()
if err != nil {
return nil, err
Expand Down Expand Up @@ -358,13 +358,13 @@ func (r *OperatorReconciler) existingBundleDeploymentUnstructured(ctx context.Co
// rukpak bundle provisioner class name that is capable of unpacking the bundle type
func mapBundleMediaTypeToBundleProvisioner(mediaType string) (string, error) {
switch mediaType {
case entity.MediaTypePlain:
case entities.MediaTypePlain:
return "core-rukpak-io-plain", nil
// To ensure compatibility with bundles created with OLMv0 where the
// olm.bundle.mediatype property doesn't exist, we assume that if the
// property is empty (i.e doesn't exist) that the bundle is one created
// with OLMv0 and therefore should use the registry provisioner
case entity.MediaTypeRegistry, "":
case entities.MediaTypeRegistry, "":
return "core-rukpak-io-registry", nil
default:
return "", fmt.Errorf("unknown bundle mediatype: %s", mediaType)
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/operator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/conditionsets"
"github.com/operator-framework/operator-controller/internal/controllers"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
)

var _ = Describe("Operator Controller Test", func() {
Expand All @@ -35,7 +35,7 @@ var _ = Describe("Operator Controller Test", func() {
reconciler = &controllers.OperatorReconciler{
Client: cl,
Scheme: sch,
Resolver: solver.NewDeppySolver(testEntitySource, olm.NewOLMVariableSource(cl)),
Resolver: solver.NewDeppySolver(testEntitySource, variablesources.NewOperatorVariableSource(cl)),
}
})
When("the operator does not exist", func() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity
package entities

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package entity_test
package entities_test

import (
"fmt"
Expand All @@ -10,7 +10,7 @@ import (
"github.com/operator-framework/deppy/pkg/deppy/input"
"github.com/operator-framework/operator-registry/alpha/property"

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

func TestBundleEntity(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 deletions internal/resolution/entitysources/catalogdsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/operator-framework/operator-registry/alpha/property"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
"github.com/operator-framework/operator-controller/internal/resolution/entities"
)

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

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

imgValue, err := json.Marshal(bundle.Spec.Image)
if err != nil {
return nil, err
}
props[entity.PropertyBundlePath] = string(imgValue)
props[entities.PropertyBundlePath] = string(imgValue)
catalogScopedPkgName := fmt.Sprintf("%s-%s", bundle.Spec.Catalog.Name, bundle.Spec.Package)
bundlePkg := packageMetdatas[catalogScopedPkgName]
for _, ch := range bundlePkg.Spec.Channels {
Expand All @@ -110,12 +110,12 @@ func getEntities(ctx context.Context, client client.Client) (input.EntityList, e
ID: deppy.IdentifierFromString(fmt.Sprintf("%s%s%s", bundle.Name, bundle.Spec.Package, ch.Name)),
Properties: props,
}
entities = append(entities, entity)
entityList = append(entityList, entity)
}
}
}
}
return entities, nil
return entityList, nil
}

func fetchMetadata(ctx context.Context, client client.Client) (catalogd.BundleMetadataList, map[string]catalogd.Package, error) {
Expand Down
10 changes: 5 additions & 5 deletions internal/resolution/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/fake"

"github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/olm"
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
)

func TestOperatorResolver(t *testing.T) {
Expand Down Expand Up @@ -75,7 +75,7 @@ var _ = Describe("OperatorResolver", func() {
}
client := FakeClient(resources...)
entitySource := input.NewCacheQuerier(testEntityCache)
variableSource := olm.NewOLMVariableSource(client)
variableSource := variablesources.NewOperatorVariableSource(client)
resolver := solver.NewDeppySolver(entitySource, variableSource)
solution, err := resolver.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expand All @@ -95,7 +95,7 @@ var _ = Describe("OperatorResolver", func() {
var resources []client.Object
client := FakeClient(resources...)
entitySource := input.NewCacheQuerier(testEntityCache)
variableSource := olm.NewOLMVariableSource(client)
variableSource := variablesources.NewOperatorVariableSource(client)
resolver := solver.NewDeppySolver(entitySource, variableSource)
solution, err := resolver.Solve(context.Background())
Expect(err).ToNot(HaveOccurred())
Expand All @@ -113,7 +113,7 @@ var _ = Describe("OperatorResolver", func() {
}
client := FakeClient(resource)
entitySource := FailEntitySource{}
variableSource := olm.NewOLMVariableSource(client)
variableSource := variablesources.NewOperatorVariableSource(client)
resolver := solver.NewDeppySolver(entitySource, variableSource)
solution, err := resolver.Solve(context.Background())
Expect(solution).To(BeNil())
Expand All @@ -123,7 +123,7 @@ var _ = Describe("OperatorResolver", func() {
It("should return an error if the client throws an error", func() {
client := NewFailClientWithError(fmt.Errorf("something bad happened"))
entitySource := input.NewCacheQuerier(testEntityCache)
variableSource := olm.NewOLMVariableSource(client)
variableSource := variablesources.NewOperatorVariableSource(client)
resolver := solver.NewDeppySolver(entitySource, variableSource)
solution, err := resolver.Solve(context.Background())
Expect(solution).To(BeNil())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/blang/semver/v4"
"github.com/operator-framework/deppy/pkg/deppy/input"

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

func WithPackageName(packageName string) input.Predicate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/operator-framework/deppy/pkg/deppy/input"
"github.com/operator-framework/operator-registry/alpha/property"

olmentity "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/util/predicates"
olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities"
"github.com/operator-framework/operator-controller/internal/resolution/util/predicates"
)

func TestPredicates(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import (

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

"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
"github.com/operator-framework/operator-controller/internal/resolution/entities"
)

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

// first sort package lexical order
pkgOrder := packageOrder(e1, e2)
Expand Down Expand Up @@ -44,7 +44,7 @@ func compareErrors(err1 error, err2 error) int {
return 0
}

func packageOrder(e1, e2 *entity.BundleEntity) int {
func packageOrder(e1, e2 *entities.BundleEntity) int {
name1, err1 := e1.PackageName()
name2, err2 := e2.PackageName()
errComp := compareErrors(err1, err2)
Expand All @@ -54,7 +54,7 @@ func packageOrder(e1, e2 *entity.BundleEntity) int {
return strings.Compare(name1, name2)
}

func channelOrder(e1, e2 *entity.BundleEntity) int {
func channelOrder(e1, e2 *entities.BundleEntity) int {
channelProperties1, err1 := e1.ChannelProperties()
channelProperties2, err2 := e2.ChannelProperties()
errComp := compareErrors(err1, err2)
Expand All @@ -67,7 +67,7 @@ func channelOrder(e1, e2 *entity.BundleEntity) int {
return strings.Compare(channelProperties1.ChannelName, channelProperties2.ChannelName)
}

func versionOrder(e1, e2 *entity.BundleEntity) int {
func versionOrder(e1, e2 *entities.BundleEntity) int {
ver1, err1 := e1.Version()
ver2, err2 := e2.Version()
errComp := compareErrors(err1, err2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/operator-framework/deppy/pkg/deppy/input"
"github.com/operator-framework/operator-registry/alpha/property"

entitysort "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/util/sort"
entitysort "github.com/operator-framework/operator-controller/internal/resolution/util/sort"
)

func TestSort(t *testing.T) {
Expand Down
51 changes: 0 additions & 51 deletions internal/resolution/variable_sources/olm/olm.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package bundlesanddependencies
package variablesources

import (
"context"
Expand All @@ -10,10 +10,9 @@ import (
"github.com/operator-framework/deppy/pkg/deppy/constraint"
"github.com/operator-framework/deppy/pkg/deppy/input"

olmentity "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/entity"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/requiredpackage"
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/util/predicates"
entitysort "github.com/operator-framework/operator-controller/internal/resolution/variable_sources/util/sort"
olmentity "github.com/operator-framework/operator-controller/internal/resolution/entities"
"github.com/operator-framework/operator-controller/internal/resolution/util/predicates"
entitysort "github.com/operator-framework/operator-controller/internal/resolution/util/sort"
)

type BundleVariable struct {
Expand Down Expand Up @@ -74,7 +73,7 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context, entityS
var bundleEntityQueue []*olmentity.BundleEntity
for _, variable := range variables {
switch v := variable.(type) {
case *requiredpackage.Variable:
case *RequiredPackageVariable:
bundleEntityQueue = append(bundleEntityQueue, v.BundleEntities()...)
}
}
Expand Down
Loading

0 comments on commit 5f27a87

Please sign in to comment.