handleActiveTemplateVersion determines the reconciliation actions for a preset with an active template version. It ensures the system moves towards the desired number of healthy prebuilds. The reconciliation follows this order: 1. Delete expired prebuilds: These are no longer valid and must be remo
()
| 350 | // |
| 351 | // The function returns a list of actions to be executed to achieve the desired state. |
| 352 | func (p PresetSnapshot) handleActiveTemplateVersion() (actions []*ReconciliationActions, err error) { |
| 353 | state := p.CalculateState() |
| 354 | |
| 355 | // If we have expired prebuilds, delete them |
| 356 | if state.Expired > 0 { |
| 357 | var deleteIDs []uuid.UUID |
| 358 | for _, expired := range p.Expired { |
| 359 | deleteIDs = append(deleteIDs, expired.ID) |
| 360 | } |
| 361 | actions = append(actions, |
| 362 | &ReconciliationActions{ |
| 363 | ActionType: ActionTypeDelete, |
| 364 | DeleteIDs: deleteIDs, |
| 365 | }) |
| 366 | } |
| 367 | |
| 368 | // If we still have more prebuilds than desired, delete the oldest ones |
| 369 | if state.Extraneous > 0 { |
| 370 | actions = append(actions, |
| 371 | &ReconciliationActions{ |
| 372 | ActionType: ActionTypeDelete, |
| 373 | DeleteIDs: p.getOldestPrebuildIDs(int(state.Extraneous)), |
| 374 | }) |
| 375 | } |
| 376 | |
| 377 | // Number of running prebuilds excluding the recently deleted Expired |
| 378 | runningValid := state.Actual - state.Expired |
| 379 | |
| 380 | // Calculate how many new prebuilds we need to create |
| 381 | // We subtract starting prebuilds since they're already being created |
| 382 | prebuildsToCreate := max(state.Desired-runningValid-state.Starting, 0) |
| 383 | if prebuildsToCreate > 0 { |
| 384 | actions = append(actions, |
| 385 | &ReconciliationActions{ |
| 386 | ActionType: ActionTypeCreate, |
| 387 | Create: prebuildsToCreate, |
| 388 | }) |
| 389 | } |
| 390 | |
| 391 | return actions, nil |
| 392 | } |
| 393 | |
| 394 | // handleInactiveTemplateVersion handles prebuilds from inactive template versions: |
| 395 | // 1. If the preset has pending prebuild jobs from an inactive template version, create a cancel reconciliation action. |
no test coverage detected