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

Report when backoff limit is exceeded #356

Merged
merged 2 commits into from
May 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ You can get the OpenStackAnsibleEE resource created with the `oc get openstackan
```bash
$ oc get osaee
NAME NETWORKATTACHMENTS STATUS MESSAGE
ansibleee-playbook-local True AnsibleExecutionJob complete
ansibleee-playbook-local True Job completed
```

After knowing the name of the OpenStackAnsibleEE resource, you can search for its pod by filtering the `openstackansibleee_cr` label.
Expand Down
47 changes: 0 additions & 47 deletions api/v1beta1/conditions.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/v1beta1/openstack_ansibleee_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,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
23 changes: 15 additions & 8 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 @@ -208,20 +208,27 @@ 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 {
var errorReason condition.Reason
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
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
2 changes: 1 addition & 1 deletion docs/assemblies/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ You can get the OpenStackAnsibleEE resource created with the `oc get openstackan
----
$ oc get osaee
NAME NETWORKATTACHMENTS STATUS MESSAGE
ansibleee-playbook-local True AnsibleExecutionJob complete
ansibleee-playbook-local True Job completed
----

After knowing the name of the OpenStackAnsibleEE resource, you can search for its pod by filtering the `openstackansibleee_cr` label.
Expand Down
73 changes: 36 additions & 37 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,10 +39,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
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,10 +79,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
Expand All @@ -102,10 +101,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
"Job error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
)
th.ExpectCondition(
ansibleeeName,
Expand All @@ -123,10 +122,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
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,10 +162,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("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,10 +196,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
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,10 +236,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
Expand All @@ -259,10 +258,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
"Job error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
)
th.ExpectCondition(
ansibleeeName,
Expand Down Expand Up @@ -328,10 +327,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
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,10 +367,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
Expand All @@ -390,10 +389,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
"Job error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
)
th.ExpectCondition(
ansibleeeName,
Expand Down Expand Up @@ -476,10 +475,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
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,10 +515,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
th.ExpectCondition(
ansibleeeName,
Expand All @@ -538,10 +537,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.ErrorReason,
"AnsibleExecutionJob error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
"Job error occurred Internal error occurred: Job Attempt #1 Failed. Check job logs",
)
th.ExpectCondition(
ansibleeeName,
Expand Down Expand Up @@ -569,10 +568,10 @@ var _ = Describe("Ansibleee controller", func() {
th.ExpectConditionWithDetails(
ansibleeeName,
ConditionGetterFunc(AnsibleeeConditionGetter),
v1beta1.AnsibleExecutionJobReadyCondition,
condition.JobReadyCondition,
corev1.ConditionFalse,
condition.RequestedReason,
"AnsibleExecutionJob is running",
"Job in progress",
)
marshalled := map[string]json.RawMessage{
"foo": json.RawMessage([]byte("\"bar\"")),
Expand Down
Loading
Loading