Persisting presets defined with prebuilds to DB

Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
Danny Kopping
2025-02-04 14:41:07 +00:00
parent 0ba8f89df1
commit b60f2f66c6
20 changed files with 896 additions and 650 deletions

View File

@ -6,7 +6,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/coder/coder/v2/coderd/agentapi"
"net/http"
"net/url"
"reflect"
@ -16,6 +15,8 @@ import (
"sync/atomic"
"time"
"github.com/coder/coder/v2/coderd/agentapi"
"github.com/google/uuid"
"github.com/sqlc-dev/pqtype"
semconv "go.opentelemetry.io/otel/semconv/v1.14.0"
@ -28,6 +29,8 @@ import (
"cdr.dev/slog"
"github.com/coder/quartz"
"github.com/coder/coder/v2/coderd/apikey"
"github.com/coder/coder/v2/coderd/audit"
"github.com/coder/coder/v2/coderd/database"
@ -47,7 +50,6 @@ import (
"github.com/coder/coder/v2/provisionerd/proto"
"github.com/coder/coder/v2/provisionersdk"
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
"github.com/coder/quartz"
)
const (
@ -1882,6 +1884,17 @@ func InsertWorkspacePresetAndParameters(ctx context.Context, db database.Store,
if err != nil {
return xerrors.Errorf("insert preset and parameters: %w", err)
}
if protoPreset.Prebuild != nil {
_, err := db.InsertPresetPrebuild(ctx, database.InsertPresetPrebuildParams{
ID: uuid.New(),
PresetID: dbPreset.ID,
DesiredInstances: protoPreset.Prebuild.Instances,
InvalidateAfterSecs: 0, // TODO: implement cache invalidation
})
if err != nil {
return xerrors.Errorf("insert preset prebuild: %w", err)
}
}
return nil
}