Allow suspending of HelmReleases
This commit is contained in:
parent
bb7a2aa616
commit
a4244cc45a
|
@ -115,4 +115,7 @@ const (
|
|||
|
||||
// DependencyNotReadyReason represents the fact that the one of the dependencies is not ready.
|
||||
DependencyNotReadyReason string = "DependencyNotReady"
|
||||
|
||||
// SuspendedReason represents the fact that the reconciliation of the HelmRelease is suspended.
|
||||
SuspendedReason string = "Suspended"
|
||||
)
|
||||
|
|
|
@ -38,6 +38,11 @@ type HelmReleaseSpec struct {
|
|||
// +required
|
||||
Interval metav1.Duration `json:"interval"`
|
||||
|
||||
// Suspend tells the reconciler to suspend reconciliation for this HelmRelease,
|
||||
// it does not apply to already started reconciliations. Defaults to false.
|
||||
// +optional
|
||||
Suspend bool `json:"suspend,omitempty"`
|
||||
|
||||
// ReleaseName used for the Helm release. Defaults to a composition of
|
||||
// '[TargetNamespace-]Name'.
|
||||
// +optional
|
||||
|
|
|
@ -138,6 +138,11 @@ spec:
|
|||
- kind
|
||||
- name
|
||||
type: object
|
||||
suspend:
|
||||
description: Suspend tells the reconciler to suspend reconciliation
|
||||
for this HelmRelease, it does not apply to already started reconciliations.
|
||||
Defaults to false.
|
||||
type: boolean
|
||||
targetNamespace:
|
||||
description: TargetNamespace to target when performing operations for
|
||||
the HelmRelease. Defaults to the namespace of the HelmRelease.
|
||||
|
|
|
@ -78,6 +78,17 @@ func (r *HelmReleaseReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
|
|||
|
||||
log := r.Log.WithValues(strings.ToLower(hr.Kind), req.NamespacedName)
|
||||
|
||||
if hr.Spec.Suspend {
|
||||
msg := "HelmRelease is suspended, skipping reconciliation"
|
||||
hr = v2.HelmReleaseNotReady(hr, hr.Status.LastAttemptedRevision, hr.Status.LastReleaseRevision, v2.SuspendedReason, msg)
|
||||
if err := r.Status().Update(ctx, &hr); err != nil {
|
||||
log.Error(err, "unable to update HelmRelease status")
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
log.Info(msg)
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
hr = v2.HelmReleaseProgressing(hr)
|
||||
if err := r.Status().Update(ctx, &hr); err != nil {
|
||||
log.Error(err, "unable to update HelmRelease status")
|
||||
|
|
|
@ -61,7 +61,7 @@ type HelmReleaseGarbageCollectPredicate struct {
|
|||
}
|
||||
|
||||
func (gc HelmReleaseGarbageCollectPredicate) Delete(e event.DeleteEvent) bool {
|
||||
if hr, ok := e.Object.(*v2.HelmRelease); ok {
|
||||
if hr, ok := e.Object.(*v2.HelmRelease); ok && !hr.Spec.Suspend {
|
||||
cfg, err := newActionCfg(gc.Log, gc.Config, *hr)
|
||||
if err != nil {
|
||||
gc.Log.Error(err, "failed to initialize Helm action configuration for uninstall", "helmrelease", fmt.Sprintf("%s/%s", hr.Namespace, hr.Name))
|
||||
|
|
|
@ -96,6 +96,19 @@ Kubernetes meta/v1.Duration
|
|||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>suspend</code><br>
|
||||
<em>
|
||||
bool
|
||||
</em>
|
||||
</td>
|
||||
<td>
|
||||
<em>(Optional)</em>
|
||||
<p>Suspend tells the reconciler to suspend reconciliation for this HelmRelease,
|
||||
it does not apply to already started reconciliations. Defaults to false.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>releaseName</code><br>
|
||||
<em>
|
||||
string
|
||||
|
@ -391,6 +404,19 @@ Kubernetes meta/v1.Duration
|
|||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>suspend</code><br>
|
||||
<em>
|
||||
bool
|
||||
</em>
|
||||
</td>
|
||||
<td>
|
||||
<em>(Optional)</em>
|
||||
<p>Suspend tells the reconciler to suspend reconciliation for this HelmRelease,
|
||||
it does not apply to already started reconciliations. Defaults to false.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>releaseName</code><br>
|
||||
<em>
|
||||
string
|
||||
|
|
Loading…
Reference in New Issue