Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: add documentation for prebuild scheduling feature#18462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
7 commits
Select commitHold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
refactor: change calculate-actions function signature
  • Loading branch information
@evgeniy-scherbina
evgeniy-scherbina committedJun 19, 2025
commit38e5bc5235a91b8e1b35656b58595220ca946b4f
4 changes: 2 additions & 2 deletionscoderd/prebuilds/preset_snapshot.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -267,14 +267,14 @@ func (p PresetSnapshot) CalculateState() *ReconciliationState {
// - ActionTypeBackoff: Only BackoffUntil is set, indicating when to retry
// - ActionTypeCreate: Only Create is set, indicating how many prebuilds to create
// - ActionTypeDelete: Only DeleteIDs is set, containing IDs of prebuilds to delete
func (p PresetSnapshot) CalculateActions(clock quartz.Clock,backoffInterval time.Duration) ([]*ReconciliationActions, error) {
func (p PresetSnapshot) CalculateActions(backoffInterval time.Duration) ([]*ReconciliationActions, error) {
// TODO: align workspace states with how we represent them on the FE and the CLI
// right now there's some slight differences which can lead to additional prebuilds being created

// TODO: add mechanism to prevent prebuilds being reconciled from being claimable by users; i.e. if a prebuild is
// about to be deleted, it should not be deleted if it has been claimed - beware of TOCTOU races!

actions, needsBackoff := p.needsBackoffPeriod(clock, backoffInterval)
actions, needsBackoff := p.needsBackoffPeriod(p.clock, backoffInterval)
if needsBackoff {
return actions, nil
}
Expand Down
42 changes: 21 additions & 21 deletionscoderd/prebuilds/preset_snapshot_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -86,12 +86,12 @@ func TestNoPrebuilds(t *testing.T) {
preset(true, 0, current),
}

snapshot := prebuilds.NewGlobalSnapshot(presets, nil, nil, nil, nil, nil,quartz.NewMock(t), testutil.Logger(t))
snapshot := prebuilds.NewGlobalSnapshot(presets, nil, nil, nil, nil, nil,clock, testutil.Logger(t))
ps, err := snapshot.FilterByPreset(current.presetID)
require.NoError(t, err)

state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)

validateState(t, prebuilds.ReconciliationState{ /*all zero values*/ }, *state)
Expand All@@ -108,12 +108,12 @@ func TestNetNew(t *testing.T) {
preset(true, 1, current),
}

snapshot := prebuilds.NewGlobalSnapshot(presets, nil, nil, nil, nil, nil,quartz.NewMock(t), testutil.Logger(t))
snapshot := prebuilds.NewGlobalSnapshot(presets, nil, nil, nil, nil, nil,clock, testutil.Logger(t))
ps, err := snapshot.FilterByPreset(current.presetID)
require.NoError(t, err)

state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)

validateState(t, prebuilds.ReconciliationState{
Expand DownExpand Up@@ -156,7 +156,7 @@ func TestOutdatedPrebuilds(t *testing.T) {

// THEN: we should identify that this prebuild is outdated and needs to be deleted.
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 1,
Expand All@@ -174,7 +174,7 @@ func TestOutdatedPrebuilds(t *testing.T) {

// THEN: we should not be blocked from creating a new prebuild while the outdate one deletes.
state = ps.CalculateState()
actions, err = ps.CalculateActions(clock,backoffInterval)
actions, err = ps.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{Desired: 1}, *state)
validateActions(t, []*prebuilds.ReconciliationActions{
Expand DownExpand Up@@ -223,7 +223,7 @@ func TestDeleteOutdatedPrebuilds(t *testing.T) {
// THEN: we should identify that this prebuild is outdated and needs to be deleted.
// Despite the fact that deletion of another outdated prebuild is already in progress.
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 1,
Expand DownExpand Up@@ -467,7 +467,7 @@ func TestInProgressActions(t *testing.T) {

// THEN: we should identify that this prebuild is in progress.
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)
tc.checkFn(*state, actions)
})
Expand DownExpand Up@@ -510,7 +510,7 @@ func TestExtraneous(t *testing.T) {

// THEN: an extraneous prebuild is detected and marked for deletion.
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 2, Desired: 1, Extraneous: 1, Eligible: 2,
Expand DownExpand Up@@ -685,13 +685,13 @@ func TestExpiredPrebuilds(t *testing.T) {
}

// WHEN: calculating the current preset's state.
snapshot := prebuilds.NewGlobalSnapshot(presets, nil, running, nil, nil, nil,quartz.NewMock(t), testutil.Logger(t))
snapshot := prebuilds.NewGlobalSnapshot(presets, nil, running, nil, nil, nil,clock, testutil.Logger(t))
ps, err := snapshot.FilterByPreset(current.presetID)
require.NoError(t, err)

// THEN: we should identify that this prebuild is expired.
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)
tc.checkFn(running, *state, actions)
})
Expand DownExpand Up@@ -727,7 +727,7 @@ func TestDeprecated(t *testing.T) {

// THEN: all running prebuilds should be deleted because the template is deprecated.
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 1,
Expand DownExpand Up@@ -774,13 +774,13 @@ func TestLatestBuildFailed(t *testing.T) {
}

// WHEN: calculating the current preset's state.
snapshot := prebuilds.NewGlobalSnapshot(presets, nil, running, inProgress, backoffs, nil,quartz.NewMock(t), testutil.Logger(t))
snapshot := prebuilds.NewGlobalSnapshot(presets, nil, running, inProgress, backoffs, nil,clock, testutil.Logger(t))
psCurrent, err := snapshot.FilterByPreset(current.presetID)
require.NoError(t, err)

// THEN: reconciliation should backoff.
state := psCurrent.CalculateState()
actions, err := psCurrent.CalculateActions(clock,backoffInterval)
actions, err := psCurrent.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 0, Desired: 1,
Expand All@@ -798,7 +798,7 @@ func TestLatestBuildFailed(t *testing.T) {

// THEN: it should NOT be in backoff because all is OK.
state = psOther.CalculateState()
actions, err = psOther.CalculateActions(clock,backoffInterval)
actions, err = psOther.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 1, Desired: 1, Eligible: 1,
Expand All@@ -812,7 +812,7 @@ func TestLatestBuildFailed(t *testing.T) {
psCurrent, err = snapshot.FilterByPreset(current.presetID)
require.NoError(t, err)
state = psCurrent.CalculateState()
actions, err = psCurrent.CalculateActions(clock,backoffInterval)
actions, err = psCurrent.CalculateActions(backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 0, Desired: 1,
Expand DownExpand Up@@ -867,15 +867,15 @@ func TestMultiplePresetsPerTemplateVersion(t *testing.T) {
},
}

snapshot := prebuilds.NewGlobalSnapshot(presets, nil, nil, inProgress, nil, nil,quartz.NewMock(t), testutil.Logger(t))
snapshot := prebuilds.NewGlobalSnapshot(presets, nil, nil, inProgress, nil, nil,clock, testutil.Logger(t))

// Nothing has to be created for preset 1.
{
ps, err := snapshot.FilterByPreset(presetOpts1.presetID)
require.NoError(t, err)

state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)

validateState(t, prebuilds.ReconciliationState{
Expand All@@ -891,7 +891,7 @@ func TestMultiplePresetsPerTemplateVersion(t *testing.T) {
require.NoError(t, err)

state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)

validateState(t, prebuilds.ReconciliationState{
Expand DownExpand Up@@ -995,7 +995,7 @@ func TestPrebuildScheduling(t *testing.T) {
require.NoError(t, err)

state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)

validateState(t, prebuilds.ReconciliationState{
Expand All@@ -1016,7 +1016,7 @@ func TestPrebuildScheduling(t *testing.T) {
require.NoError(t, err)

state := ps.CalculateState()
actions, err := ps.CalculateActions(clock,backoffInterval)
actions, err := ps.CalculateActions(backoffInterval)
require.NoError(t, err)

validateState(t, prebuilds.ReconciliationState{
Expand Down
2 changes: 1 addition & 1 deletionenterprise/coderd/prebuilds/reconcile.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -518,7 +518,7 @@ func (c *StoreReconciler) CalculateActions(ctx context.Context, snapshot prebuil
return nil, ctx.Err()
}

return snapshot.CalculateActions(c.clock, c.cfg.ReconciliationBackoffInterval.Value())
return snapshot.CalculateActions(c.cfg.ReconciliationBackoffInterval.Value())
}

func (c *StoreReconciler) WithReconciliationLock(
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp