Skip to content

Commit e669088

Browse files
committed
add progressing condition
Signed-off-by: everettraven <[email protected]>
1 parent 62b5c53 commit e669088

File tree

7 files changed

+288
-211
lines changed

7 files changed

+288
-211
lines changed

api/v1alpha1/clusterextension_types.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ import (
2222
"github.com/operator-framework/operator-controller/internal/conditionsets"
2323
)
2424

25-
var (
26-
ClusterExtensionKind = "ClusterExtension"
27-
)
25+
var ClusterExtensionKind = "ClusterExtension"
2826

29-
type UpgradeConstraintPolicy string
30-
type CRDUpgradeSafetyPolicy string
27+
type (
28+
UpgradeConstraintPolicy string
29+
CRDUpgradeSafetyPolicy string
30+
)
3131

3232
const (
3333
// The extension will only upgrade if the new version satisfies
@@ -412,9 +412,10 @@ type CRDUpgradeSafetyPreflightConfig struct {
412412

413413
const (
414414
// TODO(user): add more Types, here and into init()
415-
TypeInstalled = "Installed"
416-
TypeResolved = "Resolved"
417-
TypeHealthy = "Healthy"
415+
TypeInstalled = "Installed"
416+
TypeResolved = "Resolved"
417+
TypeHealthy = "Healthy"
418+
TypeProgressing = "Progressing"
418419

419420
// TypeDeprecated is a rollup condition that is present when
420421
// any of the deprecated conditions are present.
@@ -427,6 +428,8 @@ const (
427428
ReasonSuccess = "Succeeded"
428429
ReasonDeprecated = "Deprecated"
429430
ReasonFailed = "Failed"
431+
ReasonBlocked = "Blocked"
432+
ReasonRetrying = "Retrying"
430433

431434
ReasonErrorGettingClient = "ErrorGettingClient"
432435
ReasonErrorGettingReleaseState = "ErrorGettingReleaseState"
@@ -448,6 +451,7 @@ func init() {
448451
TypeBundleDeprecated,
449452
TypeUnpacked,
450453
TypeHealthy,
454+
TypeProgressing,
451455
)
452456
// TODO(user): add Reasons from above
453457
conditionsets.ConditionReasons = append(conditionsets.ConditionReasons,
@@ -457,6 +461,8 @@ func init() {
457461
ReasonErrorGettingClient,
458462
ReasonErrorGettingReleaseState,
459463
ReasonUnverifiable,
464+
ReasonBlocked,
465+
ReasonRetrying,
460466
)
461467
}
462468

internal/controllers/clusterextension_controller.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
201201
setInstallStatus(ext, nil)
202202
setResolutionStatus(ext, nil)
203203
setResolvedStatusConditionFailed(ext, err.Error())
204+
setStatusProgressing(ext, err)
204205
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonFailed, err.Error())
205206
return ctrl.Result{}, err
206207
}
@@ -216,6 +217,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
216217
setInstallStatus(ext, nil)
217218
// TODO: use Installed=Unknown
218219
setInstalledStatusConditionFailed(ext, err.Error())
220+
setStatusProgressing(ext, err)
219221
return ctrl.Result{}, err
220222
}
221223

@@ -227,6 +229,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
227229
setInstallStatus(ext, nil)
228230
setResolutionStatus(ext, nil)
229231
setResolvedStatusConditionFailed(ext, err.Error())
232+
setStatusProgressing(ext, err)
230233
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonFailed, err.Error())
231234
return ctrl.Result{}, err
232235
}
@@ -264,20 +267,15 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
264267
unpackResult, err := r.Unpacker.Unpack(ctx, bundleSource)
265268
if err != nil {
266269
setStatusUnpackFailed(ext, err.Error())
270+
setStatusProgressing(ext, err)
267271
return ctrl.Result{}, err
268272
}
269273

270274
switch unpackResult.State {
271-
case rukpaksource.StatePending:
272-
setStatusUnpackFailed(ext, unpackResult.Message)
273-
ensureAllConditionsWithReason(ext, ocv1alpha1.ReasonFailed, "unpack pending")
274-
return ctrl.Result{}, nil
275275
case rukpaksource.StateUnpacked:
276276
setStatusUnpacked(ext, unpackResult.Message)
277277
default:
278-
setStatusUnpackFailed(ext, "unexpected unpack status")
279-
// We previously exit with a failed status if error is not nil.
280-
return ctrl.Result{}, fmt.Errorf("unexpected unpack status: %v", unpackResult.Message)
278+
panic(fmt.Sprintf("unexpected unpack state %q", unpackResult.State))
281279
}
282280

283281
objLbls := map[string]string{
@@ -304,6 +302,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
304302
managedObjs, _, err := r.Applier.Apply(ctx, unpackResult.Bundle, ext, objLbls, storeLbls)
305303
if err != nil {
306304
setInstalledStatusConditionFailed(ext, err.Error())
305+
setStatusProgressing(ext, err)
307306
return ctrl.Result{}, err
308307
}
309308

@@ -325,6 +324,7 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
325324
Message: err.Error(),
326325
ObservedGeneration: ext.Generation,
327326
})
327+
setStatusProgressing(ext, err)
328328
return ctrl.Result{}, err
329329
}
330330

@@ -338,13 +338,20 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
338338
Message: err.Error(),
339339
ObservedGeneration: ext.Generation,
340340
})
341+
setStatusProgressing(ext, err)
341342
return ctrl.Result{}, err
342343
}
343344

344345
// If we have successfully established the watches, remove the "Healthy" condition.
345346
// It should be interpreted as "Unknown" when not present.
346347
apimeta.RemoveStatusCondition(&ext.Status.Conditions, ocv1alpha1.TypeHealthy)
347348

349+
// If we made it here, we have successfully reconciled the ClusterExtension
350+
// and have reached the desired state. Since the Progressing status should reflect
351+
// our progress towards the desired state, we also set it when we have reached
352+
// the desired state by providing a nil error value.
353+
setStatusProgressing(ext, nil)
354+
348355
return ctrl.Result{}, nil
349356
}
350357

0 commit comments

Comments
 (0)