Skip to content

fix: add minor fix to reconciliation loop #17454

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions coderd/prebuilds/preset_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ func (p PresetSnapshot) CalculateState() *ReconciliationState {
extraneous int32
)

// #nosec G115 - Safe conversion as p.Running slice length is expected to be within int32 range
actual = int32(len(p.Running))

if p.isActive() {
// #nosec G115 - Safe conversion as p.Running slice length is expected to be within int32 range
actual = int32(len(p.Running))
desired = p.Preset.DesiredInstances.Int32
eligible = p.countEligible()
extraneous = max(actual-desired, 0)
Expand Down
9 changes: 7 additions & 2 deletions coderd/prebuilds/preset_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ func TestOutdatedPrebuilds(t *testing.T) {
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock, backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{}, *state)
validateState(t, prebuilds.ReconciliationState{
Actual: 1,
}, *state)
validateActions(t, prebuilds.ReconciliationActions{
ActionType: prebuilds.ActionTypeDelete,
DeleteIDs: []uuid.UUID{outdated.prebuiltWorkspaceID},
Expand Down Expand Up @@ -208,6 +210,7 @@ func TestDeleteOutdatedPrebuilds(t *testing.T) {
actions, err := ps.CalculateActions(clock, backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{
Actual: 1,
Deleting: 1,
}, *state)

Expand Down Expand Up @@ -530,7 +533,9 @@ func TestDeprecated(t *testing.T) {
state := ps.CalculateState()
actions, err := ps.CalculateActions(clock, backoffInterval)
require.NoError(t, err)
validateState(t, prebuilds.ReconciliationState{}, *state)
validateState(t, prebuilds.ReconciliationState{
Actual: 1,
}, *state)
validateActions(t, prebuilds.ReconciliationActions{
ActionType: prebuilds.ActionTypeDelete,
DeleteIDs: []uuid.UUID{current.prebuiltWorkspaceID},
Expand Down
Loading