@@ -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,22 @@ 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+ setInstalledStatusConditionUnknown (ext , err .Error ())
210+ setStatusProgressing (ext , errors .New ("retrying to get installed bundle" ))
212211 return ctrl.Result {}, err
213212 }
214213
215214 // run resolution
216215 l .Info ("resolving bundle" )
217- resolvedBundle , resolvedBundleVersion , resolvedDeprecation , err := r .Resolver .Resolve (ctx , ext , installedBundle )
216+ var bm * ocv1alpha1.BundleMetadata
217+ if installedBundle != nil {
218+ bm = & installedBundle .BundleMetadata
219+ }
220+ resolvedBundle , resolvedBundleVersion , resolvedDeprecation , err := r .Resolver .Resolve (ctx , ext , bm )
218221 if err != nil {
219222 // Note: We don't distinguish between resolution-specific errors and generic errors
220- setInstallStatus (ext , nil )
221223 setStatusProgressing (ext , err )
224+ setInstalledStatusFromBundle (ext , installedBundle )
222225 ensureAllConditionsWithReason (ext , ocv1alpha1 .ReasonFailed , err .Error ())
223226 return ctrl.Result {}, err
224227 }
@@ -255,6 +258,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
255258 // installed since we intend for the progressing condition to replace the resolved condition
256259 // and will be removing the .status.resolution field from the ClusterExtension status API
257260 setStatusProgressing (ext , wrapErrorWithResolutionInfo (resolvedBundleMetadata , err ))
261+ setInstalledStatusFromBundle (ext , installedBundle )
258262 return ctrl.Result {}, err
259263 }
260264
@@ -268,9 +272,10 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
268272 }
269273
270274 storeLbls := map [string ]string {
271- labels .BundleNameKey : resolvedBundle .Name ,
272- labels .PackageNameKey : resolvedBundle .Package ,
273- labels .BundleVersionKey : resolvedBundleVersion .String (),
275+ labels .BundleNameKey : resolvedBundle .Name ,
276+ labels .PackageNameKey : resolvedBundle .Package ,
277+ labels .BundleVersionKey : resolvedBundleVersion .String (),
278+ labels .BundleReferenceKey : resolvedBundle .Image ,
274279 }
275280
276281 l .Info ("applying bundle contents" )
@@ -286,18 +291,17 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
286291 managedObjs , _ , err := r .Applier .Apply (ctx , unpackResult .Bundle , ext , objLbls , storeLbls )
287292 if err != nil {
288293 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- }
294+ // Now that we're actually trying to install, use the error
295+ setInstalledStatusFromBundle (ext , installedBundle )
293296 return ctrl.Result {}, err
294297 }
295298
296- installStatus := & ocv1alpha1.ClusterExtensionInstallStatus {
297- Bundle : resolvedBundleMetadata ,
299+ newInstalledBundle := & InstalledBundle {
300+ BundleMetadata : resolvedBundleMetadata ,
301+ Image : resolvedBundle .Image ,
298302 }
299- setInstallStatus ( ext , installStatus )
300- setInstalledStatusConditionSuccess (ext , fmt . Sprintf ( "Installed bundle %s successfully" , resolvedBundle . Image ) )
303+ // Successful install
304+ setInstalledStatusFromBundle (ext , newInstalledBundle )
301305
302306 l .Info ("watching managed objects" )
303307 cache , err := r .Manager .Get (ctx , ext )
@@ -466,32 +470,45 @@ type DefaultInstalledBundleGetter struct {
466470 helmclient.ActionClientGetter
467471}
468472
469- func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1.BundleMetadata , error ) {
473+ type InstalledBundle struct {
474+ ocv1alpha1.BundleMetadata
475+ Image string
476+ }
477+
478+ func (d * DefaultInstalledBundleGetter ) GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* InstalledBundle , error ) {
470479 cl , err := d .ActionClientFor (ctx , ext )
471480 if err != nil {
472481 return nil , err
473482 }
474483
475- rel , err := cl .Get (ext .GetName ())
484+ relhis , err := cl .History (ext .GetName ())
476485 if err != nil && ! errors .Is (err , driver .ErrReleaseNotFound ) {
477486 return nil , err
478487 }
479- if rel == nil {
488+ if len ( relhis ) == 0 {
480489 return nil , nil
481490 }
482491
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 )
492+ // relhis[0].Info.Status is the status of the most recent install attempt.
493+ // But we need to look for the most-recent _Deployed_ release
494+ for _ , rel := range relhis {
495+ if rel .Info != nil && rel .Info .Status == release .StatusDeployed {
496+ // If there are blank values, we should consider this as not installed
497+ if n , ok := rel .Labels [labels .BundleNameKey ]; ! ok || n == "" {
498+ return nil , nil
499+ }
500+ if v , ok := rel .Labels [labels .BundleVersionKey ]; ! ok || v == "" {
501+ return nil , nil
502+ }
503+ // Not checking BundleReferenceKey, as it's new; upgrade test would fail
504+ return & InstalledBundle {
505+ BundleMetadata : ocv1alpha1.BundleMetadata {
506+ Name : rel .Labels [labels .BundleNameKey ],
507+ Version : rel .Labels [labels .BundleVersionKey ],
508+ },
509+ Image : rel .Labels [labels .BundleReferenceKey ],
510+ }, nil
511+ }
491512 }
492-
493- return & ocv1alpha1.BundleMetadata {
494- Name : rel .Labels [labels .BundleNameKey ],
495- Version : rel .Labels [labels .BundleVersionKey ],
496- }, nil
513+ return nil , nil
497514}
0 commit comments