MCPcopy Create free account
hub / github.com/coder/coder / handleActiveTemplateVersion

Method handleActiveTemplateVersion

coderd/prebuilds/preset_snapshot.go:352–392  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

350//
351// The function returns a list of actions to be executed to achieve the desired state.
352func (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.

Callers 1

CalculateActionsMethod · 0.95

Calls 2

CalculateStateMethod · 0.95
getOldestPrebuildIDsMethod · 0.95

Tested by

no test coverage detected