github.com/argoproj/argo-cd@v1.8.7/resource_customizations/argoproj.io/Rollout/health.lua (about) 1 function checkReplicasStatus(obj) 2 hs = {} 3 desiredReplicas = getNumberValueOrDefault(obj.spec.replicas, 1) 4 statusReplicas = getNumberValueOrDefault(obj.status.replicas, 0) 5 updatedReplicas = getNumberValueOrDefault(obj.status.updatedReplicas, 0) 6 availableReplicas = getNumberValueOrDefault(obj.status.availableReplicas, 0) 7 8 if updatedReplicas < desiredReplicas then 9 hs.status = "Progressing" 10 hs.message = "Waiting for roll out to finish: More replicas need to be updated" 11 return hs 12 end 13 if availableReplicas < updatedReplicas then 14 hs.status = "Progressing" 15 hs.message = "Waiting for roll out to finish: updated replicas are still becoming available" 16 return hs 17 end 18 return nil 19 end 20 21 -- In Argo Rollouts v0.8 we deprecated .status.canary.stableRS for .status.stableRS 22 -- This func grabs the correct one. 23 function getStableRS(obj) 24 if obj.status.stableRS ~= nil then 25 return obj.status.stableRS 26 end 27 if obj.status.canary ~= nil then 28 return obj.status.canary.stableRS 29 end 30 return "" 31 end 32 33 function getNumberValueOrDefault(field, default) 34 if field ~= nil then 35 return field 36 end 37 return default 38 end 39 40 function checkPaused(obj) 41 hs = {} 42 hs.status = "Suspended" 43 hs.message = "Rollout is paused" 44 if obj.status.pauseConditions ~= nil and table.getn(obj.status.pauseConditions) > 0 then 45 return hs 46 end 47 48 if obj.spec.paused ~= nil and obj.spec.paused then 49 return hs 50 end 51 return nil 52 end 53 54 -- isGenerationObserved determines if the rollout spec has been observed by the controller. This 55 -- only applies to v0.10 rollout which uses a numeric status.observedGeneration. For v0.9 rollouts 56 -- and below this function always returns true. 57 function isGenerationObserved(obj) 58 if obj.status == nil then 59 return false 60 end 61 observedGeneration = tonumber(obj.status.observedGeneration) 62 if observedGeneration == nil or observedGeneration > obj.metadata.generation then 63 -- if we get here, the rollout is a v0.9 rollout 64 return true 65 end 66 return observedGeneration == obj.metadata.generation 67 end 68 69 hs = {} 70 if not isGenerationObserved(obj) then 71 hs.status = "Progressing" 72 hs.message = "Waiting for rollout spec update to be observed" 73 return hs 74 end 75 76 for _, condition in ipairs(obj.status.conditions) do 77 if condition.type == "InvalidSpec" then 78 hs.status = "Degraded" 79 hs.message = condition.message 80 return hs 81 end 82 if condition.type == "Progressing" and condition.reason == "RolloutAborted" then 83 hs.status = "Degraded" 84 hs.message = condition.message 85 return hs 86 end 87 if condition.type == "Progressing" and condition.reason == "ProgressDeadlineExceeded" then 88 hs.status = "Degraded" 89 hs.message = condition.message 90 return hs 91 end 92 end 93 94 isPaused = checkPaused(obj) 95 if isPaused ~= nil then 96 return isPaused 97 end 98 99 if obj.status.currentPodHash == nil then 100 hs.status = "Progressing" 101 hs.message = "Waiting for rollout to finish: status has not been reconciled." 102 return hs 103 end 104 105 replicasHS = checkReplicasStatus(obj) 106 if replicasHS ~= nil then 107 return replicasHS 108 end 109 110 111 stableRS = getStableRS(obj) 112 113 if obj.spec.strategy.blueGreen ~= nil then 114 if obj.status.blueGreen == nil or obj.status.blueGreen.activeSelector ~= obj.status.currentPodHash then 115 hs.status = "Progressing" 116 hs.message = "active service cutover pending" 117 return hs 118 end 119 -- Starting in v0.8 blue-green uses status.stableRS. To drop support for v0.7, uncomment following 120 -- if stableRS == "" or stableRS ~= obj.status.currentPodHash then 121 if stableRS ~= "" and stableRS ~= obj.status.currentPodHash then 122 hs.status = "Progressing" 123 hs.message = "waiting for analysis to complete" 124 return hs 125 end 126 elseif obj.spec.strategy.canary ~= nil then 127 if statusReplicas > updatedReplicas then 128 hs.status = "Progressing" 129 hs.message = "Waiting for roll out to finish: old replicas are pending termination" 130 return hs 131 end 132 if stableRS == "" or stableRS ~= obj.status.currentPodHash then 133 hs.status = "Progressing" 134 hs.message = "Waiting for rollout to finish steps" 135 return hs 136 end 137 end 138 139 hs.status = "Healthy" 140 hs.message = "" 141 return hs