Skip to content

Commit

Permalink
Use conditions from lib-common
Browse files Browse the repository at this point in the history
Signed-off-by: Fabricio Aguiar <[email protected]>
  • Loading branch information
fao89 committed May 7, 2024
1 parent d464430 commit 3bb0a8b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 79 deletions.
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
12 changes: 6 additions & 6 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,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
Expand All @@ -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
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
6 changes: 3 additions & 3 deletions tests/kuttl/tests/run_failed_playbook/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bb0a8b

Please sign in to comment.