github.com/argoproj/argo-cd/v2@v2.10.9/resource_customizations/argoproj.io/Rollout/health.lua (about) 1 function checkReplicasStatus(obj) 2 local hs = {} 3 local desiredReplicas = getNumberValueOrDefault(obj.spec.replicas, 1) 4 statusReplicas = getNumberValueOrDefault(obj.status.replicas, 0) 5 updatedReplicas = getNumberValueOrDefault(obj.status.updatedReplicas, 0) 6 local 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 local 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 -- isWorkloadGenerationObserved determines if the referenced workload's generation spec has been 70 -- observed by the controller. This only applies to v1.1 rollout 71 function isWorkloadGenerationObserved(obj) 72 if obj.spec.workloadRef == nil or obj.metadata.annotations == nil then 73 -- rollout is v1.0 or earlier 74 return true 75 end 76 local workloadGen = tonumber(obj.metadata.annotations["rollout.argoproj.io/workload-generation"]) 77 local observedWorkloadGen = tonumber(obj.status.workloadObservedGeneration) 78 return workloadGen == observedWorkloadGen 79 end 80 81 local hs = {} 82 if not isGenerationObserved(obj) or not isWorkloadGenerationObserved(obj) then 83 hs.status = "Progressing" 84 hs.message = "Waiting for rollout spec update to be observed" 85 return hs 86 end 87 88 -- Argo Rollouts v1.0 has been improved to record a phase/message in status, which Argo CD can blindly surface 89 if obj.status.phase ~= nil then 90 if obj.status.phase == "Paused" then 91 -- Map Rollout's "Paused" status to Argo CD's "Suspended" 92 hs.status = "Suspended" 93 else 94 hs.status = obj.status.phase 95 end 96 hs.message = obj.status.message 97 return hs 98 end 99 100 for _, condition in ipairs(obj.status.conditions) do 101 if condition.type == "InvalidSpec" then 102 hs.status = "Degraded" 103 hs.message = condition.message 104 return hs 105 end 106 if condition.type == "Progressing" and condition.reason == "RolloutAborted" then 107 hs.status = "Degraded" 108 hs.message = condition.message 109 return hs 110 end 111 if condition.type == "Progressing" and condition.reason == "ProgressDeadlineExceeded" then 112 hs.status = "Degraded" 113 hs.message = condition.message 114 return hs 115 end 116 end 117 118 local isPaused = checkPaused(obj) 119 if isPaused ~= nil then 120 return isPaused 121 end 122 123 if obj.status.currentPodHash == nil then 124 hs.status = "Progressing" 125 hs.message = "Waiting for rollout to finish: status has not been reconciled." 126 return hs 127 end 128 129 replicasHS = checkReplicasStatus(obj) 130 if replicasHS ~= nil then 131 return replicasHS 132 end 133 134 135 local stableRS = getStableRS(obj) 136 137 if obj.spec.strategy.blueGreen ~= nil then 138 if obj.status.blueGreen == nil or obj.status.blueGreen.activeSelector ~= obj.status.currentPodHash then 139 hs.status = "Progressing" 140 hs.message = "active service cutover pending" 141 return hs 142 end 143 -- Starting in v0.8 blue-green uses status.stableRS. To drop support for v0.7, uncomment following 144 -- if stableRS == "" or stableRS ~= obj.status.currentPodHash then 145 if stableRS ~= "" and stableRS ~= obj.status.currentPodHash then 146 hs.status = "Progressing" 147 hs.message = "waiting for analysis to complete" 148 return hs 149 end 150 elseif obj.spec.strategy.canary ~= nil then 151 if statusReplicas > updatedReplicas then 152 hs.status = "Progressing" 153 hs.message = "Waiting for roll out to finish: old replicas are pending termination" 154 return hs 155 end 156 if stableRS == "" or stableRS ~= obj.status.currentPodHash then 157 hs.status = "Progressing" 158 hs.message = "Waiting for rollout to finish steps" 159 return hs 160 end 161 end 162 163 hs.status = "Healthy" 164 hs.message = "" 165 return hs