MCPcopy
hub / github.com/akuity/kargo / summarizeConditions

Function summarizeConditions

pkg/controller/stages/regular_stages.go:2156–2256  ·  view source on GitHub ↗

summarizeConditions summarizes the conditions of the given Stage. It sets the Ready condition based on the Promoting, Healthy, and Verified conditions. If there is an error, the Ready condition is set to False until the error is resolved.

(stage *kargoapi.Stage, newStatus *kargoapi.StageStatus, err error)

Source from the content-addressed store, hash-verified

2154// If there is an error, the Ready condition is set to False until the error is
2155// resolved.
2156func summarizeConditions(stage *kargoapi.Stage, newStatus *kargoapi.StageStatus, err error) {
2157 // If there is an error, then we are not Ready until the error is resolved.
2158 if err != nil {
2159 conditions.Set(newStatus, &metav1.Condition{
2160 Type: kargoapi.ConditionTypeReady,
2161 Status: metav1.ConditionFalse,
2162 Reason: "ReconcileError",
2163 Message: err.Error(),
2164 ObservedGeneration: stage.Generation,
2165 })
2166
2167 conditions.Set(newStatus, &metav1.Condition{
2168 Type: kargoapi.ConditionTypeReconciling,
2169 Status: metav1.ConditionTrue,
2170 Reason: "RetryAfterError",
2171 ObservedGeneration: stage.Generation,
2172 })
2173 return
2174 }
2175
2176 // Set the Freight summary.
2177 newStatus.FreightSummary = buildFreightSummary(len(stage.Spec.RequestedFreight), newStatus.FreightHistory.Current())
2178
2179 // If we are currently Promoting, then we are not Ready.
2180 promoCond := conditions.Get(newStatus, kargoapi.ConditionTypePromoting)
2181 if promoCond != nil {
2182 conditions.Set(newStatus, &metav1.Condition{
2183 Type: kargoapi.ConditionTypeReady,
2184 Status: metav1.ConditionFalse,
2185 Reason: promoCond.Reason,
2186 Message: promoCond.Message,
2187 ObservedGeneration: stage.Generation,
2188 })
2189 return
2190 }
2191
2192 // If we are not currently Promoting but the last promotion failed,
2193 // then we are not Ready.
2194 if lastPromo := newStatus.LastPromotion; lastPromo != nil && lastPromo.Status != nil &&
2195 lastPromo.Status.Phase.IsTerminal() && lastPromo.Status.Phase != kargoapi.PromotionPhaseSucceeded {
2196 conditions.Set(newStatus, &metav1.Condition{
2197 Type: kargoapi.ConditionTypeReady,
2198 Status: metav1.ConditionFalse,
2199 Reason: fmt.Sprintf("LastPromotion%s", string(lastPromo.Status.Phase)),
2200 Message: lastPromo.Status.Message,
2201 ObservedGeneration: stage.Generation,
2202 })
2203 return
2204 }
2205
2206 // If we are not Healthy, then we are not Ready.
2207 healthCond := conditions.Get(newStatus, kargoapi.ConditionTypeHealthy)
2208 if healthCond == nil || healthCond.Status != metav1.ConditionTrue {
2209 readyCond := &metav1.Condition{
2210 Type: kargoapi.ConditionTypeReady,
2211 Status: metav1.ConditionFalse,
2212 Reason: "Unhealthy",
2213 Message: "Stage is not healthy",

Callers 2

Test_summarizeConditionsFunction · 0.85
reconcileMethod · 0.85

Calls 7

SetFunction · 0.92
GetFunction · 0.92
DeleteFunction · 0.92
buildFreightSummaryFunction · 0.85
ErrorMethod · 0.45
CurrentMethod · 0.45
IsTerminalMethod · 0.45

Tested by 1

Test_summarizeConditionsFunction · 0.68