@@ -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 ) (* ocv1alpha1.BundleMetadata , release. Status , error )
88
88
}
89
89
90
90
//+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
203
203
}
204
204
205
205
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 )
207
208
if err != nil {
208
209
setInstallStatus (ext , nil )
209
- // TODO: use Installed=Unknown
210
- setInstalledStatusConditionFailed (ext , err .Error ())
210
+ setInstalledStatusConditionUnknown (ext , err .Error ())
211
211
setStatusProgressing (ext , err )
212
212
return ctrl.Result {}, err
213
213
}
214
214
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
+
215
229
// run resolution
216
230
l .Info ("resolving bundle" )
217
231
resolvedBundle , resolvedBundleVersion , resolvedDeprecation , err := r .Resolver .Resolve (ctx , ext , installedBundle )
218
232
if err != nil {
219
233
// Note: We don't distinguish between resolution-specific errors and generic errors
220
- setInstallStatus (ext , nil )
221
234
setStatusProgressing (ext , err )
222
235
ensureAllConditionsWithReason (ext , ocv1alpha1 .ReasonFailed , err .Error ())
223
236
return ctrl.Result {}, err
@@ -466,32 +479,36 @@ type DefaultInstalledBundleGetter struct {
466
479
helmclient.ActionClientGetter
467
480
}
468
481
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
470
484
cl , err := d .ActionClientFor (ctx , ext )
471
485
if err != nil {
472
- return nil , err
486
+ return nil , status , err
473
487
}
474
488
475
- rel , err := cl .Get (ext .GetName ())
489
+ relhis , err := cl .History (ext .GetName ())
476
490
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
478
495
}
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
+ }
481
504
}
482
505
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
491
508
}
492
509
493
510
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
497
514
}
0 commit comments