|
| 1 | +-- Health check copied from here: https://github.com/crossplane/docs/blob/bd701357e9d5eecf529a0b42f23a78850a6d1d87/content/master/guides/crossplane-with-argo-cd.md |
| 2 | + |
| 3 | +health_status = { |
| 4 | + status = "Progressing", |
| 5 | + message = "Provisioning ..." |
| 6 | +} |
| 7 | + |
| 8 | +local function contains (table, val) |
| 9 | + for i, v in ipairs(table) do |
| 10 | + if v == val then |
| 11 | + return true |
| 12 | + end |
| 13 | + end |
| 14 | + return false |
| 15 | +end |
| 16 | + |
| 17 | +local has_no_status = { |
| 18 | + "Composition", |
| 19 | + "CompositionRevision", |
| 20 | + "DeploymentRuntimeConfig", |
| 21 | + "ControllerConfig", |
| 22 | + "ProviderConfig", |
| 23 | + "ProviderConfigUsage" |
| 24 | +} |
| 25 | +if obj.status == nil or next(obj.status) == nil and contains(has_no_status, obj.kind) then |
| 26 | + health_status.status = "Healthy" |
| 27 | + health_status.message = "Resource is up-to-date." |
| 28 | + return health_status |
| 29 | +end |
| 30 | + |
| 31 | +if obj.status == nil or next(obj.status) == nil or obj.status.conditions == nil then |
| 32 | + if obj.kind == "ProviderConfig" and obj.status.users ~= nil then |
| 33 | + health_status.status = "Healthy" |
| 34 | + health_status.message = "Resource is in use." |
| 35 | + return health_status |
| 36 | + end |
| 37 | + return health_status |
| 38 | +end |
| 39 | + |
| 40 | +for i, condition in ipairs(obj.status.conditions) do |
| 41 | + if condition.type == "LastAsyncOperation" then |
| 42 | + if condition.status == "False" then |
| 43 | + health_status.status = "Degraded" |
| 44 | + health_status.message = condition.message |
| 45 | + return health_status |
| 46 | + end |
| 47 | + end |
| 48 | + |
| 49 | + if condition.type == "Synced" then |
| 50 | + if condition.status == "False" then |
| 51 | + health_status.status = "Degraded" |
| 52 | + health_status.message = condition.message |
| 53 | + return health_status |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + if contains({"Ready", "Healthy", "Offered", "Established"}, condition.type) then |
| 58 | + if condition.status == "True" then |
| 59 | + health_status.status = "Healthy" |
| 60 | + health_status.message = "Resource is up-to-date." |
| 61 | + return health_status |
| 62 | + end |
| 63 | + end |
| 64 | +end |
| 65 | + |
| 66 | +return health_status |
0 commit comments