|
1 | 1 | hs = {}
|
2 | 2 |
|
3 | 3 | if obj.spec.suspend == true then
|
4 |
| - hs.status = "Suspended" |
| 4 | + -- Set to Healthy insted of Suspended until bug is resolved |
| 5 | + -- See https://github.com/argoproj/argo-cd/issues/24428 |
| 6 | + hs.status = "Healthy" |
5 | 7 | hs.message = "CronJob is Suspended"
|
6 | 8 | return hs
|
7 | 9 | end
|
8 | 10 |
|
9 | 11 | if obj.status ~= nil then
|
10 |
| - if obj.status.active ~= nil and table.getn(obj.status.active) > 0 then |
11 |
| - -- We could be Progressing very often, depending on the Cron schedule, which would bubble up |
12 |
| - -- to the Application health. If this is undesired, the annotation `argocd.argoproj.io/ignore-healthcheck: "true"` |
13 |
| - -- can be added on the CronJob. |
14 |
| - hs.status = "Progressing" |
15 |
| - hs.message = string.format("Waiting for %d Jobs to complete", table.getn(obj.status.active)) |
16 |
| - return hs |
17 |
| - end |
| 12 | + if obj.status.lastScheduleTime ~= nil then |
| 13 | + |
| 14 | + -- Job is running its first execution and has not yet reported any success |
| 15 | + if obj.status.lastSuccessfulTime == nil then |
| 16 | + -- Set to healthy even if it may be degraded, because we dont know |
| 17 | + -- if it was not yet executed or if it never succeeded |
| 18 | + hs.status = "Healthy" |
| 19 | + hs.message = "The Cronjob never completed succesfully. It may not be healthy" |
| 20 | + return hs |
| 21 | + end |
| 22 | + |
| 23 | + |
| 24 | + -- Job is progressing, so lastScheduleTime will always be grater than lastSuccessfulTime |
| 25 | + -- Set to healthy since we do not know if it is Degraded |
| 26 | + -- See https://github.com/argoproj/argo-cd/issues/24429 |
| 27 | + if obj.status.active ~= nil and table.getn(obj.status.active) > 0 then |
| 28 | + hs.status = "Healthy" |
| 29 | + hs.message = "The job is running. Its last execution may not have been successful" |
| 30 | + return hs |
| 31 | + end |
18 | 32 |
|
19 | 33 | -- If the CronJob has no active jobs and the lastSuccessfulTime < lastScheduleTime
|
20 | 34 | -- then we know it failed the last execution
|
21 |
| - if obj.status.lastScheduleTime ~= nil then |
22 |
| - -- No issue comparing time as text |
23 |
| - if obj.status.lastSuccessfulTime == nil or obj.status.lastSuccessfulTime < obj.status.lastScheduleTime then |
| 35 | + if obj.status.lastSuccessfulTime ~= nil and obj.status.lastSuccessfulTime < obj.status.lastScheduleTime then |
24 | 36 | hs.status = "Degraded"
|
25 | 37 | hs.message = "CronJob has not completed its last execution successfully"
|
26 | 38 | return hs
|
27 | 39 | end
|
| 40 | + |
28 | 41 | hs.message = "CronJob has completed its last execution successfully"
|
| 42 | + hs.status = "Healthy" |
| 43 | + return hs |
29 | 44 | end
|
30 | 45 |
|
31 | 46 | -- There is no way to know if as CronJob missed its execution based on status
|
32 | 47 | -- so we assume Healthy even if a cronJob is not getting scheduled.
|
33 | 48 | -- https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#job-creation
|
| 49 | + hs.message = "CronJob has not been scheduled yet" |
34 | 50 | hs.status = "Healthy"
|
35 | 51 | return hs
|
36 | 52 | end
|
|
0 commit comments