Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remediateLastFailure #1372

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api/v1alpha2/terraform_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ type Remediation struct {
// retries.
// +optional
Retries int64 `json:"retries,omitempty"`

// RemediateLastFailure tells the controller to remediate the last failure, when
// no retries remain. Defaults to 'false' unless 'Retries' is greater than 0.
// +optional
RemediateLastFailure *bool `json:"remediateLastFailure,omitempty"`

}

type CloudSpec struct {
Expand Down Expand Up @@ -954,6 +960,15 @@ func (in *Terraform) GetRetries() int64 {
return in.Spec.Remediation.Retries
}

// MustRemediateLastFailure returns whether to remediate the last failure when
// no retries remain.
func (in *Terraform) MustRemediateLastFailure() bool {
if in.Spec.Remediation.RemediateLastFailure == nil {
return false
}
return *in.Spec.Remediation.RemediateLastFailure
}

func (in *Terraform) GetReconciliationFailures() int64 {
return in.Status.ReconciliationFailures
}
Expand Down
6 changes: 6 additions & 0 deletions charts/tofu-controller/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5581,6 +5581,12 @@ spec:
retries.
format: int64
type: integer
remediateLastFailure:
default: false
description: |-
remediateLastFailure instructs the controller to remediate the last failure
when no retries remain. Defaults to false
type: boolean
type: object
retryInterval:
description: |-
Expand Down
10 changes: 10 additions & 0 deletions controllers/tf_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,16 @@ func (r *TerraformReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
terraform.GetGeneration(),
))

if terraform.MustRemediateLastFailure() {
log.Info("RemediateLastFailure is true, reseting retries, requeue after interval", "interval", terraform.Spec.Interval.Duration.String())
terraform = infrav1.TerraformResetRetry(terraform)
if err := r.patchStatus(ctx, req.NamespacedName, terraform.Status); err != nil {
log.Error(err, "unable to update status after maximum number of retries reached")
return ctrl.Result{Requeue: true}, err
}
return ctrl.Result{RequeueAfter: terraform.Spec.Interval.Duration}, nil
}

terraform = infrav1.TerraformReachedLimit(terraform)

traceLog.Info("Patch the status of the Terraform resource")
Expand Down
13 changes: 13 additions & 0 deletions docs/References/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,19 @@ before bailing. Defaults to ‘0’, a negative integer denotes unlimite
retries.</p>
</td>
</tr>
<tr>
<td>
<code>remediateLastFailure</code><br>
<em>
bool
</em>
</td>
<td>
<em>(Optional)</em>
<p>RemediateLastFailure tells the controller to remediate the last failure, when
no retries remain. Defaults to &lsquo;false&rsquo; unless &lsquo;Retries&rsquo; is greater than 0.</p>
</td>
</tr>
</tbody>
</table>
</div>
Expand Down
Loading