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

fix: don't create autostart workspace builds with no available provisioners#19067

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
cstyan merged 18 commits intomainfromcallum-autostart-no-provisioner
Aug 15, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
18 commits
Select commitHold shift + click to select a range
314bb66
add test that fails since we still trigger autobuilds even if a
cstyanJul 28, 2025
310511e
add check for available provisioners before we try to do a workspace
cstyanJul 28, 2025
1256877
fix provisioner check for tests which don't fully set up/wait for the
cstyanJul 29, 2025
26f5001
use the runOnce time
cstyanJul 31, 2025
78a8f5e
refactor: remove SkipProvisionerCheck and improve test provisioner ha…
cstyanJul 31, 2025
a983dc2
more fixes for tests; mostly around ensuring that tests which use the
cstyanAug 5, 2025
0bc4cce
significantly simplify
cstyanAug 11, 2025
9a3f534
more refactor and clean up
cstyanAug 11, 2025
a98ef1d
fix lint
cstyanAug 11, 2025
e48c724
hasValidProvisioner only needs tags
cstyanAug 11, 2025
883c748
more cleanup of function params
cstyanAug 11, 2025
3c90c6d
already waiting for the workspaces provisioner, don't need to wait for
cstyanAug 11, 2025
5a6493c
fix print statement missed in earlier commit
cstyanAug 12, 2025
c5f0d41
address more review feedback; mostly around provisioner closers in the
cstyanAug 12, 2025
224acfc
remove MustWaitForAnyProvisionerWithClient
cstyanAug 12, 2025
e7d748e
Merge branch 'main' into callum-autostart-no-provisioner
cstyanAug 14, 2025
3275c57
not sure how this was passing before, the prebuilds NextStartAt time is
cstyanAug 14, 2025
bae5c80
this test also needs to have the provisioner time updated
cstyanAug 14, 2025
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
50 changes: 50 additions & 0 deletionscoderd/autobuild/lifecycle_executor.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,7 @@ import (
"github.com/coder/coder/v2/coderd/database/provisionerjobs"
"github.com/coder/coder/v2/coderd/database/pubsub"
"github.com/coder/coder/v2/coderd/notifications"
"github.com/coder/coder/v2/coderd/provisionerdserver"
"github.com/coder/coder/v2/coderd/schedule"
"github.com/coder/coder/v2/coderd/wsbuilder"
"github.com/coder/coder/v2/codersdk"
Expand DownExpand Up@@ -132,6 +133,39 @@ func (e *Executor) Run() {
})
}

// hasValidProvisioner checks whether there is at least one valid (non-stale, correct tags) provisioner
// based on time t and the tags maps (such as from a templateVersionJob).
func (e *Executor) hasValidProvisioner(ctx context.Context, tx database.Store, t time.Time, ws database.Workspace, tags map[string]string) (bool, error) {
queryParams := database.GetProvisionerDaemonsByOrganizationParams{
OrganizationID: ws.OrganizationID,
WantTags: tags,
}

// nolint: gocritic // The user (in this case, the user/context for autostart builds) may not have the full
// permissions to read provisioner daemons, but we need to check if there's any for the job prior to the
// execution of the job via autostart to fix: https://github.com/coder/coder/issues/17941
provisionerDaemons, err := tx.GetProvisionerDaemonsByOrganization(dbauthz.AsSystemReadProvisionerDaemons(ctx), queryParams)
if err != nil {
return false, xerrors.Errorf("get provisioner daemons: %w", err)
}

logger := e.log.With(slog.F("tags", tags))
// Check if any provisioners are active (not stale)
for _, pd := range provisionerDaemons {
if pd.LastSeenAt.Valid {
age := t.Sub(pd.LastSeenAt.Time)
if age <= provisionerdserver.StaleInterval {
logger.Debug(ctx, "hasValidProvisioner: found active provisioner",
slog.F("daemon_id", pd.ID),
)
return true, nil
}
}
}
logger.Debug(ctx, "hasValidProvisioner: no active provisioners found")
return false, nil
}

func (e *Executor) runOnce(t time.Time) Stats {
stats := Stats{
Transitions: make(map[uuid.UUID]database.WorkspaceTransition),
Expand DownExpand Up@@ -281,6 +315,22 @@ func (e *Executor) runOnce(t time.Time) Stats {
return nil
}

// Get the template version job to access tags
templateVersionJob, err := tx.GetProvisionerJobByID(e.ctx, activeTemplateVersion.JobID)
if err != nil {
return xerrors.Errorf("get template version job: %w", err)
}

// Before creating the workspace build, check for available provisioners
hasProvisioners, err := e.hasValidProvisioner(e.ctx, tx, t, ws, templateVersionJob.Tags)
if err != nil {
return xerrors.Errorf("check provisioner availability: %w", err)
}
if !hasProvisioners {
log.Warn(e.ctx, "skipping autostart - no available provisioners")
return nil // Skip this workspace
}

if nextTransition != "" {
builder := wsbuilder.New(ws, nextTransition, *e.buildUsageChecker.Load()).
SetLastWorkspaceBuildInTx(&latestBuild).
Expand Down
Loading
Loading

[8]ページ先頭

©2009-2025 Movatter.jp