@@ -84,7 +84,7 @@ type Applier interface {
8484}
8585
8686type InstalledBundleGetter interface {
87- GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1.BundleMetadata , error )
87+ GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1.BundleMetadata , release. Status , error )
8888}
8989
9090//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clusterextensions,verbs=get;list;watch;update;patch
@@ -203,21 +203,34 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
203203 }
204204
205205 l .Info ("getting installed bundle" )
206- installedBundle , err := r .InstalledBundleGetter .GetInstalledBundle (ctx , ext )
206+ // second return is status of the highest semver, if we need it
207+ installedBundle , _ , err := r .InstalledBundleGetter .GetInstalledBundle (ctx , ext )
207208 if err != nil {
208209 setInstallStatus (ext , nil )
209- // TODO: use Installed=Unknown
210- setInstalledStatusConditionFailed (ext , err .Error ())
210+ setInstalledStatusConditionUnknown (ext , err .Error ())
211211 setStatusProgressing (ext , err )
212212 return ctrl.Result {}, err
213213 }
214214
215+ // Update current install status conditions before we start trying to install something new
216+ if installedBundle != nil {
217+ installStatus := & ocv1alpha1.ClusterExtensionInstallStatus {
218+ Bundle : * installedBundle ,
219+ }
220+ setInstallStatus (ext , installStatus )
221+ if ! apimeta .IsStatusConditionTrue (ext .Status .Conditions , ocv1alpha1 .TypeInstalled ) {
222+ setInstalledStatusConditionSuccess (ext , "Installed extension successfully" )
223+ }
224+ } else {
225+ setInstallStatus (ext , nil )
226+ apimeta .RemoveStatusCondition (& ext .Status .Conditions , ocv1alpha1 .TypeInstalled )
227+ }
228+
215229 // run resolution
216230 l .Info ("resolving bundle" )
217231 resolvedBundle , resolvedBundleVersion , resolvedDeprecation , err := r .Resolver .Resolve (ctx , ext , installedBundle )
218232 if err != nil {
219233 // Note: We don't distinguish between resolution-specific errors and generic errors
220- setInstallStatus (ext , nil )
221234 setStatusProgressing (ext , err )
222235 ensureAllConditionsWithReason (ext , ocv1alpha1 .ReasonFailed , err .Error ())
223236 return ctrl.Result {}, err
@@ -466,32 +479,36 @@ type DefaultInstalledBundleGetter struct {
466479 helmclient.ActionClientGetter
467480}
468481
469- func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1.BundleMetadata , error ) {
482+ func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1.BundleMetadata , release.Status , error ) {
483+ status := release .StatusUnknown
470484 cl , err := d .ActionClientFor (ctx , ext )
471485 if err != nil {
472- return nil , err
486+ return nil , status , err
473487 }
474488
475- rel , err := cl .Get (ext .GetName ())
489+ relhis , err := cl .History (ext .GetName ())
476490 if err != nil && ! errors .Is (err , driver .ErrReleaseNotFound ) {
477- return nil , err
491+ return nil , status , err
492+ }
493+ if relhis == nil || len (relhis ) == 0 {
494+ return nil , status , nil
478495 }
479- if rel == nil {
480- return nil , nil
496+ var found * release.Release
497+
498+ status = relhis [0 ].Info .Status
499+ for _ , rel := range relhis {
500+ if rel .Info .Status == release .StatusDeployed {
501+ found = rel
502+ break
503+ }
481504 }
482505
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 )
506+ if found == nil {
507+ return nil , status , nil
491508 }
492509
493510 return & ocv1alpha1.BundleMetadata {
494- Name : rel .Labels [labels .BundleNameKey ],
495- Version : rel .Labels [labels .BundleVersionKey ],
496- }, nil
511+ Name : found .Labels [labels .BundleNameKey ],
512+ Version : found .Labels [labels .BundleVersionKey ],
513+ }, status , nil
497514}
0 commit comments