Skip to content

Commit c2e96f3

Browse files
committed
add bundle path to operator resource status
Signed-off-by: perdasilva <[email protected]>
1 parent 98e9d2c commit c2e96f3

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

api/v1alpha1/operator_types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ const (
3232
// TODO(user): add more Types, here and into init()
3333
TypeReady = "Ready"
3434

35-
// TODO(user): add more Reasons, here and into init()
36-
ReasonNotImplemented = "NotImplemented"
35+
ReasonNotImplemented = "NotImplemented"
36+
ReasonResolutionFailed = "ResolutionFailed"
37+
ReasonResolutionSucceeded = "ResolutionSucceeded"
3738
)
3839

3940
func init() {
@@ -54,6 +55,7 @@ type OperatorStatus struct {
5455
// +listType=map
5556
// +listMapKey=type
5657
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
58+
BundlePath string `json:"BundlePath,omitempty"`
5759
}
5860

5961
//+kubebuilder:object:root=true

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

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

controllers/operator_controller.go

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

1919
import (
2020
"context"
21+
"strings"
2122

23+
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
24+
"github.com/operator-framework/operator-controller/internal/resolution"
2225
"k8s.io/apimachinery/pkg/api/equality"
2326
apimeta "k8s.io/apimachinery/pkg/api/meta"
2427
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -27,14 +30,14 @@ import (
2730
ctrl "sigs.k8s.io/controller-runtime"
2831
"sigs.k8s.io/controller-runtime/pkg/client"
2932
"sigs.k8s.io/controller-runtime/pkg/log"
30-
31-
operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
3233
)
3334

3435
// OperatorReconciler reconciles a Operator object
3536
type OperatorReconciler struct {
3637
client.Client
3738
Scheme *runtime.Scheme
39+
40+
resolver *resolution.OperatorResolver
3841
}
3942

4043
//+kubebuilder:rbac:groups=operators.operatorframework.io,resources=operators,verbs=get;list;watch;create;update;patch;delete
@@ -97,24 +100,62 @@ func checkForUnexpectedFieldChange(a, b operatorsv1alpha1.Operator) bool {
97100
// Helper function to do the actual reconcile
98101
func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha1.Operator) (ctrl.Result, error) {
99102

100-
// TODO(user): change ReasonNotImplemented when functionality added
101-
readyCondition := metav1.Condition{
102-
Type: operatorsv1alpha1.TypeReady,
103-
Status: metav1.ConditionFalse,
104-
Reason: operatorsv1alpha1.ReasonNotImplemented,
105-
Message: "The Reconcile operation is not implemented",
106-
ObservedGeneration: op.GetGeneration(),
103+
// todo(perdasilva): this is a _hack_ we probably want to find a better way to ride or die resolve and update
104+
solution, err := r.resolver.Resolve(ctx)
105+
status := metav1.ConditionTrue
106+
reason := operatorsv1alpha1.ReasonResolutionSucceeded
107+
message := "resolution was successful"
108+
if err != nil {
109+
status = metav1.ConditionTrue
110+
reason = operatorsv1alpha1.ReasonResolutionFailed
111+
message = err.Error()
107112
}
108-
apimeta.SetStatusCondition(&op.Status.Conditions, readyCondition)
109113

110-
// TODO(user): your logic here
114+
// todo(perdasilva): more hacks - need to fix up the solution structure to be more useful
115+
packageVariableIDMap := map[string]string{}
116+
if solution != nil {
117+
for variableID, ok := range solution {
118+
if ok {
119+
idComponents := strings.Split(string(variableID), "/")
120+
packageVariableIDMap[idComponents[1]] = string(variableID)
121+
}
122+
}
123+
}
124+
125+
operatorList := &operatorsv1alpha1.OperatorList{}
126+
if err := r.Client.List(ctx, operatorList); err != nil {
127+
return ctrl.Result{}, err
128+
}
129+
130+
for _, operator := range operatorList.Items {
131+
apimeta.SetStatusCondition(&operator.Status.Conditions, metav1.Condition{
132+
Type: operatorsv1alpha1.TypeReady,
133+
Status: status,
134+
Reason: reason,
135+
Message: message,
136+
ObservedGeneration: op.GetGeneration(),
137+
})
138+
if varID, ok := packageVariableIDMap[operator.Spec.PackageName]; ok {
139+
operator.Status.BundlePath = varID
140+
}
141+
if err := r.Client.Status().Update(ctx, &operator); err != nil {
142+
return ctrl.Result{}, err
143+
}
144+
}
111145

112146
return ctrl.Result{}, nil
113147
}
114148

115149
// SetupWithManager sets up the controller with the Manager.
116150
func (r *OperatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
117-
return ctrl.NewControllerManagedBy(mgr).
151+
r.resolver = resolution.NewOperatorResolver(mgr.GetClient(), resolution.HardcodedEntitySource)
152+
153+
err := ctrl.NewControllerManagedBy(mgr).
118154
For(&operatorsv1alpha1.Operator{}).
119155
Complete(r)
156+
157+
if err != nil {
158+
return err
159+
}
160+
return nil
120161
}

0 commit comments

Comments
 (0)