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 23, 2024
1 parent f9f5ecd commit c6e11d8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 96 deletions.
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
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
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
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 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
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
status: "False"
type: AnsibleExecutionJobReady
type: JobReady
---
apiVersion: v1
kind: Pod
Expand Down

0 comments on commit c6e11d8

Please sign in to comment.