@@ -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 ())
211- setStatusProgressing (ext , err )
209+ // The error is put into Progressing
210+ setInstalledStatusConditionUnknown (ext , err .Error ())
211+ setStatusProgressing (ext , errors . New ( "retrying to get installed bundle" ) )
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,17 @@ 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+ // Successful install
307+ setInstalledStatusFromBundle (ext , installedBundle , nil )
301308
302309 l .Info ("watching managed objects" )
303310 cache , err := r .Manager .Get (ctx , ext )
@@ -466,32 +473,38 @@ type DefaultInstalledBundleGetter struct {
466473 helmclient.ActionClientGetter
467474}
468475
469- func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1.BundleMetadata , error ) {
476+ type InstalledBundle struct {
477+ ocv1alpha1.BundleMetadata
478+ Image string
479+ }
480+
481+ func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* InstalledBundle , error ) {
470482 cl , err := d .ActionClientFor (ctx , ext )
471483 if err != nil {
472484 return nil , err
473485 }
474486
475- rel , err := cl .Get (ext .GetName ())
487+ relhis , err := cl .History (ext .GetName ())
476488 if err != nil && ! errors .Is (err , driver .ErrReleaseNotFound ) {
477489 return nil , err
478490 }
479- if rel == nil {
491+ if len ( relhis ) == 0 {
480492 return nil , nil
481493 }
482494
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 )
495+ // TODO: relhis[0].Info.Status is the status of the most recent install attempt.
496+ // This might be useful informaton if it's not release.StatusDeployed, in telling us
497+ // the status of an upgrade attempt.
498+ for _ , rel := range relhis {
499+ if rel .Info != nil && rel .Info .Status == release .StatusDeployed {
500+ return & InstalledBundle {
501+ BundleMetadata : ocv1alpha1.BundleMetadata {
502+ Name : rel .Labels [labels .BundleNameKey ],
503+ Version : rel .Labels [labels .BundleVersionKey ],
504+ },
505+ Image : rel .Labels [labels .BundleReferenceKey ],
506+ }, nil
507+ }
491508 }
492-
493- return & ocv1alpha1.BundleMetadata {
494- Name : rel .Labels [labels .BundleNameKey ],
495- Version : rel .Labels [labels .BundleVersionKey ],
496- }, nil
509+ return nil , nil
497510}
0 commit comments