Skip to content

Add bundle data snapshotting for resolution #433

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 4 additions & 5 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ func main() {
catalogClient := catalogclient.New(cl, cache.NewFilesystemCache(cachePath, &http.Client{Timeout: 10 * time.Second}))

if err = (&controllers.OperatorReconciler{
Client: cl,
Scheme: mgr.GetScheme(),
Resolver: solver.NewDeppySolver(
controllers.NewVariableSource(cl, catalogClient),
),
Client: cl,
Scheme: mgr.GetScheme(),
CatalogClient: catalogClient,
NewSolver: solver.NewDeppySolver,
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Operator")
os.Exit(1)
Expand Down
28 changes: 28 additions & 0 deletions internal/catalogmetadata/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,34 @@ func (c *Client) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error)
return allBundles, nil
}

func NewSnapshotClient(catalogClient *Client) *SnapshotClient {
return &SnapshotClient{
Client: catalogClient,
}
}

// SnapshotClient fetches data from catalogs and caches them for the lifetime of the
// SnapshotClient instance. Meaning that any change to catalogs after the first call
// of the client will not affect set of bundles returned by this instance.
// This is convenient for bundle resolution process where we want all components
// to have the same view of catalogs.
type SnapshotClient struct {
*Client
bundlesSnapshot []*catalogmetadata.Bundle
}

func (c *SnapshotClient) Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error) {
if c.bundlesSnapshot == nil {
allBundles, err := c.Client.Bundles(ctx)
if err != nil {
return nil, err
}
c.bundlesSnapshot = allBundles
}

return c.bundlesSnapshot, nil
}

func PopulateExtraFields(catalogName string, channels []*catalogmetadata.Channel, bundles []*catalogmetadata.Bundle) ([]*catalogmetadata.Bundle, error) {
bundlesMap := map[string]*catalogmetadata.Bundle{}
for i := range bundles {
Expand Down
10 changes: 7 additions & 3 deletions internal/controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/go-logr/logr"
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
"github.com/operator-framework/deppy/pkg/deppy"
"github.com/operator-framework/deppy/pkg/deppy/input"
"github.com/operator-framework/deppy/pkg/deppy/solver"
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
"k8s.io/apimachinery/pkg/api/equality"
Expand All @@ -45,15 +46,17 @@ import (

operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
catalogclient "github.com/operator-framework/operator-controller/internal/catalogmetadata/client"
"github.com/operator-framework/operator-controller/internal/controllers/validators"
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
)

// OperatorReconciler reconciles a Operator object
type OperatorReconciler struct {
client.Client
Scheme *runtime.Scheme
Resolver *solver.DeppySolver
Scheme *runtime.Scheme
CatalogClient *catalogclient.Client
NewSolver func(variableSource input.VariableSource) *solver.DeppySolver
}

//+kubebuilder:rbac:groups=operators.operatorframework.io,resources=operators,verbs=get;list;watch
Expand Down Expand Up @@ -130,7 +133,8 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
return ctrl.Result{}, nil
}
// run resolution
solution, err := r.Resolver.Solve(ctx)
variableSource := NewVariableSource(r.Client, catalogclient.NewSnapshotClient(r.CatalogClient))
solution, err := r.NewSolver(variableSource).Solve(ctx)
if err != nil {
op.Status.InstalledBundleResource = ""
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution failed", op.GetGeneration())
Expand Down
11 changes: 8 additions & 3 deletions internal/controllers/operator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/operator-framework/deppy/pkg/deppy/input"
"github.com/operator-framework/deppy/pkg/deppy/solver"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/alpha/property"
Expand Down Expand Up @@ -37,9 +38,13 @@ var _ = Describe("Operator Controller Test", func() {
ctx = context.Background()
fakeCatalogClient = testutil.NewFakeCatalogClient(testBundleList)
reconciler = &controllers.OperatorReconciler{
Client: cl,
Scheme: sch,
Resolver: solver.NewDeppySolver(controllers.NewVariableSource(cl, &fakeCatalogClient)),
Client: cl,
Scheme: sch,
NewSolver: func(variableSource input.VariableSource) *solver.DeppySolver {
return solver.NewDeppySolver(
controllers.NewVariableSource(cl, &fakeCatalogClient),
)
},
}
})
When("the operator does not exist", func() {
Expand Down