@@ -18,7 +18,10 @@ package controllers
1818
1919import (
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
3536type 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
98101func (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.
116150func (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