@@ -113,6 +113,16 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
113113 Message : err .Error (),
114114 ObservedGeneration : op .GetGeneration (),
115115 })
116+ // Set the TypeInstalled condition to Unknown to indicate that the resolution
117+ // hasn't been attempted yet, due to the spec being invalid.
118+ op .Status .InstalledBundleSource = ""
119+ apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
120+ Type : operatorsv1alpha1 .TypeInstalled ,
121+ Status : metav1 .ConditionUnknown ,
122+ Reason : operatorsv1alpha1 .ReasonInstallationStatusUnknown ,
123+ Message : "installation has not been attempted as spec is invalid" ,
124+ ObservedGeneration : op .GetGeneration (),
125+ })
116126 // Set the TypeResolved condition to Unknown to indicate that the resolution
117127 // hasn't been attempted yet, due to the spec being invalid.
118128 op .Status .ResolvedBundleResource = ""
@@ -135,6 +145,14 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
135145 Message : err .Error (),
136146 ObservedGeneration : op .GetGeneration (),
137147 })
148+ op .Status .InstalledBundleSource = ""
149+ apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
150+ Type : operatorsv1alpha1 .TypeInstalled ,
151+ Status : metav1 .ConditionUnknown ,
152+ Reason : operatorsv1alpha1 .ReasonInstallationStatusUnknown ,
153+ Message : "installation has not been attempted as resolution failed" ,
154+ ObservedGeneration : op .GetGeneration (),
155+ })
138156 op .Status .ResolvedBundleResource = ""
139157 apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
140158 Type : operatorsv1alpha1 .TypeResolved ,
@@ -157,6 +175,14 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
157175 Message : err .Error (),
158176 ObservedGeneration : op .GetGeneration (),
159177 })
178+ op .Status .InstalledBundleSource = ""
179+ apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
180+ Type : operatorsv1alpha1 .TypeInstalled ,
181+ Status : metav1 .ConditionUnknown ,
182+ Reason : operatorsv1alpha1 .ReasonInstallationStatusUnknown ,
183+ Message : "installation has not been attempted as resolution failed" ,
184+ ObservedGeneration : op .GetGeneration (),
185+ })
160186 op .Status .ResolvedBundleResource = ""
161187 apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
162188 Type : operatorsv1alpha1 .TypeResolved ,
@@ -178,6 +204,14 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
178204 Message : err .Error (),
179205 ObservedGeneration : op .GetGeneration (),
180206 })
207+ op .Status .InstalledBundleSource = ""
208+ apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
209+ Type : operatorsv1alpha1 .TypeInstalled ,
210+ Status : metav1 .ConditionUnknown ,
211+ Reason : operatorsv1alpha1 .ReasonInstallationStatusUnknown ,
212+ Message : "installation has not been attempted as resolution failed" ,
213+ ObservedGeneration : op .GetGeneration (),
214+ })
181215 op .Status .ResolvedBundleResource = ""
182216 apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
183217 Type : operatorsv1alpha1 .TypeResolved ,
@@ -210,6 +244,14 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
210244 Message : err .Error (),
211245 ObservedGeneration : op .GetGeneration (),
212246 })
247+ op .Status .InstalledBundleSource = ""
248+ apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
249+ Type : operatorsv1alpha1 .TypeInstalled ,
250+ Status : metav1 .ConditionFalse ,
251+ Reason : operatorsv1alpha1 .ReasonInstallationFailed ,
252+ Message : err .Error (),
253+ ObservedGeneration : op .GetGeneration (),
254+ })
213255 return ctrl.Result {}, err
214256 }
215257
@@ -223,14 +265,79 @@ func (r *OperatorReconciler) reconcile(ctx context.Context, op *operatorsv1alpha
223265 Message : err .Error (),
224266 ObservedGeneration : op .GetGeneration (),
225267 })
268+ op .Status .InstalledBundleSource = ""
269+ apimeta .SetStatusCondition (& op .Status .Conditions , metav1.Condition {
270+ Type : operatorsv1alpha1 .TypeInstalled ,
271+ Status : metav1 .ConditionUnknown ,
272+ Reason : operatorsv1alpha1 .ReasonInstallationStatusUnknown ,
273+ Message : err .Error (),
274+ ObservedGeneration : op .GetGeneration (),
275+ })
226276 return ctrl.Result {}, err
227277 }
228278
279+ // Let's set the proper Installed condition and installedBundleSource field based on the
280+ // existing BundleDeployment object status.
281+ installedCond , installedBundleSource := mapBDStatusToInstalledCondition (existingTypedBundleDeployment , op )
282+ apimeta .SetStatusCondition (& op .Status .Conditions , installedCond )
283+ op .Status .InstalledBundleSource = installedBundleSource
284+
229285 // set the status of the operator based on the respective bundle deployment status conditions.
230286 apimeta .SetStatusCondition (& op .Status .Conditions , mapBDStatusToReadyCondition (existingTypedBundleDeployment , op .GetGeneration ()))
231287 return ctrl.Result {}, nil
232288}
233289
290+ func mapBDStatusToInstalledCondition (existingTypedBundleDeployment * rukpakv1alpha1.BundleDeployment , op * operatorsv1alpha1.Operator ) (metav1.Condition , string ) {
291+ bundleDeploymentReady := apimeta .FindStatusCondition (existingTypedBundleDeployment .Status .Conditions , rukpakv1alpha1 .TypeInstalled )
292+ if bundleDeploymentReady == nil {
293+ return metav1.Condition {
294+ Type : operatorsv1alpha1 .TypeInstalled ,
295+ Status : metav1 .ConditionUnknown ,
296+ Reason : operatorsv1alpha1 .ReasonInstallationStatusUnknown ,
297+ Message : "bundledeployment status is unknown" ,
298+ ObservedGeneration : op .GetGeneration (),
299+ }, ""
300+ }
301+
302+ if bundleDeploymentReady .Status != metav1 .ConditionTrue {
303+ return metav1.Condition {
304+ Type : operatorsv1alpha1 .TypeInstalled ,
305+ Status : metav1 .ConditionFalse ,
306+ Reason : operatorsv1alpha1 .ReasonInstallationFailed ,
307+ Message : fmt .Sprintf ("bundledeployment not ready: %s" , bundleDeploymentReady .Message ),
308+ ObservedGeneration : op .GetGeneration (),
309+ }, ""
310+ }
311+
312+ bundleDeploymentSource := existingTypedBundleDeployment .Spec .Template .Spec .Source
313+ switch bundleDeploymentSource .Type {
314+ case rukpakv1alpha1 .SourceTypeImage :
315+ return metav1.Condition {
316+ Type : operatorsv1alpha1 .TypeInstalled ,
317+ Status : metav1 .ConditionTrue ,
318+ Reason : operatorsv1alpha1 .ReasonSuccess ,
319+ Message : fmt .Sprintf ("installed from %q" , bundleDeploymentSource .Image .Ref ),
320+ ObservedGeneration : op .GetGeneration (),
321+ }, bundleDeploymentSource .Image .Ref
322+ case rukpakv1alpha1 .SourceTypeGit :
323+ return metav1.Condition {
324+ Type : operatorsv1alpha1 .TypeInstalled ,
325+ Status : metav1 .ConditionTrue ,
326+ Reason : operatorsv1alpha1 .ReasonSuccess ,
327+ Message : fmt .Sprintf ("installed from %q" , bundleDeploymentSource .Git .Repository + "@" + bundleDeploymentSource .Git .Ref .Commit ),
328+ ObservedGeneration : op .GetGeneration (),
329+ }, bundleDeploymentSource .Git .Repository + "@" + bundleDeploymentSource .Git .Ref .Commit
330+ default :
331+ return metav1.Condition {
332+ Type : operatorsv1alpha1 .TypeInstalled ,
333+ Status : metav1 .ConditionUnknown ,
334+ Reason : operatorsv1alpha1 .ReasonInstallationStatusUnknown ,
335+ Message : fmt .Sprintf ("unknown bundledeployment source type %q" , bundleDeploymentSource .Type ),
336+ ObservedGeneration : op .GetGeneration (),
337+ }, ""
338+ }
339+ }
340+
234341func (r * OperatorReconciler ) getBundleEntityFromSolution (solution * solver.Solution , packageName string ) (* entity.BundleEntity , error ) {
235342 for _ , variable := range solution .SelectedVariables () {
236343 switch v := variable .(type ) {
0 commit comments