github.com/argoproj/argo-cd/v3@v3.2.1/resource_customizations/policy.open-cluster-management.io/Policy/health.lua (about) 1 hs = {} 2 if obj.spec.disabled then 3 hs.status = "Healthy" 4 hs.message = "Policy is disabled" 5 return hs 6 end 7 8 if obj.status == nil then 9 hs.status = "Progressing" 10 hs.message = "Waiting for the status to be reported" 11 return hs 12 end 13 14 -- A policy will not have a compliant field but will have a placement key set if 15 -- it is not being applied to any clusters 16 if obj.status.compliant == nil and obj.status.status == nil and obj.status.placement ~= nil and #obj.status.placement > 0 then 17 hs.status = "Healthy" 18 hs.message = "No clusters match this policy" 19 return hs 20 end 21 22 if obj.status.compliant == nil then 23 hs.status = "Progressing" 24 hs.message = "Waiting for the status to be reported" 25 return hs 26 end 27 28 if obj.status.compliant == "Compliant" then 29 hs.status = "Healthy" 30 else 31 hs.status = "Degraded" 32 end 33 34 -- Collect NonCompliant clusters for the policy 35 noncompliants = {} 36 if obj.status.status ~= nil then 37 -- "root" policy 38 for i, entry in ipairs(obj.status.status) do 39 if entry.compliant ~= "Compliant" then 40 table.insert(noncompliants, entry.clustername) 41 end 42 end 43 if #noncompliants == 0 then 44 hs.message = "All clusters are compliant" 45 else 46 hs.message = "NonCompliant clusters: " .. table.concat(noncompliants, ", ") 47 end 48 elseif obj.status.details ~= nil then 49 -- "replicated" policy 50 for i, entry in ipairs(obj.status.details) do 51 if entry.compliant ~= "Compliant" then 52 table.insert(noncompliants, entry.templateMeta.name) 53 end 54 end 55 if #noncompliants == 0 then 56 hs.message = "All templates are compliant" 57 else 58 hs.message = "NonCompliant templates: " .. table.concat(noncompliants, ", ") 59 end 60 end 61 62 return hs