Skip to content

Commit

Permalink
Report when backoff limit is exceeded
Browse files Browse the repository at this point in the history
Depends-On: openstack-k8s-operators/lib-common#504
Signed-off-by: Fabricio Aguiar <[email protected]>
  • Loading branch information
fao89 committed May 7, 2024
1 parent d464430 commit 6db26ab
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 86 deletions.
3 changes: 3 additions & 0 deletions api/bases/ansibleee.openstack.org_openstackansibleees.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ spec:
- type
type: object
type: array
failed:
format: int64
type: integer
hash:
additionalProperties:
type: string
Expand Down
47 changes: 0 additions & 47 deletions api/v1beta1/conditions.go

This file was deleted.

6 changes: 5 additions & 1 deletion api/v1beta1/openstack_ansibleee_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ type OpenStackAnsibleEEStatus struct {
// JobStatus status of the executed job (Pending/Running/Succeeded/Failed)
JobStatus string `json:"JobStatus,omitempty" optional:"true"`

// The number of pods which reached phase Failed.
// +optional
Failed int64 `json:"failed,omitempty"`

// ObservedGeneration - the most recent generation observed for this
// service. If the observed generation is less than the spec generation,
// then the controller has not processed the latest changes injected by
Expand Down Expand Up @@ -182,7 +186,7 @@ func init() {

// IsReady - returns true if the OpenStackAnsibleEE is ready
func (instance OpenStackAnsibleEE) IsReady() bool {
return instance.Status.Conditions.IsTrue(AnsibleExecutionJobReadyCondition)
return instance.Status.Conditions.IsTrue(condition.JobReadyCondition)
}

// SetupDefaults - initializes any CRD field defaults based on environment variables (the defaulting mechanism itself is implemented via webhooks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ spec:
- type
type: object
type: array
failed:
format: int64
type: integer
hash:
additionalProperties:
type: string
Expand Down
25 changes: 16 additions & 9 deletions controllers/openstack_ansibleee_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R

cl := condition.CreateList(
condition.UnknownCondition(condition.ReadyCondition, condition.InitReason, condition.ReadyInitMessage),
condition.UnknownCondition(ansibleeev1.AnsibleExecutionJobReadyCondition, condition.InitReason, ansibleeev1.AnsibleExecutionJobInitMessage),
condition.UnknownCondition(condition.JobReadyCondition, condition.InitReason, condition.JobReadyInitMessage),
)

instance.Status.Conditions.Init(&cl)
Expand Down Expand Up @@ -163,7 +163,7 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.SeverityError,
condition.NetworkAttachmentsReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
Expand Down Expand Up @@ -208,22 +208,29 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R

if (ctrlResult != ctrl.Result{}) {
instance.Status.Conditions.Set(condition.FalseCondition(
ansibleeev1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
ansibleeev1.AnsibleExecutionJobWaitingMessage))
condition.JobReadyRunningMessage))
instance.Status.JobStatus = ansibleeev1.JobStatusRunning
return ctrlResult, nil
}

if err != nil {
errorReason := condition.ErrorReason
severity := condition.SeverityWarning
if ansibleeeJob.HasReachedLimit() {
errorReason = condition.JobReasonBackoffLimitExceeded
severity = condition.SeverityError
}
instance.Status.Conditions.Set(condition.FalseCondition(
ansibleeev1.AnsibleExecutionJobReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
ansibleeev1.AnsibleExecutionJobErrorMessage,
condition.JobReadyCondition,
errorReason,
severity,
condition.JobReadyErrorMessage,
err.Error()))
instance.Status.JobStatus = ansibleeev1.JobStatusFailed
instance.Status.Failed = ansibleeeJob.GetTotalFailedAttempts()
return ctrl.Result{}, err
}

Expand All @@ -232,7 +239,7 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R
Log.Info(fmt.Sprintf("AnsibleEE CR '%s' - Job %s hash added - %s", instance.Name, jobDef.Name, instance.Status.Hash[ansibleeeJobType]))
}

instance.Status.Conditions.MarkTrue(ansibleeev1.AnsibleExecutionJobReadyCondition, ansibleeev1.AnsibleExecutionJobReadyMessage)
instance.Status.Conditions.MarkTrue(condition.JobReadyCondition, condition.JobReadyMessage)
instance.Status.JobStatus = ansibleeev1.JobStatusSucceeded

// We reached the end of the Reconcile, update the Ready condition based on
Expand Down
5 changes: 5 additions & 0 deletions docs/assemblies/openstack_ansibleee.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ OpenStackAnsibleEEStatus defines the observed state of OpenStackAnsibleEE
| string
| false
| failed
| The number of pods which reached phase Failed.
| int64
| false
| observedGeneration
| ObservedGeneration - the most recent generation observed for this service. If the observed generation is less than the spec generation, then the controller has not processed the latest changes injected by the opentack-operator in the top-level CR (e.g. the ContainerImage)
| int64
Expand Down
43 changes: 21 additions & 22 deletions tests/functional/ansibleee_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

//revive:disable-next-line:dot-imports
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
"github.com/openstack-k8s-operators/openstack-ansibleee-operator/api/v1beta1"
)

var _ = Describe("Ansibleee controller", func() {
Expand All @@ -40,7 +39,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -61,7 +60,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectCondition(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
Expand All @@ -80,7 +79,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -102,7 +101,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occured Internal error occurred: Job Failed. Check job logs",
Expand All @@ -123,7 +122,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -140,7 +139,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectCondition(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionTrue,
)
ansibleee := GetAnsibleee(ansibleeeName)
Expand All @@ -163,7 +162,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -177,7 +176,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectCondition(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionTrue,
)
ansibleee = GetAnsibleee(ansibleeeName)
Expand All @@ -197,7 +196,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -218,7 +217,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectCondition(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
Expand All @@ -237,7 +236,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -259,7 +258,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occured Internal error occurred: Job Failed. Check job logs",
Expand Down Expand Up @@ -328,7 +327,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -349,7 +348,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectCondition(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
Expand All @@ -368,7 +367,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -390,7 +389,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occured Internal error occurred: Job Failed. Check job logs",
Expand Down Expand Up @@ -476,7 +475,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -497,7 +496,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectCondition(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionTrue,
)
th.ExpectCondition(
Expand All @@ -516,7 +515,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand All @@ -538,7 +537,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occured Internal error occurred: Job Failed. Check job logs",
Expand Down Expand Up @@ -569,7 +568,7 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
Expand Down
15 changes: 8 additions & 7 deletions tests/kuttl/tests/run_failed_playbook/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ spec:
preserveJobs: true
status:
JobStatus: Failed
failed: 4
conditions:
- message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed.
- message: 'Job error occured Internal error occurred: Job has reached the specified backoff limit.
Check job logs'
reason: Error
severity: Warning
reason: BackoffLimitExceeded
severity: Error
status: "False"
type: Ready
- message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed.
- message: 'Job error occured Internal error occurred: Job has reached the specified backoff limit.
Check job logs'
reason: Error
severity: Warning
reason: BackoffLimitExceeded
severity: Error
status: "False"
type: AnsibleExecutionJobReady
type: JobReady
---
apiVersion: v1
kind: Pod
Expand Down

0 comments on commit 6db26ab

Please sign in to comment.