CalculateState computes the current state of prebuilds for a preset, including: - Actual: Number of currently running prebuilds, i.e., non-expired and expired prebuilds - Expired: Number of currently running expired prebuilds - Desired: Number of prebuilds desired as defined in the preset - Eligible
()
| 263 | // in-progress transitions. This state information is used to determine what reconciliation |
| 264 | // actions are needed to reach the desired state. |
| 265 | func (p PresetSnapshot) CalculateState() *ReconciliationState { |
| 266 | var ( |
| 267 | actual int32 |
| 268 | desired int32 |
| 269 | expired int32 |
| 270 | eligible int32 |
| 271 | extraneous int32 |
| 272 | ) |
| 273 | |
| 274 | // #nosec G115 - Safe conversion as p.Running and p.Expired slice length is expected to be within int32 range |
| 275 | actual = int32(len(p.Running) + len(p.Expired)) |
| 276 | |
| 277 | // #nosec G115 - Safe conversion as p.Expired slice length is expected to be within int32 range |
| 278 | expired = int32(len(p.Expired)) |
| 279 | |
| 280 | if p.isActive() { |
| 281 | desired = p.CalculateDesiredInstances(p.clock.Now()) |
| 282 | eligible = p.countEligible() |
| 283 | extraneous = max(actual-expired-desired, 0) |
| 284 | } |
| 285 | |
| 286 | starting, stopping, deleting := p.countInProgress() |
| 287 | |
| 288 | return &ReconciliationState{ |
| 289 | Actual: actual, |
| 290 | Expired: expired, |
| 291 | Desired: desired, |
| 292 | Eligible: eligible, |
| 293 | Extraneous: extraneous, |
| 294 | |
| 295 | Starting: starting, |
| 296 | Stopping: stopping, |
| 297 | Deleting: deleting, |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | // CalculateActions determines what actions are needed to reconcile the current state with the desired state. |
| 302 | // The function: |