Skip to content
This repository has been archived by the owner on Nov 28, 2024. It is now read-only.

Commit

Permalink
Add JobGeneration
Browse files Browse the repository at this point in the history
For tracking when jobs are recreated

Signed-off-by: Fabricio Aguiar <[email protected]>
  • Loading branch information
fao89 committed Apr 2, 2024
1 parent 1003b1a commit c415f3c
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 0 deletions.
4 changes: 4 additions & 0 deletions api/bases/ansibleee.openstack.org_openstackansibleees.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,10 @@ spec:
type: object
status:
properties:
JobGeneration:
default: 1
format: int64
type: integer
JobStatus:
default: Pending
enum:
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/openstack_ansibleee_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ type OpenStackAnsibleEEStatus struct {
// +kubebuilder:default:=Pending
// JobStatus status of the executed job (Pending/Running/Succeeded/Failed)
JobStatus string `json:"JobStatus,omitempty" optional:"true"`

// +kubebuilder:default:=1
// JobGeneration track the amount of job generations
JobGeneration int64 `json:"JobGeneration,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,10 @@ spec:
type: object
status:
properties:
JobGeneration:
default: 1
format: int64
type: integer
JobStatus:
default: Pending
enum:
Expand Down
4 changes: 4 additions & 0 deletions controllers/openstack_ansibleee_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ func (r *OpenStackAnsibleEEReconciler) Reconcile(ctx context.Context, req ctrl.R
currentJobHash,
)

if len(currentJobHash) > 0 && ansibleeeJob.HasChanged() {
instance.Status.JobGeneration++
}

ctrlResult, err := ansibleeeJob.DoJob(
ctx,
helper,
Expand Down
5 changes: 5 additions & 0 deletions docs/assemblies/openstack_ansibleee.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ OpenStackAnsibleEEStatus defines the observed state of OpenStackAnsibleEE
| JobStatus status of the executed job (Pending/Running/Succeeded/Failed)
| string
| false
| JobGeneration
| JobGeneration track the amount of job generations
| int64
| false
|===
<<custom-resources,Back to Custom Resources>>
19 changes: 19 additions & 0 deletions tests/functional/ansibleee_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -72,6 +73,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Succeeded"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).To(HaveKey("ansibleee"))
})
Expand All @@ -93,6 +95,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -115,6 +118,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Failed"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))
})
Expand Down Expand Up @@ -145,6 +149,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Succeeded"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
originalInputHash := ansibleee.Status.Hash["input"]
Expect(ansibleee.Status.Hash).To(HaveKey("ansibleee"))
Expand All @@ -170,6 +175,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))

// simulate that the second job succeeds
th.SimulateJobSuccess(ansibleeeName)
Expand All @@ -182,6 +188,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Succeeded"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash["input"]).NotTo(Equal(originalInputHash))
Expect(ansibleee.Status.Hash["ansibleee"]).NotTo(Equal(originalJobHash))
})
Expand Down Expand Up @@ -227,6 +234,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -246,6 +254,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Succeeded"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).To(HaveKey("ansibleee"))
})
Expand All @@ -267,6 +276,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -289,6 +299,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Failed"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))
})
Expand Down Expand Up @@ -358,6 +369,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -377,6 +389,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Succeeded"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).To(HaveKey("ansibleee"))
})
Expand All @@ -398,6 +411,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -420,6 +434,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Failed"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))
})
Expand Down Expand Up @@ -506,6 +521,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -525,6 +541,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Succeeded"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).To(HaveKey("ansibleee"))
})
Expand All @@ -546,6 +563,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee := GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Running"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))

Expand All @@ -568,6 +586,7 @@ var _ = Describe("Ansibleee controller", func() {
)
ansibleee = GetAnsibleee(ansibleeeName)
Expect(ansibleee.Status.JobStatus).To(Equal("Failed"))
Expect(ansibleee.Status.JobGeneration).To(Equal(int64(1)))
Expect(ansibleee.Status.Hash).To(HaveKey("input"))
Expect(ansibleee.Status.Hash).NotTo(HaveKey("ansibleee"))
})
Expand Down
1 change: 1 addition & 0 deletions tests/kuttl/tests/run_failed_playbook/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spec:
preserveJobs: true
status:
JobStatus: Failed
JobGeneration: 4
conditions:
- message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed.
Check job logs'
Expand Down
1 change: 1 addition & 0 deletions tests/kuttl/tests/run_simple_playbook/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ spec:
msg: "Hello, world this is ansibleee-play.yaml"
status:
JobStatus: Succeeded
JobGeneration: 1
---
apiVersion: v1
kind: Pod
Expand Down
1 change: 1 addition & 0 deletions tests/kuttl/tests/run_simple_playbook_debug/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ spec:
msg: "Hello, world this is ansibleee-play-debug.yaml"
status:
JobStatus: Running
JobGeneration: 1
---
apiVersion: v1
kind: Pod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ spec:
msg: "Hello, world this is ansibleee-play-debug.yaml"
status:
JobStatus: Running
JobGeneration: 1
---
apiVersion: v1
kind: Pod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
why: "because"
status:
JobStatus: Succeeded
JobGeneration: 1
---
apiVersion: v1
kind: Pod
Expand Down

0 comments on commit c415f3c

Please sign in to comment.