@@ -18,7 +18,10 @@ package controllers
18
18
19
19
import (
20
20
"context"
21
+ "strings"
21
22
23
+ operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
24
+ "github.com/operator-framework/operator-controller/internal/resolution"
22
25
"k8s.io/apimachinery/pkg/api/equality"
23
26
apimeta "k8s.io/apimachinery/pkg/api/meta"
24
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -27,14 +30,14 @@ import (
27
30
ctrl "sigs.k8s.io/controller-runtime"
28
31
"sigs.k8s.io/controller-runtime/pkg/client"
29
32
"sigs.k8s.io/controller-runtime/pkg/log"
30
-
31
- operatorsv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
32
33
)
33
34
34
35
// OperatorReconciler reconciles a Operator object
35
36
type OperatorReconciler struct {
36
37
client.Client
37
38
Scheme * runtime.Scheme
39
+
40
+ resolver * resolution.OperatorResolver
38
41
}
39
42
40
43
//+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 {
97
100
// Helper function to do the actual reconcile
98
101
func (r * OperatorReconciler ) reconcile (ctx context.Context , op * operatorsv1alpha1.Operator ) (ctrl.Result , error ) {
99
102
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 ()
107
112
}
108
- apimeta .SetStatusCondition (& op .Status .Conditions , readyCondition )
109
113
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
+ }
111
145
112
146
return ctrl.Result {}, nil
113
147
}
114
148
115
149
// SetupWithManager sets up the controller with the Manager.
116
150
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 ).
118
154
For (& operatorsv1alpha1.Operator {}).
119
155
Complete (r )
156
+
157
+ if err != nil {
158
+ return err
159
+ }
160
+ return nil
120
161
}
0 commit comments