UpdateRuntimeCondition updates the runtime to include the provided condition. If the condition that we are about to add already exists and has the same status and reason then we are not going to update.
(conditions []data.RuntimeCondition, condition data.RuntimeCondition)
| 40 | // If the condition that we are about to add already exists |
| 41 | // and has the same status and reason then we are not going to update. |
| 42 | func UpdateRuntimeCondition(conditions []data.RuntimeCondition, condition data.RuntimeCondition) []data.RuntimeCondition { |
| 43 | // conditions = trimRuntimeConditions(conditions) |
| 44 | retConditions := slices.Clone(conditions) |
| 45 | |
| 46 | index, oldCondtion := GetRuntimeCondition(retConditions, condition.Type) |
| 47 | |
| 48 | if oldCondtion == nil { |
| 49 | retConditions = append(retConditions, condition) |
| 50 | return retConditions |
| 51 | } |
| 52 | |
| 53 | // We define two types of runtime condition: ready type conditions (e.g. WorkerReady) and action type conditions (e.g. WorkerScaledOut). |
| 54 | // For action type conditions that occur only once (e.g. WorkerInitialized), if condition exists, fluid will not update it. |
| 55 | if isOnceActionTypeCondition(condition) { |
| 56 | return retConditions |
| 57 | } |
| 58 | |
| 59 | // For ready type conditions, recording the earliest transition and probe time is enough and |
| 60 | // we avoiding update its probe time and transition time in every sync because it needs large amount of status updates. |
| 61 | if isReadyTypeCondition(condition) { |
| 62 | // keep old transition time and probe time if condition status is not changed |
| 63 | if condition.Status == oldCondtion.Status { |
| 64 | condition.LastTransitionTime = oldCondtion.LastTransitionTime |
| 65 | condition.LastProbeTime = oldCondtion.LastProbeTime |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | retConditions[index] = condition |
| 70 | return retConditions |
| 71 | } |
| 72 | |
| 73 | // GetRuntimeCondition gets a runtime condition given a runtime condition type. |
| 74 | // If found, return index of the founded condition in the condition array |
no test coverage detected