github.com/argoproj/argo-cd/v3@v3.2.1/resource_customizations/promoter.argoproj.io/ChangeTransferPolicy/health.lua (about) 1 local hs = {} 2 hs.status = "Progressing" 3 hs.message = "Initializing change transfer policy" 4 5 -- Check for deletion timestamp 6 if obj.metadata.deletionTimestamp then 7 hs.status = "Progressing" 8 hs.message = "Change transfer policy is being deleted" 9 return hs 10 end 11 12 -- Check if status exists 13 if not obj.status then 14 return hs 15 end 16 17 -- Check for reconciliation conditions 18 local hasReadyCondition = false 19 if obj.status.conditions then 20 for _, condition in ipairs(obj.status.conditions) do 21 if condition.type == "Ready" then 22 hasReadyCondition = true 23 -- Check observedGeneration vs metadata.generation within the reconciliation condition 24 if condition.observedGeneration and obj.metadata.generation and condition.observedGeneration ~= obj.metadata.generation then 25 hs.status = "Progressing" 26 hs.message = "Waiting for change transfer policy spec update to be observed" 27 return hs 28 end 29 -- Check for any False condition status 30 if condition.status == "False" then 31 hs.status = "Degraded" 32 local msg = condition.message or "Unknown error" 33 local reason = condition.reason or "Unknown" 34 -- Don't include ReconciliationError in the message since it's redundant 35 if reason == "ReconciliationError" then 36 hs.message = "Change transfer policy reconciliation failed: " .. msg 37 else 38 hs.message = "Change transfer policy reconciliation failed (" .. reason .. "): " .. msg 39 end 40 return hs 41 end 42 end 43 end 44 end 45 if not hasReadyCondition then 46 hs.status = "Progressing" 47 hs.message = "Change transfer policy is not ready yet" 48 return hs 49 end 50 51 if not obj.status.active or not obj.status.active.dry or not obj.status.active.dry.sha or obj.status.active.dry.sha == "" then 52 hs.status = "Progressing" 53 hs.message = "The active commit DRY SHA is missing or empty." 54 return hs 55 end 56 if not obj.status.proposed or not obj.status.proposed.dry or not obj.status.proposed.dry.sha or obj.status.proposed.dry.sha == "" then 57 hs.status = "Progressing" 58 hs.message = "The proposed commit DRY SHA is missing or empty." 59 return hs 60 end 61 62 -- Helper function to get short SHA 63 local function getShortSha(sha) 64 if not sha or sha == "" then 65 return "" 66 end 67 if string.len(sha) > 7 then 68 return string.sub(sha, 1, 7) 69 end 70 return sha 71 end 72 73 if obj.status.proposed.dry.sha ~= obj.status.active.dry.sha then 74 local pendingCount = 0 75 local successCount = 0 76 local failureCount = 0 77 local pendingKeys = {} 78 local failedKeys = {} 79 80 for _, status in ipairs(obj.status.proposed.commitStatuses or {}) do 81 if status.phase == "pending" then 82 pendingCount = pendingCount + 1 83 table.insert(pendingKeys, status.key) 84 elseif status.phase == "success" then 85 successCount = successCount + 1 86 elseif status.phase == "failure" then 87 failureCount = failureCount + 1 88 table.insert(failedKeys, status.key) 89 end 90 end 91 92 hs.status = "Progressing" 93 hs.message = 94 "Promotion in progress from '" .. getShortSha(obj.status.active.dry.sha) .. 95 "' to '" .. getShortSha(obj.status.proposed.dry.sha) .. "': " .. 96 pendingCount .. " pending, " .. successCount .. " successful, " .. failureCount .. " failed. " 97 98 if pendingCount > 0 then 99 hs.message = hs.message .. "Pending commit statuses: " .. table.concat(pendingKeys, ", ") .. ". " 100 end 101 if failureCount > 0 then 102 hs.message = hs.message .. "Failed commit statuses: " .. table.concat(failedKeys, ", ") .. ". " 103 end 104 return hs 105 end 106 107 local pendingCount = 0 108 local failureCount = 0 109 local successCount = 0 110 local pendingKeys = {} 111 local failedKeys = {} 112 for _, status in ipairs(obj.status.active.commitStatuses or {}) do 113 if status.phase == "pending" then 114 pendingCount = pendingCount + 1 115 table.insert(pendingKeys, status.key) 116 elseif status.phase == "success" then 117 successCount = successCount + 1 118 elseif status.phase == "failure" then 119 failureCount = failureCount + 1 120 table.insert(failedKeys, status.key) 121 end 122 end 123 if pendingCount > 0 or failureCount > 0 then 124 hs.status = "Healthy" 125 hs.message = "Environment is up-to-date, but there are non-successful active commit statuses: " .. pendingCount .. " pending, " .. successCount .. " successful, " .. failureCount .. " failed. " 126 if pendingCount > 0 then 127 hs.message = hs.message .. "Pending commit statuses: " .. table.concat(pendingKeys, ", ") .. ". " 128 end 129 if failureCount > 0 then 130 hs.message = hs.message .. "Failed commit statuses: " .. table.concat(failedKeys, ", ") .. ". " 131 end 132 return hs 133 end 134 135 hs.status = "Healthy" 136 hs.message = "Environment is up-to-date on commit " .. getShortSha(obj.status.active.dry.sha) .. "." 137 return hs