Skip to content

Commit a3acd70

Browse files
committed
Merge branch 'main' into resolver-e2e-test
Signed-off-by: dtfranz <[email protected]>
2 parents a06520c + 931493a commit a3acd70

File tree

11 files changed

+59
-55
lines changed

11 files changed

+59
-55
lines changed

api/v1alpha1/operator_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func init() {
4444
)
4545
// TODO(user): add Reasons from above
4646
operatorutil.ConditionReasons = append(operatorutil.ConditionReasons,
47-
ReasonNotImplemented,
47+
ReasonNotImplemented, ReasonResolutionSucceeded, ReasonResolutionFailed,
4848
)
4949
}
5050

@@ -55,7 +55,6 @@ type OperatorStatus struct {
5555
// +listType=map
5656
// +listMapKey=type
5757
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
58-
BundlePath string `json:"BundlePath,omitempty"`
5958
}
6059

6160
//+kubebuilder:object:root=true

config/crd/bases/operators.operatorframework.io_operators.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ spec:
4545
status:
4646
description: OperatorStatus defines the observed state of Operator
4747
properties:
48-
BundlePath:
49-
type: string
5048
conditions:
5149
items:
5250
description: "Condition contains details for one aspect of the current

config/samples/operators_v1alpha1_operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ metadata:
1010
name: operator-sample
1111
spec:
1212
# TODO(user): Add fields here
13-
packageName: my-operator
13+
packageName: prometheus

controllers/operator_controller.go

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ package controllers
1818

