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

Commit 1003b1a

Browse files
Merge pull request #341 from fao89/ensurejob
Ensure job retries
2 parents bd54c1a + c160261 commit 1003b1a

File tree

3 files changed

+141
-2
lines changed

3 files changed

+141
-2
lines changed

controllers/openstack_ansibleee_controller.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package controllers
1919
import (
2020
"fmt"
2121
"regexp"
22+
"sort"
2223
"strings"
2324
"time"
2425

@@ -407,11 +408,16 @@ func (r *OpenStackAnsibleEEReconciler) jobForOpenStackAnsibleEE(ctx context.Cont
407408

408409
// if we have any extra vars for ansible to use set them in the RUNNER_EXTRA_VARS
409410
if len(instance.Spec.ExtraVars) > 0 {
411+
keys := make([]string, 0, len(instance.Spec.ExtraVars))
412+
for k := range instance.Spec.ExtraVars {
413+
keys = append(keys, k)
414+
}
415+
sort.Strings(keys)
410416
parsedExtraVars := ""
411417
// unmarshal nested data structures
412-
for variable, val := range instance.Spec.ExtraVars {
418+
for _, variable := range keys {
413419
var tmp interface{}
414-
err := yaml.Unmarshal(val, &tmp)
420+
err := yaml.Unmarshal(instance.Spec.ExtraVars[variable], &tmp)
415421
if err != nil {
416422
return nil, err
417423
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#
2+
# Check for:
3+
#
4+
# - 1 OpenStackAnsibleEE CR
5+
# - 1 failed-play pod
6+
# - 1 failed-play job
7+
# - Correct output from ansible play
8+
#
9+
apiVersion: ansibleee.openstack.org/v1beta1
10+
kind: OpenStackAnsibleEE
11+
metadata:
12+
name: failed-play
13+
spec:
14+
name: openstackansibleee
15+
play: |
16+
- name: Execution failure
17+
hosts: localhost
18+
tasks:
19+
- name: Copy absent file
20+
ansible.builtin.shell: |
21+
set -euxo pipefail
22+
cp absent failed_op
23+
preserveJobs: true
24+
status:
25+
JobStatus: Failed
26+
conditions:
27+
- message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed.
28+
Check job logs'
29+
reason: Error
30+
severity: Warning
31+
status: "False"
32+
type: Ready
33+
- message: 'AnsibleExecutionJob error occured Internal error occurred: Job Failed.
34+
Check job logs'
35+
reason: Error
36+
severity: Warning
37+
status: "False"
38+
type: AnsibleExecutionJobReady
39+
---
40+
apiVersion: v1
41+
kind: Pod
42+
metadata:
43+
generateName: failed-play-
44+
labels:
45+
app: openstackansibleee
46+
job-name: failed-play
47+
status:
48+
phase: Failed
49+
---
50+
apiVersion: batch/v1
51+
kind: Job
52+
metadata:
53+
labels:
54+
app: openstackansibleee
55+
job-name: failed-play
56+
openstackansibleee_cr: failed-play
57+
osaee: "true"
58+
name: failed-play
59+
spec:
60+
backoffLimit: 3
61+
completionMode: NonIndexed
62+
completions: 1
63+
parallelism: 1
64+
template:
65+
metadata:
66+
labels:
67+
app: openstackansibleee
68+
batch.kubernetes.io/job-name: failed-play
69+
job-name: failed-play
70+
openstackansibleee_cr: failed-play
71+
osaee: "true"
72+
spec:
73+
containers:
74+
- args:
75+
- ansible-runner
76+
- run
77+
- /runner
78+
- -p
79+
- playbook.yaml
80+
- -i
81+
- failed-play
82+
env:
83+
- name: RUNNER_PLAYBOOK
84+
value: |2+
85+
86+
- name: Execution failure
87+
hosts: localhost
88+
tasks:
89+
- name: Copy absent file
90+
ansible.builtin.shell: |
91+
set -euxo pipefail
92+
cp absent failed_op
93+
94+
95+
- name: RUNNER_EXTRA_VARS
96+
value: |2+
97+
98+
aaa: %!s(int=1)
99+
bbb: %!s(int=2)
100+
ccc: %!s(int=3)
101+
102+
103+
imagePullPolicy: Always
104+
name: openstackansibleee
105+
dnsPolicy: ClusterFirst
106+
restartPolicy: Never
107+
schedulerName: default-scheduler
108+
terminationGracePeriodSeconds: 30
109+
status:
110+
conditions:
111+
- message: Job has reached the specified backoff limit
112+
reason: BackoffLimitExceeded
113+
status: "True"
114+
type: Failed
115+
failed: 4
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: ansibleee.openstack.org/v1beta1
2+
kind: OpenStackAnsibleEE
3+
metadata:
4+
name: failed-play
5+
spec:
6+
play: |
7+
- name: Execution failure
8+
hosts: localhost
9+
tasks:
10+
- name: Copy absent file
11+
ansible.builtin.shell: |
12+
set -euxo pipefail
13+
cp absent failed_op
14+
extraVars:
15+
aaa: 1
16+
ccc: 3
17+
bbb: 2
18+
backoffLimit: 3

0 commit comments

Comments
 (0)