@@ -206,8 +206,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
206206 installedBundle , err := r .InstalledBundleGetter .GetInstalledBundle (ctx , ext )
207207 if err != nil {
208208 setInstallStatus (ext , nil )
209- // TODO: use Installed=Unknown
210- setInstalledStatusConditionFailed (ext , err .Error ())
209+ setInstalledStatusConditionUnknown (ext , err .Error ())
211210 setStatusProgressing (ext , err )
212211 return ctrl.Result {}, err
213212 }
@@ -217,7 +216,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
217216 resolvedBundle , resolvedBundleVersion , resolvedDeprecation , err := r .Resolver .Resolve (ctx , ext , installedBundle )
218217 if err != nil {
219218 // Note: We don't distinguish between resolution-specific errors and generic errors
220- setInstallStatus (ext , nil )
219+ setInstalledStatusFromBundle (ext , installedBundle , err )
221220 setStatusProgressing (ext , err )
222221 ensureAllConditionsWithReason (ext , ocv1alpha1 .ReasonFailed , err .Error ())
223222 return ctrl.Result {}, err
@@ -254,6 +253,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
254253 // Wrap the error passed to this with the resolution information until we have successfully
255254 // installed since we intend for the progressing condition to replace the resolved condition
256255 // and will be removing the .status.resolution field from the ClusterExtension status API
256+ setInstalledStatusFromBundle (ext , installedBundle , err )
257257 setStatusProgressing (ext , wrapErrorWithResolutionInfo (resolvedBundleMetadata , err ))
258258 return ctrl.Result {}, err
259259 }
@@ -286,10 +286,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
286286 managedObjs , _ , err := r .Applier .Apply (ctx , unpackResult .Bundle , ext , objLbls , storeLbls )
287287 if err != nil {
288288 setStatusProgressing (ext , wrapErrorWithResolutionInfo (resolvedBundleMetadata , err ))
289- // If bundle is not already installed, set Installed status condition to False
290- if installedBundle == nil {
291- setInstalledStatusConditionFailed (ext , err .Error ())
292- }
289+ setInstalledStatusFromBundle (ext , installedBundle , err )
293290 return ctrl.Result {}, err
294291 }
295292
@@ -472,26 +469,31 @@ func (d *DefaultInstalledBundleGetter) GetInstalledBundle(ctx context.Context, e
472469 return nil , err
473470 }
474471
475- rel , err := cl .Get (ext .GetName ())
472+ relhis , err := cl .History (ext .GetName ())
476473 if err != nil && ! errors .Is (err , driver .ErrReleaseNotFound ) {
477474 return nil , err
478475 }
479- if rel == nil {
476+ if relhis == nil || len ( relhis ) == 0 {
480477 return nil , nil
481478 }
479+ var found * release.Release
480+
481+ // TODO: relhis[0].Info.Status is the status of the highest semver install attempt.
482+ // This might be useful informaton if it's not release.StatusDeployed, in telling us
483+ // the status of an upgrade attempt.
484+ for _ , rel := range relhis {
485+ if rel .Info != nil && rel .Info .Status == release .StatusDeployed {
486+ found = rel
487+ break
488+ }
489+ }
482490
483- switch rel .Info .Status {
484- case release .StatusUnknown :
485- return nil , fmt .Errorf ("installation status is unknown" )
486- case release .StatusDeployed , release .StatusUninstalled , release .StatusSuperseded , release .StatusFailed :
487- case release .StatusUninstalling , release .StatusPendingInstall , release .StatusPendingRollback , release .StatusPendingUpgrade :
488- return nil , fmt .Errorf ("installation is still pending: %s" , rel .Info .Status )
489- default :
490- return nil , fmt .Errorf ("unknown installation status: %s" , rel .Info .Status )
491+ if found == nil {
492+ return nil , nil
491493 }
492494
493495 return & ocv1alpha1.BundleMetadata {
494- Name : rel .Labels [labels .BundleNameKey ],
495- Version : rel .Labels [labels .BundleVersionKey ],
496+ Name : found .Labels [labels .BundleNameKey ],
497+ Version : found .Labels [labels .BundleVersionKey ],
496498 }, nil
497499}
0 commit comments