Skip to content

Commit 0df6789

Browse files
authored
Merge pull request #465 from replicatedhq/divolgin/analyzers
Jobs status analyzer
2 parents 9666679 + 1cdfd96 commit 0df6789

File tree

9 files changed

+1332
-571
lines changed

9 files changed

+1332
-571
lines changed

pkg/analyze/analyzer.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,20 @@ func Analyze(analyzer *troubleshootv1beta2.Analyze, getFile getCollectedFileCont
205205
}
206206
return results, nil
207207
}
208+
if analyzer.JobStatus != nil {
209+
isExcluded, err := isExcluded(analyzer.JobStatus.Exclude)
210+
if err != nil {
211+
return nil, err
212+
}
213+
if isExcluded {
214+
return nil, nil
215+
}
216+
results, err := analyzeJobStatus(analyzer.JobStatus, findFiles)
217+
if err != nil {
218+
return nil, err
219+
}
220+
return results, nil
221+
}
208222
if analyzer.ClusterPodStatuses != nil {
209223
isExcluded, err := isExcluded(analyzer.ClusterPodStatuses.Exclude)
210224
if err != nil {

pkg/analyze/data_test.go

Lines changed: 11 additions & 571 deletions
Large diffs are not rendered by default.

pkg/analyze/files/deployments.json

Lines changed: 452 additions & 0 deletions
Large diffs are not rendered by default.

pkg/analyze/files/jobs.json

Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
[
2+
{
3+
"metadata": {
4+
"name": "pre-install-job",
5+
"namespace": "test",
6+
"uid": "4545c8ba-0462-45a6-96c3-793a545dfcf6",
7+
"resourceVersion": "8303004",
8+
"creationTimestamp": "2021-10-05T19:11:43Z",
9+
"labels": {
10+
"kots.io/app-slug": "test",
11+
"kots.io/backup": "velero"
12+
},
13+
"annotations": {
14+
"helm.sh/hook": "pre-install",
15+
"helm.sh/hook-weight": "2",
16+
"kots.io/app-slug": "test",
17+
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"batch/v1\",\"kind\":\"Job\",\"metadata\":{\"annotations\":{\"helm.sh/hook\":\"pre-install\",\"helm.sh/hook-weight\":\"2\",\"kots.io/app-slug\":\"test\"},\"labels\":{\"kots.io/app-slug\":\"test\",\"kots.io/backup\":\"velero\"},\"name\":\"pre-install-job\",\"namespace\":\"test\"},\"spec\":{\"backoffLimit\":3,\"template\":{\"metadata\":{\"annotations\":{\"kots.io/app-slug\":\"test\"},\"labels\":{\"kots.io/app-slug\":\"test\",\"kots.io/backup\":\"velero\"},\"name\":\"security-test\"},\"spec\":{\"containers\":[{\"command\":[\"sh\",\"-c\",\"sleep 10\"],\"image\":\"alpine\",\"imagePullPolicy\":\"IfNotPresent\",\"name\":\"hook-test\"}],\"restartPolicy\":\"Never\"}}}}\n"
18+
},
19+
"managedFields": [
20+
{
21+
"manager": "kubectl-client-side-apply",
22+
"operation": "Update",
23+
"apiVersion": "batch/v1",
24+
"time": "2021-10-05T19:11:43Z",
25+
"fieldsType": "FieldsV1",
26+
"fieldsV1": {
27+
"f:metadata": {
28+
"f:annotations": {
29+
".": {},
30+
"f:helm.sh/hook": {},
31+
"f:helm.sh/hook-weight": {},
32+
"f:kots.io/app-slug": {},
33+
"f:kubectl.kubernetes.io/last-applied-configuration": {}
34+
},
35+
"f:labels": {
36+
".": {},
37+
"f:kots.io/app-slug": {},
38+
"f:kots.io/backup": {}
39+
}
40+
},
41+
"f:spec": {
42+
"f:backoffLimit": {},
43+
"f:completions": {},
44+
"f:parallelism": {},
45+
"f:template": {
46+
"f:metadata": {
47+
"f:annotations": {
48+
".": {},
49+
"f:kots.io/app-slug": {}
50+
},
51+
"f:labels": {
52+
".": {},
53+
"f:kots.io/app-slug": {},
54+
"f:kots.io/backup": {}
55+
},
56+
"f:name": {}
57+
},
58+
"f:spec": {
59+
"f:containers": {
60+
"k:{\"name\":\"hook-test\"}": {
61+
".": {},
62+
"f:command": {},
63+
"f:image": {},
64+
"f:imagePullPolicy": {},
65+
"f:name": {},
66+
"f:resources": {},
67+
"f:terminationMessagePath": {},
68+
"f:terminationMessagePolicy": {}
69+
}
70+
},
71+
"f:dnsPolicy": {},
72+
"f:restartPolicy": {},
73+
"f:schedulerName": {},
74+
"f:securityContext": {},
75+
"f:terminationGracePeriodSeconds": {}
76+
}
77+
}
78+
}
79+
}
80+
},
81+
{
82+
"manager": "k3s",
83+
"operation": "Update",
84+
"apiVersion": "batch/v1",
85+
"time": "2021-10-05T19:11:55Z",
86+
"fieldsType": "FieldsV1",
87+
"fieldsV1": {
88+
"f:status": {
89+
"f:completionTime": {},
90+
"f:conditions": {},
91+
"f:startTime": {},
92+
"f:succeeded": {}
93+
}
94+
}
95+
}
96+
]
97+
},
98+
"spec": {
99+
"parallelism": 1,
100+
"completions": 1,
101+
"backoffLimit": 3,
102+
"selector": {
103+
"matchLabels": {
104+
"controller-uid": "4545c8ba-0462-45a6-96c3-793a545dfcf6"
105+
}
106+
},
107+
"template": {
108+
"metadata": {
109+
"name": "security-test",
110+
"creationTimestamp": null,
111+
"labels": {
112+
"controller-uid": "4545c8ba-0462-45a6-96c3-793a545dfcf6",
113+
"job-name": "pre-install-job",
114+
"kots.io/app-slug": "test",
115+
"kots.io/backup": "velero"
116+
},
117+
"annotations": {
118+
"kots.io/app-slug": "test"
119+
}
120+
},
121+
"spec": {
122+
"containers": [
123+
{
124+
"name": "hook-test",
125+
"image": "alpine",
126+
"command": [
127+
"sh",
128+
"-c",
129+
"sleep 10"
130+
],
131+
"resources": {},
132+
"terminationMessagePath": "/dev/termination-log",
133+
"terminationMessagePolicy": "File",
134+
"imagePullPolicy": "IfNotPresent"
135+
}
136+
],
137+
"restartPolicy": "Never",
138+
"terminationGracePeriodSeconds": 30,
139+
"dnsPolicy": "ClusterFirst",
140+
"securityContext": {},
141+
"schedulerName": "default-scheduler"
142+
}
143+
}
144+
},
145+
"status": {
146+
"conditions": [
147+
{
148+
"type": "Complete",
149+
"status": "True",
150+
"lastProbeTime": "2021-10-05T19:11:55Z",
151+
"lastTransitionTime": "2021-10-05T19:11:55Z"
152+
}
153+
],
154+
"startTime": "2021-10-05T19:11:43Z",
155+
"completionTime": "2021-10-05T19:11:55Z",
156+
"succeeded": 1
157+
}
158+
},
159+
{
160+
"metadata": {
161+
"name": "post-install-job",
162+
"namespace": "test",
163+
"uid": "13844969-d21a-4514-8bed-66157f216af7",
164+
"resourceVersion": "8303007",
165+
"creationTimestamp": "2021-10-05T19:11:43Z",
166+
"labels": {
167+
"kots.io/app-slug": "test",
168+
"kots.io/backup": "velero"
169+
},
170+
"annotations": {
171+
"helm.sh/hook": "post-install",
172+
"helm.sh/hook-weight": "2",
173+
"kots.io/app-slug": "test",
174+
"kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"batch/v1\",\"kind\":\"Job\",\"metadata\":{\"annotations\":{\"helm.sh/hook\":\"post-install\",\"helm.sh/hook-weight\":\"2\",\"kots.io/app-slug\":\"test\"},\"labels\":{\"kots.io/app-slug\":\"test\",\"kots.io/backup\":\"velero\"},\"name\":\"post-install-job\",\"namespace\":\"test\"},\"spec\":{\"backoffLimit\":3,\"template\":{\"metadata\":{\"annotations\":{\"kots.io/app-slug\":\"test\"},\"labels\":{\"kots.io/app-slug\":\"test\",\"kots.io/backup\":\"velero\"},\"name\":\"security-test\"},\"spec\":{\"containers\":[{\"command\":[\"sh\",\"-c\",\"sleep 10\"],\"image\":\"alpine\",\"imagePullPolicy\":\"IfNotPresent\",\"name\":\"hook-test\"}],\"restartPolicy\":\"Never\"}}}}\n"
175+
},
176+
"managedFields": [
177+
{
178+
"manager": "kubectl-client-side-apply",
179+
"operation": "Update",
180+
"apiVersion": "batch/v1",
181+
"time": "2021-10-05T19:11:43Z",
182+
"fieldsType": "FieldsV1",
183+
"fieldsV1": {
184+
"f:metadata": {
185+
"f:annotations": {
186+
".": {},
187+
"f:helm.sh/hook": {},
188+
"f:helm.sh/hook-weight": {},
189+
"f:kots.io/app-slug": {},
190+
"f:kubectl.kubernetes.io/last-applied-configuration": {}
191+
},
192+
"f:labels": {
193+
".": {},
194+
"f:kots.io/app-slug": {},
195+
"f:kots.io/backup": {}
196+
}
197+
},
198+
"f:spec": {
199+
"f:backoffLimit": {},
200+
"f:completions": {},
201+
"f:parallelism": {},
202+
"f:template": {
203+
"f:metadata": {
204+
"f:annotations": {
205+
".": {},
206+
"f:kots.io/app-slug": {}
207+
},
208+
"f:labels": {
209+
".": {},
210+
"f:kots.io/app-slug": {},
211+
"f:kots.io/backup": {}
212+
},
213+
"f:name": {}
214+
},
215+
"f:spec": {
216+
"f:containers": {
217+
"k:{\"name\":\"hook-test\"}": {
218+
".": {},
219+
"f:command": {},
220+
"f:image": {},
221+
"f:imagePullPolicy": {},
222+
"f:name": {},
223+
"f:resources": {},
224+
"f:terminationMessagePath": {},
225+
"f:terminationMessagePolicy": {}
226+
}
227+
},
228+
"f:dnsPolicy": {},
229+
"f:restartPolicy": {},
230+
"f:schedulerName": {},
231+
"f:securityContext": {},
232+
"f:terminationGracePeriodSeconds": {}
233+
}
234+
}
235+
}
236+
}
237+
},
238+
{
239+
"manager": "k3s",
240+
"operation": "Update",
241+
"apiVersion": "batch/v1",
242+
"time": "2021-10-05T19:11:55Z",
243+
"fieldsType": "FieldsV1",
244+
"fieldsV1": {
245+
"f:status": {
246+
"f:completionTime": {},
247+
"f:conditions": {},
248+
"f:startTime": {},
249+
"f:succeeded": {}
250+
}
251+
}
252+
}
253+
]
254+
},
255+
"spec": {
256+
"parallelism": 1,
257+
"completions": 1,
258+
"backoffLimit": 3,
259+
"selector": {
260+
"matchLabels": {
261+
"controller-uid": "13844969-d21a-4514-8bed-66157f216af7"
262+
}
263+
},
264+
"template": {
265+
"metadata": {
266+
"name": "security-test",
267+
"creationTimestamp": null,
268+
"labels": {
269+
"controller-uid": "13844969-d21a-4514-8bed-66157f216af7",
270+
"job-name": "post-install-job",
271+
"kots.io/app-slug": "test",
272+
"kots.io/backup": "velero"
273+
},
274+
"annotations": {
275+
"kots.io/app-slug": "test"
276+
}
277+
},
278+
"spec": {
279+
"containers": [
280+
{
281+
"name": "hook-test",
282+
"image": "alpine",
283+
"command": [
284+
"sh",
285+
"-c",
286+
"sleep 10"
287+
],
288+
"resources": {},
289+
"terminationMessagePath": "/dev/termination-log",
290+
"terminationMessagePolicy": "File",
291+
"imagePullPolicy": "IfNotPresent"
292+
}
293+
],
294+
"restartPolicy": "Never",
295+
"terminationGracePeriodSeconds": 30,
296+
"dnsPolicy": "ClusterFirst",
297+
"securityContext": {},
298+
"schedulerName": "default-scheduler"
299+
}
300+
}
301+
},
302+
"status": {
303+
"conditions": [
304+
{
305+
"type": "Failed",
306+
"status": "True",
307+
"lastProbeTime": "2021-10-05T19:11:55Z",
308+
"lastTransitionTime": "2021-10-05T19:11:55Z",
309+
"message": "Job has reached the specified backoff limit",
310+
"reason": "BackoffLimitExceeded"
311+
}
312+
],
313+
"startTime": "2021-10-05T19:11:43Z",
314+
"completionTime": "2021-10-05T19:11:55Z",
315+
"failed": 1
316+
}
317+
}
318+
]

0 commit comments

Comments
 (0)