From 3bb0a8b8d26b570f4128ba318ba3d4571eaf0a2f Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Tue, 7 May 2024 14:02:09 +0100 Subject: [PATCH] Use conditions from lib-common Signed-off-by: Fabricio Aguiar --- api/v1beta1/conditions.go | 47 ------------------- api/v1beta1/openstack_ansibleee_types.go | 2 +- controllers/openstack_ansibleee_controller.go | 12 ++--- tests/functional/ansibleee_controller_test.go | 43 +++++++++-------- .../tests/run_failed_playbook/01-assert.yaml | 6 +-- 5 files changed, 31 insertions(+), 79 deletions(-) delete mode 100644 api/v1beta1/conditions.go diff --git a/api/v1beta1/conditions.go b/api/v1beta1/conditions.go deleted file mode 100644 index 7b7bcd90..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 occured %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..0fa7b2c7 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,20 @@ 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 { instance.Status.Conditions.Set(condition.FalseCondition( - ansibleeev1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, condition.ErrorReason, condition.SeverityWarning, - ansibleeev1.AnsibleExecutionJobErrorMessage, + condition.JobReadyErrorMessage, err.Error())) instance.Status.JobStatus = ansibleeev1.JobStatusFailed return ctrl.Result{}, err @@ -232,7 +232,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/tests/functional/ansibleee_controller_test.go b/tests/functional/ansibleee_controller_test.go index 007d2485..7f60b2d2 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,7 +39,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectConditionWithDetails( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionFalse, condition.RequestedReason, "AnsibleExecutionJob is running", @@ -61,7 +60,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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", @@ -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", @@ -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", @@ -140,7 +139,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) ansibleee := GetAnsibleee(ansibleeeName) @@ -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", @@ -177,7 +176,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) ansibleee = GetAnsibleee(ansibleeeName) @@ -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", @@ -218,7 +217,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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", @@ -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", @@ -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", @@ -349,7 +348,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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", @@ -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", @@ -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", @@ -497,7 +496,7 @@ var _ = Describe("Ansibleee controller", func() { th.ExpectCondition( ansibleeeName, ConditionGetterFunc(AnsibleeeConditionGetter), - v1beta1.AnsibleExecutionJobReadyCondition, + condition.JobReadyCondition, corev1.ConditionTrue, ) th.ExpectCondition( @@ -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", @@ -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", @@ -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", diff --git a/tests/kuttl/tests/run_failed_playbook/01-assert.yaml b/tests/kuttl/tests/run_failed_playbook/01-assert.yaml index 2d2ba129..80894b87 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 occured Internal error occurred: Job Failed. + - message: 'Job error occured Internal error occurred: Job Failed. Check job logs' reason: Error severity: Warning status: "False" type: Ready - - message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed. + - message: 'Job error occured Internal error occurred: Job Failed. Check job logs' reason: Error severity: Warning status: "False" - type: AnsibleExecutionJobReady + type: JobReady --- apiVersion: v1 kind: Pod