Skip to content

Commit

Permalink
Fix ansible job error reason
Browse files Browse the repository at this point in the history
This change fixes a nil pointer dereference by ensuring the job failures
exceed the defined BackoffLimit.

Since our logic is written to determine if the BackoffLimit has been
exceeded, there is no need to specifically check the condition.Reason
that would tell us the same thing. We can simply infer from our check
that the job has failed due to the BackoffLimit being reached.

closes OSPRH-11068

Signed-off-by: Fabricio Aguiar <[email protected]>
Co-Authored-by: Brendan Shephard <[email protected]>
  • Loading branch information
fao89 and bshephar committed Oct 31, 2024
1 parent 1276a85 commit 409b331
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions pkg/dataplane/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,47 +195,39 @@ func (d *Deployer) ConditionalDeploy(

}

var ansibleCondition *batchv1.JobCondition
var ansibleCondition batchv1.JobCondition
if nsConditions.IsFalse(readyCondition) {
var ansibleEE *batchv1.Job
var ansibleJob *batchv1.Job
_, labelSelector := dataplaneutil.GetAnsibleExecutionNameAndLabels(&foundService, d.Deployment.Name, d.NodeSet.Name)
ansibleEE, err = dataplaneutil.GetAnsibleExecution(d.Ctx, d.Helper, d.Deployment, labelSelector)
ansibleJob, err = dataplaneutil.GetAnsibleExecution(d.Ctx, d.Helper, d.Deployment, labelSelector)
if err != nil {
// Return nil if we don't have AnsibleEE available yet
if k8s_errors.IsNotFound(err) {
log.Info(fmt.Sprintf("%s AnsibleEE job is not yet found", readyCondition))
return nil
}
log.Error(err, fmt.Sprintf("Error getting ansibleEE job for %s", deployName))
log.Error(err, fmt.Sprintf("Error getting ansibleJob job for %s", deployName))
nsConditions.Set(condition.FalseCondition(
readyCondition,
condition.ErrorReason,
condition.SeverityError,
readyErrorMessage,
err.Error()))
}

if ansibleEE.Status.Succeeded > 0 {
if ansibleJob.Status.Succeeded > 0 {
log.Info(fmt.Sprintf("Condition %s ready", readyCondition))
nsConditions.Set(condition.TrueCondition(
readyCondition,
readyMessage))
} else if ansibleEE.Status.Active > 0 {
log.Info(fmt.Sprintf("AnsibleEE job is not yet completed: Execution: %s, Active pods: %d", ansibleEE.Name, ansibleEE.Status.Active))
nsConditions.Set(condition.FalseCondition(
readyCondition,
condition.RequestedReason,
condition.SeverityInfo,
readyWaitingMessage))
} else if ansibleEE.Status.Failed > 0 {
errorMsg := fmt.Sprintf("execution.name %s execution.namespace %s failed pods: %d", ansibleEE.Name, ansibleEE.Namespace, ansibleEE.Status.Failed)
for _, condition := range ansibleEE.Status.Conditions {
} else if ansibleJob.Status.Failed > *ansibleJob.Spec.BackoffLimit {
errorMsg := fmt.Sprintf("execution.name %s execution.namespace %s failed pods: %d", ansibleJob.Name, ansibleJob.Namespace, ansibleJob.Status.Failed)
for _, condition := range ansibleJob.Status.Conditions {
if condition.Type == batchv1.JobFailed {
ansibleCondition = &condition
ansibleCondition = condition
}
}
if ansibleCondition.Reason == condition.JobReasonBackoffLimitExceeded {
errorMsg = fmt.Sprintf("backoff limit reached for execution.name %s execution.namespace %s execution.condition.message: %s", ansibleEE.Name, ansibleEE.Namespace, ansibleCondition.Message)
errorMsg = fmt.Sprintf("backoff limit reached for execution.name %s execution.namespace %s execution.condition.message: %s", ansibleJob.Name, ansibleJob.Namespace, ansibleCondition.Message)
}
log.Info(fmt.Sprintf("Condition %s error", readyCondition))
err = fmt.Errorf(errorMsg)
Expand All @@ -245,6 +237,13 @@ func (d *Deployer) ConditionalDeploy(
condition.SeverityError,
readyErrorMessage,
err.Error()))
} else {
log.Info(fmt.Sprintf("AnsibleEE job is not yet completed: Execution: %s, Active pods: %d, Failed pods: %d", ansibleJob.Name, ansibleJob.Status.Active, ansibleJob.Status.Failed))
nsConditions.Set(condition.FalseCondition(
readyCondition,
condition.RequestedReason,
condition.SeverityInfo,
readyWaitingMessage))
}
}
d.Status.NodeSetConditions[d.NodeSet.Name] = nsConditions
Expand Down

0 comments on commit 409b331

Please sign in to comment.