diff --git a/README.md b/README.md index 5f60c468..68274762 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/api/v1beta1/conditions.go b/api/v1beta1/conditions.go deleted file mode 100644 index e3ac23fd..00000000 --- a/api/v1beta1/conditions.go +++ /dev/null @@ -1,47 +0,0 @@ -/* -Copyright 2023. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package v1beta1 - -import condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" - -// AnsibleEE Condition Types. -const ( - // AnsibleExecutionJobReadyCondition Status=True condition indicates - // AnsibleExecutionJob is ready. - AnsibleExecutionJobReadyCondition condition.Type = "AnsibleExecutionJobReady" -) - -// Common Messages used by AnsibleEE objects. -const ( - // - // AnsibleExecutionJob condition messages - // - // AnsibleExecutionJobInitMessage - AnsibleExecutionJobInitMessage = "AnsibleExecutionJob not started" - - // AnsibleExecutionJobReadyMessage - AnsibleExecutionJobReadyMessage = "AnsibleExecutionJob complete" - - // AnsibleExecutionJobNotFoundMessage - AnsibleExecutionJobNotFoundMessage = "AnsibleExecutionJob not found" - - // AnsibleExecutionJobWaitingMessage - AnsibleExecutionJobWaitingMessage = "AnsibleExecutionJob is running" - - // AnsibleExecutionJobErrorMessage - AnsibleExecutionJobErrorMessage = "AnsibleExecutionJob error occurred %s" -) diff --git a/api/v1beta1/openstack_ansibleee_types.go b/api/v1beta1/openstack_ansibleee_types.go index 42ddfb82..f39bd2fd 100644 --- a/api/v1beta1/openstack_ansibleee_types.go +++ b/api/v1beta1/openstack_ansibleee_types.go @@ -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) diff --git a/controllers/openstack_ansibleee_controller.go b/controllers/openstack_ansibleee_controller.go index 916cc399..4209a52e 100644 --- a/controllers/openstack_ansibleee_controller.go +++ b/controllers/openstack_ansibleee_controller.go @@ -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) @@ -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 @@ -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 diff --git a/docs/assemblies/index.adoc b/docs/assemblies/index.adoc index 6e5ebfc0..68e20181 100644 --- a/docs/assemblies/index.adoc +++ b/docs/assemblies/index.adoc @@ -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. diff --git a/tests/functional/ansibleee_controller_test.go b/tests/functional/ansibleee_controller_test.go index 6cb72e40..b7b6bf78 100644 --- a/tests/functional/ansibleee_controller_test.go +++ b/tests/functional/ansibleee_controller_test.go @@ -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() { @@ -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, @@ -61,7 +60,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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, @@ -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, @@ -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, @@ -140,7 +139,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) ansibleee := GetAnsibleee(ansibleeeName) @@ -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")) @@ -177,7 +176,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) ansibleee = GetAnsibleee(ansibleeeName) @@ -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, @@ -218,7 +217,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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, @@ -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, @@ -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, @@ -349,7 +348,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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, @@ -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, @@ -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, @@ -497,7 +496,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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, @@ -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, @@ -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\"")), diff --git a/tests/kuttl/tests/run_failed_playbook/01-assert.yaml b/tests/kuttl/tests/run_failed_playbook/01-assert.yaml index fd2a8f17..dff4fb05 100644 --- a/tests/kuttl/tests/run_failed_playbook/01-assert.yaml +++ b/tests/kuttl/tests/run_failed_playbook/01-assert.yaml @@ -24,18 +24,18 @@ spec: status: JobStatus: Failed conditions: - - message: 'AnsibleExecutionJob error occurred Internal error occurred: Job has reached the specified backoff limit. + - message: 'Job error occurred 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 occurred Internal error occurred: Job has reached the specified backoff limit. + - message: 'Job error occurred 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