mirror of
https://github.com/argoproj/argo-cd
synced 2026-04-21 17:07:16 +00:00
fix(health): use note.drySha when available (#26698)
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
This commit is contained in:
parent
6740282c3a
commit
6eea558023
3 changed files with 52 additions and 6 deletions
|
|
@ -56,6 +56,17 @@ if not obj.status.environments or #obj.status.environments == 0 then
|
|||
return hs
|
||||
end
|
||||
|
||||
-- Use note.drySha as canonical proposed SHA when present; fallback to proposed.dry.sha.
|
||||
local function getProposedDrySha(env)
|
||||
if env and env.proposed and env.proposed.note and env.proposed.note.drySha and env.proposed.note.drySha ~= "" then
|
||||
return env.proposed.note.drySha
|
||||
end
|
||||
if env and env.proposed and env.proposed.dry and env.proposed.dry.sha and env.proposed.dry.sha ~= "" then
|
||||
return env.proposed.dry.sha
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Make sure there's a fully-populated status for both active and proposed commits in all environments. If anything is
|
||||
-- missing or empty, return a Progressing status.
|
||||
for _, env in ipairs(obj.status.environments) do
|
||||
|
|
@ -64,7 +75,7 @@ for _, env in ipairs(obj.status.environments) do
|
|||
hs.message = "The active commit DRY SHA is missing or empty in environment '" .. env.branch .. "'."
|
||||
return hs
|
||||
end
|
||||
if not env.proposed or not env.proposed.dry or not env.proposed.dry.sha or env.proposed.dry.sha == "" then
|
||||
if not getProposedDrySha(env) then
|
||||
hs.status = "Progressing"
|
||||
hs.message = "The proposed commit DRY SHA is missing or empty in environment '" .. env.branch .. "'."
|
||||
return hs
|
||||
|
|
@ -72,9 +83,9 @@ for _, env in ipairs(obj.status.environments) do
|
|||
end
|
||||
|
||||
-- Check if all the proposed environments have the same proposed commit dry sha. If not, return a Progressing status.
|
||||
local proposedSha = obj.status.environments[1].proposed.dry.sha -- Don't panic, Lua is 1-indexed.
|
||||
local proposedSha = getProposedDrySha(obj.status.environments[1]) -- Don't panic, Lua is 1-indexed.
|
||||
for _, env in ipairs(obj.status.environments) do
|
||||
if env.proposed.dry.sha ~= proposedSha then
|
||||
if getProposedDrySha(env) ~= proposedSha then
|
||||
hs.status = "Progressing"
|
||||
hs.message = "Not all environments have the same proposed commit SHA. This likely means the hydrator has not run for all environments yet."
|
||||
return hs
|
||||
|
|
@ -96,7 +107,8 @@ end
|
|||
-- statuses and build a summary about how many are pending, successful, or failed. Return a Progressing status for this
|
||||
-- in-progress environment.
|
||||
for _, env in ipairs(obj.status.environments) do
|
||||
if env.proposed.dry.sha ~= env.active.dry.sha then
|
||||
local envProposedSha = getProposedDrySha(env)
|
||||
if envProposedSha ~= env.active.dry.sha then
|
||||
local pendingCount = 0
|
||||
local successCount = 0
|
||||
local failureCount = 0
|
||||
|
|
@ -121,7 +133,7 @@ for _, env in ipairs(obj.status.environments) do
|
|||
hs.message =
|
||||
"Promotion in progress for environment '" .. env.branch ..
|
||||
"' from '" .. getShortSha(env.active.dry.sha) ..
|
||||
"' to '" .. getShortSha(env.proposed.dry.sha) .. "': " ..
|
||||
"' to '" .. getShortSha(envProposedSha) .. "': " ..
|
||||
pendingCount .. " pending, " .. successCount .. " successful, " .. failureCount .. " failed. "
|
||||
|
||||
if pendingCount > 0 then
|
||||
|
|
@ -172,5 +184,5 @@ end
|
|||
-- If all environments have the same proposed commit dry sha as the active one, we can consider the promotion strategy
|
||||
-- healthy. This means all environments are in sync and no further action is needed.
|
||||
hs.status = "Healthy"
|
||||
hs.message = "All environments are up-to-date on commit '" .. getShortSha(obj.status.environments[1].proposed.dry.sha) .. "'."
|
||||
hs.message = "All environments are up-to-date on commit '" .. getShortSha(getProposedDrySha(obj.status.environments[1])) .. "'."
|
||||
return hs
|
||||
|
|
|
|||
|
|
@ -47,3 +47,7 @@ tests:
|
|||
status: Degraded
|
||||
message: "Promotion strategy reconciliation failed (ChangeTransferPolicyNotReady): ChangeTransferPolicy \"strategy-environments-qal-usw2-27894e05\" is not Ready because \"ReconciliationError\": Reconciliation failed: failed to calculate ChangeTransferPolicy status: failed to get SHAs for proposed branch \"environments/qal-usw2-next\": exit status 128: fatal: 'origin/environments/qal-usw2-next' is not a commit and a branch 'environments/qal-usw2-next' cannot be created from it"
|
||||
inputPath: testdata/missing-sha-and-not-ready.yaml
|
||||
- healthStatus:
|
||||
status: Progressing
|
||||
message: "Promotion in progress for environment 'dev' from 'abc1234' to 'new9999': 0 pending, 0 successful, 0 failed. "
|
||||
inputPath: testdata/proposed-note-dry-sha-preferred.yaml
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
apiVersion: promoter.argoproj.io/v1alpha1
|
||||
kind: PromotionStrategy
|
||||
metadata:
|
||||
generation: 1
|
||||
spec: {}
|
||||
status:
|
||||
conditions:
|
||||
- type: Ready
|
||||
status: "True"
|
||||
observedGeneration: 1
|
||||
environments:
|
||||
- branch: dev
|
||||
active:
|
||||
dry:
|
||||
sha: abc1234abcdef0
|
||||
proposed:
|
||||
dry:
|
||||
sha: old1111abcdef0
|
||||
note:
|
||||
drySha: new9999abcdef0
|
||||
- branch: prod
|
||||
active:
|
||||
dry:
|
||||
sha: abc1234abcdef0
|
||||
proposed:
|
||||
dry:
|
||||
sha: old2222abcdef0
|
||||
note:
|
||||
drySha: new9999abcdef0
|
||||
|
||||
Loading…
Reference in a new issue