Skip to content

Commit

Permalink
moved docs, created reconcile result object (#5599)
Browse files Browse the repository at this point in the history
Signed-off-by: Venkat Ramaraju <[email protected]>
  • Loading branch information
VenkatRamaraju authored Mar 16, 2022
1 parent d632ae2 commit f5e15be
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 41 deletions.
31 changes: 16 additions & 15 deletions internal/helm/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
status := types.StatusFor(o)
log = log.WithValues("release", manager.ReleaseName())

reconcileResult := reconcile.Result{RequeueAfter: r.ReconcilePeriod}
// Determine the correct reconcile period based on the existing value in the reconciler and the
// annotations in the custom resource. If a reconcile period is specified in the custom resource
// annotations, this value will take precedence over the the existing reconcile period value
// (which came from either the command-line flag or the watches.yaml file).
finalReconcilePeriod, err := determineReconcilePeriod(r.ReconcilePeriod, o)
if err != nil {
log.Error(err, "Error: unable to parse reconcile period from the custom resource's annotations")
return reconcile.Result{}, err
}
reconcileResult.RequeueAfter = finalReconcilePeriod

if o.GetDeletionTimestamp() != nil {
if !(controllerutil.ContainsFinalizer(o, uninstallFinalizer) ||
controllerutil.ContainsFinalizer(o, uninstallFinalizerLegacy)) {
Expand Down Expand Up @@ -172,7 +184,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
}
if !isAllResourcesDeleted {
log.Info("Waiting until all resources are deleted")
return reconcile.Result{RequeueAfter: r.ReconcilePeriod}, nil
return reconcileResult, nil
}
status.RemoveCondition(types.ConditionReleaseFailed)
}
Expand Down Expand Up @@ -272,7 +284,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
Manifest: installedRelease.Manifest,
}
err = r.updateResourceStatus(ctx, o, status)
return reconcile.Result{RequeueAfter: r.ReconcilePeriod}, err
return reconcileResult, err
}

if !(controllerutil.ContainsFinalizer(o, uninstallFinalizer) ||
Expand Down Expand Up @@ -335,7 +347,7 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
Manifest: upgradedRelease.Manifest,
}
err = r.updateResourceStatus(ctx, o, status)
return reconcile.Result{RequeueAfter: r.ReconcilePeriod}, err
return reconcileResult, err
}

// If a change is made to the CR spec that causes a release failure, a
Expand Down Expand Up @@ -389,19 +401,8 @@ func (r HelmOperatorReconciler) Reconcile(ctx context.Context, request reconcile
Manifest: expectedRelease.Manifest,
}

// Determine the correct reconcile period based on the existing value in the reconciler and the
// annotations in the custom resource. If a reconcile period is specified in the custom resource
// annotations, this value will take precedence over the the existing reconcile period value
// (which came from either the command-line flag or the watches.yaml file).
finalReconcilePeriod, err := determineReconcilePeriod(r.ReconcilePeriod, o)
if err != nil {
log.Error(err, "Error: unable to parse reconcile period from the custom resource's annotations")
return reconcile.Result{}, err
}
r.ReconcilePeriod = finalReconcilePeriod

err = r.updateResourceStatus(ctx, o, status)
return reconcile.Result{RequeueAfter: r.ReconcilePeriod}, err
return reconcileResult, err
}

// returns the reconcile period that will be set to the RequeueAfter field in the reconciler. If any period
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,25 @@ log message when a delete has been triggered:
{"level":"info","ts":1612294054.5845876,"logger":"helm.controller","msg":"Uninstall wait","namespace":"default","name":"nginx-sample","apiVersion":"example.com/v1alpha1","kind":"Nginx","release":"nginx-sample"}
```

## `helm.sdk.operatorframework.io/reconcile-period`

While running a Helm-based operator, the reconcile-period can be specified through the custom resource's annotations under the `helm.sdk.operatorframework.io/reconcile-period` key.
This feature guarantees that an operator will get reconciled, at minimum, in the specified interval of time. In other words, it ensures that the cluster will not go longer
than the specified reconcile-period without being reconciled. However, the cluster may be reconciled at any moment if there are changes detected in the desired state.

The reconcile period can be specified in the custom resource's annotations in the following manner:

```sh
...
metadata:
name: nginx-sample
annotations:
helm.sdk.operatorframework.io/reconcile-period: 5s
...
```

The value that is present under this key must be in the h/m/s format. For example, 1h2m4s, 3m0s, 4s are all valid values, but 1x3m9s is invalid.

**NOTE**: This is just one way of specifying the reconcile period for Helm-based operators. There are two other ways: using the `--reconcile-period` command-line flag and under the 'reconcilePeriod' key in the watches.yaml file. If these three methods are used simultaneously to specify reconcile period (which they should not be), the order of precedence is as follows:
Custom Resource Annotations > watches.yaml > command-line flag.

This file was deleted.

0 comments on commit f5e15be

Please sign in to comment.