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

only handle requeue_after if the run is successful #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
33 changes: 17 additions & 16 deletions internal/ansible/controller/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (r *AnsibleOperatorReconciler) Reconcile(ctx context.Context, request recon
// iterate events from ansible, looking for the final one
statusEvent := eventapi.StatusJobEvent{}
failureMessages := eventapi.FailureMessages{}

for event := range result.Events() {
for _, eHandler := range r.EventHandlers {
go eHandler.Handle(ident, u, event)
Expand All @@ -187,25 +188,26 @@ func (r *AnsibleOperatorReconciler) Reconcile(ctx context.Context, request recon
return reconcile.Result{}, err
}
}
if module, found := event.EventData["task_action"]; found {
if module == "operator_sdk.util.requeue_after" || module == "requeue_after" && event.Event != eventapi.EventRunnerOnFailed {
if data, exists := event.EventData["res"]; exists {
if fields, check := data.(map[string]interface{}); check {
requeueDuration, err := time.ParseDuration(fields["period"].(string))
if err != nil {
logger.Error(err, "Unable to parse time input")
return reconcileResult, err
if event.Event == eventapi.EventRunnerOnFailed && !event.IgnoreError() && !event.Rescued() {
failureMessages = append(failureMessages, event.GetFailedPlaybookMessage())
} else {
if module, found := event.EventData["task_action"]; found {
if module == "operator_sdk.util.requeue_after" || module == "requeue_after" && event.Event != eventapi.EventRunnerOnFailed {
if data, exists := event.EventData["res"]; exists {
if fields, check := data.(map[string]interface{}); check {
requeueDuration, err := time.ParseDuration(fields["period"].(string))
if err != nil {
logger.Error(err, "Unable to parse time input")
return reconcileResult, err
}
reconcileResult.RequeueAfter = requeueDuration
logger.Info(fmt.Sprintf("Set the reconciliation to occur after %s", requeueDuration))
return reconcileResult, nil
}
reconcileResult.RequeueAfter = requeueDuration
logger.Info(fmt.Sprintf("Set the reconciliation to occur after %s", requeueDuration))
return reconcileResult, nil
}
}
}
}
if event.Event == eventapi.EventRunnerOnFailed && !event.IgnoreError() && !event.Rescued() {
failureMessages = append(failureMessages, event.GetFailedPlaybookMessage())
}
}

// To print the stats of the task
Expand Down Expand Up @@ -239,12 +241,11 @@ func (r *AnsibleOperatorReconciler) Reconcile(ctx context.Context, request recon
return reconcile.Result{}, err
}

recentlyDeleted := u.GetDeletionTimestamp() != nil
// We only want to update the CustomResource once, so we'll track changes
// and do it at the end
runSuccessful := len(failureMessages) == 0

recentlyDeleted := u.GetDeletionTimestamp() != nil

// The finalizer has run successfully, time to remove it
if deleted && finalizerExists && runSuccessful {
controllerutil.RemoveFinalizer(u, finalizer)
Expand Down