Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes the structure of resolution packages #273

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
)

// 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 *olmvariables.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.

58 changes: 58 additions & 0 deletions internal/resolution/variables/bundle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package variables

import (
"github.com/operator-framework/deppy/pkg/deppy"
"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/entities"
)

var _ deppy.Variable = &BundleVariable{}

type BundleVariable struct {
*input.SimpleVariable
bundleEntity *olmentity.BundleEntity
dependencies []*olmentity.BundleEntity
}

func (b *BundleVariable) BundleEntity() *olmentity.BundleEntity {
return b.bundleEntity
}

func (b *BundleVariable) Dependencies() []*olmentity.BundleEntity {
return b.dependencies
}

func NewBundleVariable(bundleEntity *olmentity.BundleEntity, dependencyBundleEntities []*olmentity.BundleEntity) *BundleVariable {
dependencyIDs := make([]deppy.Identifier, 0, len(dependencyBundleEntities))
for _, bundle := range dependencyBundleEntities {
dependencyIDs = append(dependencyIDs, bundle.ID)
}
var constraints []deppy.Constraint
if len(dependencyIDs) > 0 {
constraints = append(constraints, constraint.Dependency(dependencyIDs...))
}
return &BundleVariable{
SimpleVariable: input.NewSimpleVariable(bundleEntity.ID, constraints...),
bundleEntity: bundleEntity,
dependencies: dependencyBundleEntities,
}
}

var _ deppy.Variable = &BundleUniquenessVariable{}

type BundleUniquenessVariable struct {
*input.SimpleVariable
}

// NewBundleUniquenessVariable creates a new variable that instructs the resolver to choose at most a single bundle
// from the input 'atMostID'. Examples:
// 1. restrict the solution to at most a single bundle per package
// 2. restrict the solution to at most a single bundler per provided gvk
// this guarantees that no two operators provide the same gvk and no two version of the same operator are running at the same time
func NewBundleUniquenessVariable(id deppy.Identifier, atMostIDs ...deppy.Identifier) *BundleUniquenessVariable {
return &BundleUniquenessVariable{
SimpleVariable: input.NewSimpleVariable(id, constraint.AtMost(1, atMostIDs...)),
}
}
Loading
Loading