@@ -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 ) (* InstalledBundle , error )
8888}
8989
9090//+kubebuilder:rbac:groups=olm.operatorframework.io,resources=clusterextensions,verbs=get;list;watch;update;patch
@@ -206,19 +206,24 @@ 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+ // The error is put into Progressing
210+ setInstalledStatusConditionUnknown (ext , "retrying get installed bundle" )
211211 setStatusProgressing (ext , err )
212212 return ctrl.Result {}, err
213213 }
214214
215215 // run resolution
216216 l .Info ("resolving bundle" )
217- resolvedBundle , resolvedBundleVersion , resolvedDeprecation , err := r .Resolver .Resolve (ctx , ext , installedBundle )
217+ var bm * ocv1alpha1.BundleMetadata
218+ if installedBundle != nil {
219+ bm = & installedBundle .BundleMetadata
220+ }
221+ resolvedBundle , resolvedBundleVersion , resolvedDeprecation , err := r .Resolver .Resolve (ctx , ext , bm )
218222 if err != nil {
219223 // Note: We don't distinguish between resolution-specific errors and generic errors
220- setInstallStatus (ext , nil )
221224 setStatusProgressing (ext , err )
225+ // The error is put into Progressing
226+ setInstalledStatusFromBundle (ext , installedBundle , nil )
222227 ensureAllConditionsWithReason (ext , ocv1alpha1 .ReasonFailed , err .Error ())
223228 return ctrl.Result {}, err
224229 }
@@ -255,6 +260,8 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
255260 // installed since we intend for the progressing condition to replace the resolved condition
256261 // and will be removing the .status.resolution field from the ClusterExtension status API
257262 setStatusProgressing (ext , wrapErrorWithResolutionInfo (resolvedBundleMetadata , err ))
263+ // The error is put into Progressing
264+ setInstalledStatusFromBundle (ext , installedBundle , nil )
258265 return ctrl.Result {}, err
259266 }
260267
@@ -268,9 +275,10 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
268275 }
269276
270277 storeLbls := map [string ]string {
271- labels .BundleNameKey : resolvedBundle .Name ,
272- labels .PackageNameKey : resolvedBundle .Package ,
273- labels .BundleVersionKey : resolvedBundleVersion .String (),
278+ labels .BundleNameKey : resolvedBundle .Name ,
279+ labels .PackageNameKey : resolvedBundle .Package ,
280+ labels .BundleVersionKey : resolvedBundleVersion .String (),
281+ labels .BundleReferenceKey : resolvedBundle .Image ,
274282 }
275283
276284 l .Info ("applying bundle contents" )
@@ -286,18 +294,16 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
286294 managedObjs , _ , err := r .Applier .Apply (ctx , unpackResult .Bundle , ext , objLbls , storeLbls )
287295 if err != nil {
288296 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- }
297+ // Now that we're actually trying to install, use the error
298+ setInstalledStatusFromBundle (ext , installedBundle , err )
293299 return ctrl.Result {}, err
294300 }
295301
296- installStatus := & ocv1alpha1.ClusterExtensionInstallStatus {
297- Bundle : resolvedBundleMetadata ,
302+ installedBundle = & InstalledBundle {
303+ BundleMetadata : resolvedBundleMetadata ,
304+ Image : resolvedBundle .Image ,
298305 }
299- setInstallStatus (ext , installStatus )
300- setInstalledStatusConditionSuccess (ext , fmt .Sprintf ("Installed bundle %s successfully" , resolvedBundle .Image ))
306+ setInstalledStatusFromBundle (ext , installedBundle , nil )
301307
302308 l .Info ("watching managed objects" )
303309 cache , err := r .Manager .Get (ctx , ext )
@@ -466,32 +472,38 @@ type DefaultInstalledBundleGetter struct {
466472 helmclient.ActionClientGetter
467473}
468474
469- func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1.BundleMetadata , error ) {
475+ type InstalledBundle struct {
476+ ocv1alpha1.BundleMetadata
477+ Image string
478+ }
479+
480+ func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* InstalledBundle , error ) {
470481 cl , err := d .ActionClientFor (ctx , ext )
471482 if err != nil {
472483 return nil , err
473484 }
474485
475- rel , err := cl .Get (ext .GetName ())
486+ relhis , err := cl .History (ext .GetName ())
476487 if err != nil && ! errors .Is (err , driver .ErrReleaseNotFound ) {
477488 return nil , err
478489 }
479- if rel == nil {
490+ if len ( relhis ) == 0 {
480491 return nil , nil
481492 }
482493
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 )
494+ // TODO: relhis[0].Info.Status is the status of the highest semver install attempt.
495+ // This might be useful informaton if it's not release.StatusDeployed, in telling us
496+ // the status of an upgrade attempt.
497+ for _ , rel := range relhis {
498+ if rel .Info != nil && rel .Info .Status == release .StatusDeployed {
499+ return & InstalledBundle {
500+ BundleMetadata : ocv1alpha1.BundleMetadata {
501+ Name : rel .Labels [labels .BundleNameKey ],
502+ Version : rel .Labels [labels .BundleVersionKey ],
503+ },
504+ Image : rel .Labels [labels .BundleReferenceKey ],
505+ }, nil
506+ }
491507 }
492-
493- return & ocv1alpha1.BundleMetadata {
494- Name : rel .Labels [labels .BundleNameKey ],
495- Version : rel .Labels [labels .BundleVersionKey ],
496- }, nil
508+ return nil , nil
497509}
0 commit comments