Skip to content

Commit ba21cdf

Browse files
authored
Upgrade Deppy (#560)
New version contains breaking changes: Deppy no longer has variable source API. Instead it accepts a slice of variables as input. Signed-off-by: Mikalai Radchuk <mradchuk@redhat.com>
1 parent d1cef1f commit ba21cdf

File tree

9 files changed

+82
-75
lines changed

9 files changed

+82
-75
lines changed

cmd/manager/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,10 @@ func main() {
110110
catalogClient := catalogclient.New(cl, cache.NewFilesystemCache(cachePath, &http.Client{Timeout: 10 * time.Second}))
111111

112112
if err = (&controllers.OperatorReconciler{
113-
Client: cl,
114-
Scheme: mgr.GetScheme(),
115-
Resolver: solver.NewDeppySolver(
116-
controllers.NewVariableSource(cl, catalogClient),
117-
),
113+
Client: cl,
114+
BundleProvider: catalogClient,
115+
Scheme: mgr.GetScheme(),
116+
Resolver: solver.NewDeppySolver(),
118117
}).SetupWithManager(mgr); err != nil {
119118
setupLog.Error(err, "unable to create controller", "controller", "Operator")
120119
os.Exit(1)

cmd/resolutioncli/main.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3232

3333
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
34+
"github.com/operator-framework/deppy/pkg/deppy"
3435
"github.com/operator-framework/deppy/pkg/deppy/solver"
3536
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
3637

@@ -143,14 +144,28 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
143144
},
144145
})
145146

147+
resolver := solver.NewDeppySolver()
148+
146149
cl := clientBuilder.Build()
147150
catalogClient := newIndexRefClient(indexRef)
151+
allBundles, err := catalogClient.Bundles(ctx)
152+
if err != nil {
153+
return err
154+
}
155+
operatorList := operatorsv1alpha1.OperatorList{}
156+
if err := cl.List(ctx, &operatorList); err != nil {
157+
return err
158+
}
159+
bundleDeploymentList := rukpakv1alpha1.BundleDeploymentList{}
160+
if err := cl.List(ctx, &bundleDeploymentList); err != nil {
161+
return err
162+
}
163+
variables, err := controllers.GenerateVariables(allBundles, operatorList.Items, bundleDeploymentList.Items)
164+
if err != nil {
165+
return err
166+
}
148167

149-
resolver := solver.NewDeppySolver(
150-
controllers.NewVariableSource(cl, catalogClient),
151-
)
152-
153-
bundleImage, err := resolve(ctx, resolver, packageName)
168+
bundleImage, err := resolve(resolver, variables, packageName)
154169
if err != nil {
155170
return err
156171
}
@@ -159,8 +174,8 @@ func run(ctx context.Context, packageName, packageChannel, packageVersionRange,
159174
return nil
160175
}
161176