1919
import (
2020
"context"
21-
"strings"
2221

23-
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
24-
"github.com/operator-framework/operator-controller/internal/resolution"
2522
"k8s.io/apimachinery/pkg/api/equality"
2623
apimeta "k8s.io/apimachinery/pkg/api/meta"
2724
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -30,6 +27,10 @@ import (
3027
ctrl "sigs.k8s.io/controller-runtime"
3128
"sigs.k8s.io/controller-runtime/pkg/client"
3229
"sigs.k8s.io/controller-runtime/pkg/log"
30+
31+
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
32+
"github.com/operator-framework/operator-controller/internal/resolution"
33+
"github.com/operator-framework/operator-controller/internal/resolution/variable_sources/bundles_and_dependencies"
3334
)
3435

3536
// OperatorReconciler reconciles a Operator object
@@ -99,47 +100,47 @@ func checkForUnexpectedFieldChange(a, b operatorsv1alpha1.Operator) bool {
99100

100101
// Helper function to do the actual reconcile
101102
func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha1.Operator) (ctrl.Result, error) {
103+
// define condition parameters
104+
var status = metav1.ConditionTrue
105+
var reason = operatorsv1alpha1.ReasonResolutionSucceeded
106+
var message = "resolution was successful"
102107

103-
// todo(perdasilva): this is a _hack_ we probably want to find a better way to ride or die resolve and update
108+
// run resolution
104109
solution, err := r.resolver.Resolve(ctx)
105-
status := metav1.ConditionTrue
106-
reason := operatorsv1alpha1.ReasonResolutionSucceeded
107-
message := "resolution was successful"
108110
if err != nil {
109111
status = metav1.ConditionTrue
110112
reason = operatorsv1alpha1.ReasonResolutionFailed
111113
message = err.Error()
112-
}
113-
114-
// todo(perdasilva): more hacks - need to fix up the solution structure to be more useful
115-
packageVariableIDMap := map[string]string{}
116-
for variableID, ok := range solution {
117-
if ok {
118-
idComponents := strings.Split(string(variableID), "/")
119-
packageVariableIDMap[idComponents[1]] = string(variableID)
114+
} else {
115+
// extract package bundle path from resolved variable
116+
for _, variable := range solution.SelectedVariables() {
117+
switch v := variable.(type) {
118+
case *bundles_and_dependencies.BundleVariable:
119+
packageName, err := v.BundleEntity().PackageName()
120+
if err != nil {
121+
return ctrl.Result{}, err
122+
}
123+
if packageName == op.Spec.PackageName {
124+
bundlePath, err := v.BundleEntity().BundlePath()
125+
if err != nil {
126+
return ctrl.Result{}, err
127+
}
128+
// TODO(perdasilva): use bundlePath to stamp out bundle deployment
129+
_ = bundlePath
130+
break
131+
}
132+
}
120133
}
121134
}
122135

123-
operatorList := &operatorsv1alpha1.OperatorList{}
124-
if err := r.Client.List(ctx, operatorList); err != nil {
125-
return ctrl.Result{}, err
126-
}
127-
128-
for _, operator := range operatorList.Items {
129-
apimeta.SetStatusCondition(&operator.Status.Conditions, metav1.Condition{
130-
Type: operatorsv1alpha1.TypeReady,
131-
Status: status,
132-
Reason: reason,
133-
Message: message,
134-
ObservedGeneration: op.GetGeneration(),
135-
})
136-
if varID, ok := packageVariableIDMap[operator.Spec.PackageName]; ok {
137-
operator.Status.BundlePath = varID
138-
}
139-
if err := r.Client.Status().Update(ctx, &operator); err != nil {
140-
return ctrl.Result{}, err
141-
}
142-
}
136+
// update operator status
137+
apimeta.SetStatusCondition(&op.Status.Conditions, metav1.Condition{
138+
Type: operatorsv1alpha1.TypeReady,
139+
Status: status,
140+
Reason: reason,
141+
Message: message,
142+
ObservedGeneration: op.GetGeneration(),
143+
})
143144

144145
return ctrl.Result{}, nil
145146
}

controllers/suite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ import (
2525

2626
. "github.com/onsi/ginkgo/v2"
2727
. "github.com/onsi/gomega"
28-
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
29-
"github.com/operator-framework/operator-controller/controllers"
30-
operatorutil "github.com/operator-framework/operator-controller/internal/util"
3128
apimeta "k8s.io/apimachinery/pkg/api/meta"
3229
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3330
"k8s.io/apimachinery/pkg/util/rand"
@@ -38,6 +35,10 @@ import (
3835
"sigs.k8s.io/controller-runtime/pkg/envtest"
3936
logf "sigs.k8s.io/controller-runtime/pkg/log"
4037
"sigs.k8s.io/controller-runtime/pkg/log/zap"
38+
39+
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
40+
"github.com/operator-framework/operator-controller/controllers"
41+
operatorutil "github.com/operator-framework/operator-controller/internal/util"
4142
//+kubebuilder:scaffold:imports
4243
)
4344

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/blang/semver/v4 v4.0.0
77
github.com/onsi/ginkgo/v2 v2.3.1
88
github.com/onsi/gomega v1.22.1
9-
github.com/operator-framework/deppy v0.0.0-20230102161649-36fa82370999
9+
github.com/operator-framework/deppy v0.0.0-20230125110717-dc02e928470f
1010
github.com/operator-framework/operator-registry v1.26.2
1111
k8s.io/apimachinery v0.25.0
1212
k8s.io/client-go v0.25.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ github.com/onsi/ginkgo/v2 v2.3.1 h1:8SbseP7qM32WcvE6VaN6vfXxv698izmsJ1UQX9ve7T8=
287287
github.com/onsi/ginkgo/v2 v2.3.1/go.mod h1:Sv4yQXwG5VmF7tm3Q5Z+RWUpPo24LF1mpnz2crUb8Ys=
288288
github.com/onsi/gomega v1.22.1 h1:pY8O4lBfsHKZHM/6nrxkhVPUznOlIu3quZcKP/M20KI=
289289
github.com/onsi/gomega v1.22.1/go.mod h1:x6n7VNe4hw0vkyYUM4mjIXx3JbLiPaBPNgB7PRQ1tuM=
290-
github.com/operator-framework/deppy v0.0.0-20230102161649-36fa82370999 h1:3R+Bg57vgekyDqS0w9c7vHNsHck/bo6dkaby6U9wi/8=
291-
github.com/operator-framework/deppy v0.0.0-20230102161649-36fa82370999/go.mod h1:JaF7sX6tn7mpXcOehYjSHiKM1Y0z09vEfC6dca4AVuo=
290+
github.com/operator-framework/deppy v0.0.0-20230125110717-dc02e928470f h1:YxUZyQjF2kT2hli9ceBkuK7Mmiln0lV2RV38rzBObBI=
291+
github.com/operator-framework/deppy v0.0.0-20230125110717-dc02e928470f/go.mod h1:JaF7sX6tn7mpXcOehYjSHiKM1Y0z09vEfC6dca4AVuo=
292292
github.com/operator-framework/operator-registry v1.26.2 h1:kQToR/hPqdivljaRXM0olPllNIcc/GUk1VBoGwagJmk=
293293
github.com/operator-framework/operator-registry v1.26.2/go.mod h1:Z7XIb/3ZkhBQCvMD/rJphyuY4LmU/eWpZS+o0Mm1WAk=
294294
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=

internal/resolution/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func NewOperatorResolver(client client.Client, entitySource input.EntitySource)
2424
}
2525
}
2626

27-
func (o *OperatorResolver) Resolve(ctx context.Context) (solver.Solution, error) {
27+
func (o *OperatorResolver) Resolve(ctx context.Context) (*solver.Solution, error) {
2828
packageNames, err := o.getPackageNames(ctx)
2929
if err != nil {
3030
return nil, fmt.Errorf("failed to get package names for resolution: %w", err)

internal/resolution/resolver_test.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,26 @@ var _ = Describe("OperatorResolver", func() {
7777
resolver := resolution.NewOperatorResolver(client, entitySource)
7878
solution, err := resolver.Resolve(context.Background())
7979
Expect(err).ToNot(HaveOccurred())
80-
Expect(solution).To(HaveLen(3))
81-
Expect(solution["operatorhub/packageA/2.0.0"]).To(BeTrue())
82-
Expect(solution["operatorhub/prometheus/0.47.0"]).To(BeTrue())
83-
Expect(solution["operatorhub/prometheus/0.37.0"]).To(BeFalse())
80+
// 2 * required package variables + 2 * bundle variables
81+
Expect(solution.SelectedVariables()).To(HaveLen(4))
82+
83+
Expect(solution.IsSelected("operatorhub/packageA/2.0.0")).To(BeTrue())
84+
Expect(solution.IsSelected("operatorhub/prometheus/0.47.0")).To(BeTrue())
85+
Expect(solution.IsSelected("required package packageA")).To(BeTrue())
86+
Expect(solution.IsSelected("required package prometheus")).To(BeTrue())
87+
88+
Expect(solution.IsSelected("operatorhub/prometheus/0.37.0")).To(BeFalse())
89+
8490
})
8591

86-
It("should not return an error if there are not Operator resources", func() {
92+
It("should not return an error if there are no Operator resources", func() {
8793
var resources []client.Object
8894
client := FakeClient(resources...)
8995
entitySource := input.NewCacheQuerier(testEntityCache)
9096
resolver := resolution.NewOperatorResolver(client, entitySource)
9197
solution, err := resolver.Resolve(context.Background())
9298
Expect(err).ToNot(HaveOccurred())
93-
Expect(solution).To(HaveLen(0))
99+
Expect(solution.SelectedVariables()).To(HaveLen(0))
94100
})
95101

96102
It("should return an error if the entity source throws an error", func() {

internal/resolution/variable_sources/utils/predicates/predicates_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ var _ = Describe("Predicates", func() {
4242
})
4343

4444
Describe("InChannel", func() {
45-
It("should return true when the entity has the has version in the right range", func() {
45+
It("should return true when the entity comes from the specified channel", func() {
4646
entity := input.NewEntity("test", map[string]string{
4747
property.TypeChannel: `{"channelName":"stable","priority":0}`,
4848
})

test/e2e/install_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ var _ = Describe("Operator Install", func() {
4444
Eventually(func(g Gomega) {
4545
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
4646
g.Expect(err).ToNot(HaveOccurred())
47-
g.Expect(operator.Status.BundlePath).To(Equal("operatorhub/prometheus/0.47.0"))
4847
g.Expect(len(operator.Status.Conditions)).To(Equal(1))
4948
g.Expect(operator.Status.Conditions[0].Message).To(Equal("resolution was successful"))
5049
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())

0 commit comments

Comments
 (0)