@@ -84,7 +84,7 @@ type Applier interface {
84
84
}
85
85
86
86
type InstalledBundleGetter interface {
87
- GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* ocv1alpha1. BundleMetadata , error )
87
+ GetInstalledBundle (ctx context.Context , ext * ocv1alpha1.ClusterExtension ) (* InstalledBundle , error )
88
88
}
89
89
90
90
//+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
206
206
installedBundle , err := r .InstalledBundleGetter .GetInstalledBundle (ctx , ext )
207
207
if err != nil {
208
208
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" ))
212
211
return ctrl.Result {}, err
213
212
}
214
213
215
214
// run resolution
216
215
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 )
218
221
if err != nil {
219
222
// Note: We don't distinguish between resolution-specific errors and generic errors
220
- setInstallStatus (ext , nil )
221
223
setStatusProgressing (ext , err )
224
+ setInstalledStatusFromBundle (ext , installedBundle , nil )
222
225
ensureAllConditionsWithReason (ext , ocv1alpha1 .ReasonFailed , err .Error ())
223
226
return ctrl.Result {}, err
224
227
}
@@ -255,6 +258,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
255
258
// installed since we intend for the progressing condition to replace the resolved condition
256
259
// and will be removing the .status.resolution field from the ClusterExtension status API
257
260
setStatusProgressing (ext , wrapErrorWithResolutionInfo (resolvedBundleMetadata , err ))
261
+ setInstalledStatusFromBundle (ext , installedBundle , nil )
258
262
return ctrl.Result {}, err
259
263
}
260
264
@@ -268,9 +272,10 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
268
272
}
269
273
270
274
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 ,
274
279
}
275
280
276
281
l .Info ("applying bundle contents" )
@@ -286,18 +291,17 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
286
291
managedObjs , _ , err := r .Applier .Apply (ctx , unpackResult .Bundle , ext , objLbls , storeLbls )
287
292
if err != nil {
288
293
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 , err )
293
296
return ctrl.Result {}, err
294
297
}
295
298
296
- installStatus := & ocv1alpha1.ClusterExtensionInstallStatus {
297
- Bundle : resolvedBundleMetadata ,
299
+ newInstalledBundle := & InstalledBundle {
300
+ BundleMetadata : resolvedBundleMetadata ,
301
+ Image : resolvedBundle .Image ,
298
302
}
299
- setInstallStatus ( ext , installStatus )
300
- setInstalledStatusConditionSuccess (ext , fmt . Sprintf ( "Installed bundle %s successfully" , resolvedBundle . Image ) )
303
+ // Successful install
304
+ setInstalledStatusFromBundle (ext , newInstalledBundle , nil )
301
305
302
306
l .Info ("watching managed objects" )
303
307
cache , err := r .Manager .Get (ctx , ext )
@@ -466,32 +470,46 @@ type DefaultInstalledBundleGetter struct {
466
470
helmclient.ActionClientGetter
467
471
}
468
472
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 ) {
470
479
cl , err := d .ActionClientFor (ctx , ext )
471
480
if err != nil {
472
481
return nil , err
473
482
}
474
483
475
- rel , err := cl .Get (ext .GetName ())
484
+ relhis , err := cl .History (ext .GetName ())
476
485
if err != nil && ! errors .Is (err , driver .ErrReleaseNotFound ) {
477
486
return nil , err
478
487
}
479
- if rel == nil {
488
+ if len ( relhis ) == 0 {
480
489
return nil , nil
481
490
}
482
491
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
+ // TODO: relhis[0].Info.Status is the status of the most recent install attempt.
493
+ // This might be useful informaton if it's not release.StatusDeployed, in telling us
494
+ // the status of an upgrade attempt.
495
+ for _ , rel := range relhis {
496
+ if rel .Info != nil && rel .Info .Status == release .StatusDeployed {
497
+ // If there are blank values, we should consider this as not installed
498
+ if n , ok := rel .Labels [labels .BundleNameKey ]; ! ok || n == "" {
499
+ return nil , nil
500
+ }
501
+ if v , ok := rel .Labels [labels .BundleVersionKey ]; ! ok || v == "" {
502
+ return nil , nil
503
+ }
504
+ // Not checking BundleReferenceKey, as it's new; upgrade test would fail
505
+ return & InstalledBundle {
506
+ BundleMetadata : ocv1alpha1.BundleMetadata {
507
+ Name : rel .Labels [labels .BundleNameKey ],
508
+ Version : rel .Labels [labels .BundleVersionKey ],
509
+ },
510
+ Image : rel .Labels [labels .BundleReferenceKey ],
511
+ }, nil
512
+ }
491
513
}
492
-
493
- return & ocv1alpha1.BundleMetadata {
494
- Name : rel .Labels [labels .BundleNameKey ],
495
- Version : rel .Labels [labels .BundleVersionKey ],
496
- }, nil
514
+ return nil , nil
497
515
}
0 commit comments