162-
func resolve(ctx context.Context, resolver *solver.DeppySolver, packageName string) (string, error) {
163-
solution, err := resolver.Solve(ctx)
177+
func resolve(resolver *solver.DeppySolver, variables []deppy.Variable, packageName string) (string, error) {
178+
solution, err := resolver.Solve(variables)
164179
if err != nil {
165180
return "", err
166181
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/go-logr/logr v1.3.0
99
github.com/google/go-cmp v0.6.0
1010
github.com/operator-framework/catalogd v0.10.0
11-
github.com/operator-framework/deppy v0.1.0
11+
github.com/operator-framework/deppy v0.2.0
1212
github.com/operator-framework/operator-registry v1.32.0
1313
github.com/operator-framework/rukpak v0.16.0
1414
github.com/spf13/pflag v1.0.5

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ github.com/operator-framework/api v0.19.0 h1:QU1CTJU+CufoeneA5rsNlP/uP96s8vDHWUY
690690
github.com/operator-framework/api v0.19.0/go.mod h1:SCCslqke6AVOJ5JM+NqNE1CHuAgJLScsL66pnPaSMXs=
691691
github.com/operator-framework/catalogd v0.10.0 h1:T207IQfQCcd3f31bDPCgfJcwEvmaPGV8BotqIzIvnRo=
692692
github.com/operator-framework/catalogd v0.10.0/go.mod h1:xIeR5f/Spr5rHnLp0yOi0AYetWcHvBAx9n+K3S/va2A=
693-
github.com/operator-framework/deppy v0.1.0 h1:Kj6SgSSMsPTbiWObYe7P1JPsW6CWkuVc+38RnPcZxGQ=
694-
github.com/operator-framework/deppy v0.1.0/go.mod h1:3blHej0Hj0M17Ru2q3QrhN9OwB5/MMmFkWUmiInqs6A=
693+
github.com/operator-framework/deppy v0.2.0 h1:BYdCAKli+ofFdnHPkpUKI9DygHL2A32CaDbEJk4jz6U=
694+
github.com/operator-framework/deppy v0.2.0/go.mod h1:3blHej0Hj0M17Ru2q3QrhN9OwB5/MMmFkWUmiInqs6A=
695695
github.com/operator-framework/operator-registry v1.32.0 h1:RNazXYt3vBf5FZ+JrNNjq4bNh3tDwlkwZJnC+kmCeKk=
696696
github.com/operator-framework/operator-registry v1.32.0/go.mod h1:89VshAf6+n0V12vdh43+WOi8i1+XpY+kg6Ao4JO0y6k=
697697
github.com/operator-framework/rukpak v0.16.0 h1:d6iI7lYJbR5fHqw3vnAudB5SevAQ2dnQI7C6iOZyXJU=

internal/controllers/operator_controller.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/go-logr/logr"
2424
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
25+
"github.com/operator-framework/deppy/pkg/deppy"
2526
"github.com/operator-framework/deppy/pkg/deppy/solver"
2627
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
2728
"k8s.io/apimachinery/pkg/api/equality"
@@ -44,11 +45,18 @@ import (
4445
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
4546
)
4647

48+
// BundleProvider provides the way to retrieve a list of Bundles from a source,
49+
// generally from a catalog client of some kind.
50+
type BundleProvider interface {
51+
Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error)
52+
}
53+
4754
// OperatorReconciler reconciles a Operator object
4855
type OperatorReconciler struct {
4956
client.Client
50-
Scheme *runtime.Scheme
51-
Resolver *solver.DeppySolver
57+
BundleProvider BundleProvider
58+
Scheme *runtime.Scheme
59+
Resolver *solver.DeppySolver
5260
}
5361

5462
//+kubebuilder:rbac:groups=operators.operatorframework.io,resources=operators,verbs=get;list;watch
@@ -124,8 +132,19 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
124132
setResolvedStatusConditionUnknown(&op.Status.Conditions, "validation has not been attempted as spec is invalid", op.GetGeneration())
125133
return ctrl.Result{}, nil
126134
}
135+
136+
// gather vars for resolution
137+
vars, err := r.variables(ctx)
138+
if err != nil {
139+
op.Status.InstalledBundleResource = ""
140+
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted due to failure to gather data for resolution", op.GetGeneration())
141+
op.Status.ResolvedBundleResource = ""
142+
setResolvedStatusConditionFailed(&op.Status.Conditions, err.Error(), op.GetGeneration())
143+
return ctrl.Result{}, err
144+
}
145+
127146
// run resolution
128-
solution, err := r.Resolver.Solve(ctx)
147+
solution, err := r.Resolver.Solve(vars)
129148
if err != nil {
130149
op.Status.InstalledBundleResource = ""
131150
setInstalledStatusConditionUnknown(&op.Status.Conditions, "installation has not been attempted as resolution failed", op.GetGeneration())
@@ -194,6 +213,23 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
194213
return ctrl.Result{}, nil
195214
}
196215

216+
func (r *OperatorReconciler) variables(ctx context.Context) ([]deppy.Variable, error) {
217+
allBundles, err := r.BundleProvider.Bundles(ctx)
218+
if err != nil {
219+
return nil, err
220+
}
221+
operatorList := operatorsv1alpha1.OperatorList{}
222+
if err := r.Client.List(ctx, &operatorList); err != nil {
223+
return nil, err
224+
}
225+
bundleDeploymentList := rukpakv1alpha1.BundleDeploymentList{}
226+
if err := r.Client.List(ctx, &bundleDeploymentList); err != nil {
227+
return nil, err
228+
}
229+
230+
return GenerateVariables(allBundles, operatorList.Items, bundleDeploymentList.Items)
231+
}
232+
197233
func mapBDStatusToInstalledCondition(existingTypedBundleDeployment *rukpakv1alpha1.BundleDeployment, op *operatorsv1alpha1.Operator) {
198234
bundleDeploymentReady := apimeta.FindStatusCondition(existingTypedBundleDeployment.Status.Conditions, rukpakv1alpha1.TypeInstalled)
199235
if bundleDeploymentReady == nil {

internal/controllers/operator_controller_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func TestOperatorNonExistantVersion(t *testing.T) {
117117
require.NotNil(t, cond)
118118
require.Equal(t, metav1.ConditionUnknown, cond.Status)
119119
require.Equal(t, operatorsv1alpha1.ReasonInstallationStatusUnknown, cond.Reason)
120-
require.Equal(t, "installation has not been attempted as resolution failed", cond.Message)
120+
require.Equal(t, "installation has not been attempted due to failure to gather data for resolution", cond.Message)
121121

122122
verifyInvariants(ctx, t, reconciler.Client, operator)
123123
require.NoError(t, cl.DeleteAllOf(ctx, &operatorsv1alpha1.Operator{}))
@@ -834,7 +834,7 @@ func TestOperatorVersionNoChannel(t *testing.T) {
834834
require.NotNil(t, cond)
835835
require.Equal(t, metav1.ConditionUnknown, cond.Status)
836836
require.Equal(t, operatorsv1alpha1.ReasonInstallationStatusUnknown, cond.Reason)
837-
require.Equal(t, "installation has not been attempted as resolution failed", cond.Message)
837+
require.Equal(t, "installation has not been attempted due to failure to gather data for resolution", cond.Message)
838838

839839
verifyInvariants(ctx, t, reconciler.Client, operator)
840840
require.NoError(t, cl.DeleteAllOf(ctx, &operatorsv1alpha1.Operator{}))
@@ -882,7 +882,7 @@ func TestOperatorNoChannel(t *testing.T) {
882882
require.NotNil(t, cond)
883883
require.Equal(t, metav1.ConditionUnknown, cond.Status)
884884
require.Equal(t, operatorsv1alpha1.ReasonInstallationStatusUnknown, cond.Reason)
885-
require.Equal(t, "installation has not been attempted as resolution failed", cond.Message)
885+
require.Equal(t, "installation has not been attempted due to failure to gather data for resolution", cond.Message)
886886

887887
verifyInvariants(ctx, t, reconciler.Client, operator)
888888
require.NoError(t, cl.DeleteAllOf(ctx, &operatorsv1alpha1.Operator{}))
@@ -932,7 +932,7 @@ func TestOperatorNoVersion(t *testing.T) {
932932
require.NotNil(t, cond)
933933
require.Equal(t, metav1.ConditionUnknown, cond.Status)
934934
require.Equal(t, operatorsv1alpha1.ReasonInstallationStatusUnknown, cond.Reason)
935-
require.Equal(t, "installation has not been attempted as resolution failed", cond.Message)
935+
require.Equal(t, "installation has not been attempted due to failure to gather data for resolution", cond.Message)
936936

937937
verifyInvariants(ctx, t, reconciler.Client, operator)
938938
require.NoError(t, cl.DeleteAllOf(ctx, &operatorsv1alpha1.Operator{}))

internal/controllers/suite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ func newClientAndReconciler(t *testing.T) (client.Client, *controllers.OperatorR
4848
cl := newClient(t)
4949
fakeCatalogClient := testutil.NewFakeCatalogClient(testBundleList)
5050
reconciler := &controllers.OperatorReconciler{
51-
Client: cl,
52-
Scheme: sch,
53-
Resolver: solver.NewDeppySolver(controllers.NewVariableSource(cl, &fakeCatalogClient)),
51+
Client: cl,
52+
BundleProvider: &fakeCatalogClient,
53+
Scheme: sch,
54+
Resolver: solver.NewDeppySolver(),
5455
}
5556
return cl, reconciler
5657
}

internal/controllers/variable_source.go renamed to internal/controllers/variables.go

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20-
"context"
21-
22-
"sigs.k8s.io/controller-runtime/pkg/client"
23-
2420
"github.com/operator-framework/deppy/pkg/deppy"
2521
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
2622

@@ -29,46 +25,13 @@ import (
2925
"github.com/operator-framework/operator-controller/internal/resolution/variablesources"
3026
)
3127

32-
// BundleProvider provides the way to retrieve a list of Bundles from a source,
33-
// generally from a catalog client of some kind.
34-
type BundleProvider interface {
35-
Bundles(ctx context.Context) ([]*catalogmetadata.Bundle, error)
36-
}
37-
38-
type VariableSource struct {
39-
client client.Client
40-
catalogClient BundleProvider
41-
}
42-
43-
func NewVariableSource(cl client.Client, catalogClient BundleProvider) *VariableSource {
44-
return &VariableSource{
45-
client: cl,
46-
catalogClient: catalogClient,
47-
}
48-
}
49-
50-
func (v *VariableSource) GetVariables(ctx context.Context) ([]deppy.Variable, error) {
51-
operatorList := operatorsv1alpha1.OperatorList{}
52-
if err := v.client.List(ctx, &operatorList); err != nil {
53-
return nil, err
54-
}
55-
56-
bundleDeploymentList := rukpakv1alpha1.BundleDeploymentList{}
57-
if err := v.client.List(ctx, &bundleDeploymentList); err != nil {
58-
return nil, err
59-
}
60-
61-
allBundles, err := v.catalogClient.Bundles(ctx)
62-
if err != nil {
63-
return nil, err
64-
}
65-
66-
requiredPackages, err := variablesources.MakeRequiredPackageVariables(allBundles, operatorList.Items)
28+
func GenerateVariables(allBundles []*catalogmetadata.Bundle, operators []operatorsv1alpha1.Operator, bundleDeployments []rukpakv1alpha1.BundleDeployment) ([]deppy.Variable, error) {
29+
requiredPackages, err := variablesources.MakeRequiredPackageVariables(allBundles, operators)
6730
if err != nil {
6831
return nil, err
6932
}
7033

71-
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, operatorList.Items, bundleDeploymentList.Items)
34+
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, operators, bundleDeployments)
7235
if err != nil {
7336
return nil, err
7437
}

internal/controllers/variable_source_test.go renamed to internal/controllers/variables_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package controllers_test
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
76
"testing"
@@ -14,7 +13,6 @@ import (
1413
"k8s.io/apimachinery/pkg/util/rand"
1514
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
1615
"k8s.io/utils/pointer"
17-
"sigs.k8s.io/controller-runtime/pkg/client/fake"
1816

1917
"github.com/operator-framework/deppy/pkg/deppy"
2018
"github.com/operator-framework/deppy/pkg/deppy/constraint"
@@ -27,7 +25,6 @@ import (
2725
"github.com/operator-framework/operator-controller/internal/catalogmetadata"
2826
"github.com/operator-framework/operator-controller/internal/controllers"
2927
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables"
30-
testutil "github.com/operator-framework/operator-controller/test/util"
3128
)
3229

3330
func TestVariableSource(t *testing.T) {
@@ -64,7 +61,7 @@ func TestVariableSource(t *testing.T) {
6461

6562
pkgName := "packageA"
6663
opName := fmt.Sprintf("operator-test-%s", rand.String(8))
67-
operator := &operatorsv1alpha1.Operator{
64+
operator := operatorsv1alpha1.Operator{
6865
ObjectMeta: metav1.ObjectMeta{Name: opName},
6966
Spec: operatorsv1alpha1.OperatorSpec{
7067
PackageName: pkgName,
@@ -73,7 +70,7 @@ func TestVariableSource(t *testing.T) {
7370
},
7471
}
7572

76-
bd := &rukpakv1alpha1.BundleDeployment{
73+
bd := rukpakv1alpha1.BundleDeployment{
7774
ObjectMeta: metav1.ObjectMeta{
7875
Name: opName,
7976
OwnerReferences: []metav1.OwnerReference{
@@ -102,12 +99,8 @@ func TestVariableSource(t *testing.T) {
10299
},
103100
},
104101
}
105-
fakeClient := fake.NewClientBuilder().WithScheme(sch).WithObjects(operator, bd).Build()
106-
fakeCatalogClient := testutil.NewFakeCatalogClient(allBundles)
107102

108-
vs := controllers.NewVariableSource(fakeClient, &fakeCatalogClient)
109-
110-
vars, err := vs.GetVariables(context.Background())
103+
vars, err := controllers.GenerateVariables(allBundles, []operatorsv1alpha1.Operator{operator}, []rukpakv1alpha1.BundleDeployment{bd})
111104
require.NoError(t, err)
112105

113106
expectedVars := []deppy.Variable{

0 commit comments

Comments
 (0)