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

Commit2d1701d

Browse files
committed
chore: add parameter warning if metadata is missing
Dynamic parameters require the latest provisioner to function
1 parent6f67a9a commit2d1701d

12 files changed

+61
-24
lines changed

‎coderd/coderd.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,7 @@ func (api *API) CreateInMemoryTaggedProvisionerDaemon(dialCtx context.Context, n
17711771
logger:=api.Logger.Named(fmt.Sprintf("inmem-provisionerd-%s",name))
17721772
srv,err:=provisionerdserver.NewServer(
17731773
api.ctx,// use the same ctx as the API
1774+
daemon.APIVersion,
17741775
api.AccessURL,
17751776
daemon.ID,
17761777
defaultOrg.ID,

‎coderd/database/dbgen/dbgen.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/coder/coder/v2/coderd/rbac"
3030
"github.com/coder/coder/v2/codersdk"
3131
"github.com/coder/coder/v2/cryptorand"
32+
"github.com/coder/coder/v2/provisionerd/proto"
3233
"github.com/coder/coder/v2/testutil"
3334
)
3435

@@ -1000,10 +1001,11 @@ func TemplateVersionTerraformValues(t testing.TB, db database.Store, orig databa
10001001
t.Helper()
10011002

10021003
params:= database.InsertTemplateVersionTerraformValuesByJobIDParams{
1003-
JobID:takeFirst(orig.JobID,uuid.New()),
1004-
CachedPlan:takeFirstSlice(orig.CachedPlan, []byte("{}")),
1005-
CachedModuleFiles:orig.CachedModuleFiles,
1006-
UpdatedAt:takeFirst(orig.UpdatedAt,dbtime.Now()),
1004+
JobID:takeFirst(orig.JobID,uuid.New()),
1005+
CachedPlan:takeFirstSlice(orig.CachedPlan, []byte("{}")),
1006+
CachedModuleFiles:orig.CachedModuleFiles,
1007+
UpdatedAt:takeFirst(orig.UpdatedAt,dbtime.Now()),
1008+
ProvisionerdVersion:takeFirst(orig.ProvisionerdVersion,proto.CurrentVersion.String()),
10071009
}
10081010

10091011
err:=db.InsertTemplateVersionTerraformValuesByJobID(genCtx,params)

‎coderd/database/dump.sql‎

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTERTABLE template_version_terraform_values DROP COLUMN provisionerd_version;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTERTABLE template_version_terraform_values ADD COLUMN provisionerd_versionTEXTNOT NULL DEFAULT'';
2+
3+
COMMENT ON COLUMN template_version_terraform_values.provisionerd_version IS
4+
'What version of the provisioning engine was used to generate the cached plan and module files.';

‎coderd/database/models.go‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries.sql.go‎

Lines changed: 12 additions & 7 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/templateversionterraformvalues.sql‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ INSERT INTO
1212
template_version_id,
1313
cached_plan,
1414
cached_module_files,
15-
updated_at
15+
updated_at,
16+
provisionerd_version
1617
)
1718
VALUES
1819
(
1920
(select idfrom template_versionswhere job_id= @job_id),
2021
@cached_plan,
2122
@cached_module_files,
22-
@updated_at
23+
@updated_at,
24+
@provisionerd_version
2325
);

‎coderd/parameters.go‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"golang.org/x/sync/errgroup"
1313
"golang.org/x/xerrors"
1414

15+
"github.com/coder/coder/v2/apiversion"
1516
"github.com/coder/coder/v2/coderd/database"
1617
"github.com/coder/coder/v2/coderd/database/dbauthz"
1718
"github.com/coder/coder/v2/coderd/files"
@@ -81,23 +82,33 @@ func (api *API) templateVersionDynamicParameters(rw http.ResponseWriter, r *http
8182
deferapi.FileCache.Release(fileID)
8283

8384
staticDiagnostics:= hcl.Diagnostics{}
85+
missingMetaData:= hcl.Diagnostic{
86+
Severity:hcl.DiagWarning,
87+
Summary:"This template version is missing required metadata to support dynamic parameters. Go back to the classic creation flow.",
88+
Detail:"To restore full functionality, please re-import the terraform as a new template version.",
89+
}
8490

8591
// Having the Terraform plan available for the evaluation engine is helpful
8692
// for populating values from data blocks, but isn't strictly required. If
8793
// we don't have a cached plan available, we just use an empty one instead.
8894
plan:=json.RawMessage("{}")
8995
tf,err:=api.Database.GetTemplateVersionTerraformValues(ctx,templateVersion.ID)
9096
ifxerrors.Is(err,sql.ErrNoRows) {
91-
staticDiagnostics.Append(&hcl.Diagnostic{
92-
Severity:hcl.DiagWarning,
93-
Summary:"This template version is missing required metadata to support dynamic parameters.",
94-
Detail:"To restore full functionality, please re-import the terraform as a new template version.",
95-
})
97+
staticDiagnostics=staticDiagnostics.Append(&missingMetaData)
9698
}
97-
9899
iferr==nil {
99100
plan=tf.CachedPlan
100101

102+
major,minor,err:=apiversion.Parse(tf.ProvisionerdVersion)
103+
iferr!=nil||tf.ProvisionerdVersion=="" {
104+
staticDiagnostics=staticDiagnostics.Append(&missingMetaData)
105+
}elseifmajor<1|| (major==1&&minor<5) {
106+
missingMetaData.Detail="This template version requires provisioner v1.5 or newer to support dynamic parameters. "+
107+
"Some options may be missing or incorrect. "+
108+
"Please contact an administrator to update the provisioner and re-import the template version."
109+
staticDiagnostics=staticDiagnostics.Append(&missingMetaData)
110+
}
111+
101112
iftf.CachedModuleFiles.Valid {
102113
moduleFilesFS,err:=api.FileCache.Acquire(fileCtx,tf.CachedModuleFiles.UUID)
103114
iferr!=nil {

‎coderd/provisionerdserver/provisionerdserver.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ type Options struct {
9292
}
9393

9494
typeserverstruct {
95+
apiVersionstring
9596
// lifecycleCtx must be tied to the API server's lifecycle
9697
// as when the API server shuts down, we want to cancel any
9798
// long-running operations.
@@ -151,6 +152,7 @@ func (t Tags) Valid() error {
151152

152153
funcNewServer(
153154
lifecycleCtx context.Context,
155+
apiVersionstring,
154156
accessURL*url.URL,
155157
id uuid.UUID,
156158
organizationID uuid.UUID,
@@ -210,6 +212,7 @@ func NewServer(
210212

211213
s:=&server{
212214
lifecycleCtx:lifecycleCtx,
215+
apiVersion:apiVersion,
213216
AccessURL:accessURL,
214217
ID:id,
215218
OrganizationID:organizationID,
@@ -1506,10 +1509,11 @@ func (s *server) CompleteJob(ctx context.Context, completed *proto.CompletedJob)
15061509
}
15071510

15081511
err=s.Database.InsertTemplateVersionTerraformValuesByJobID(ctx, database.InsertTemplateVersionTerraformValuesByJobIDParams{
1509-
JobID:jobID,
1510-
UpdatedAt:now,
1511-
CachedPlan:plan,
1512-
CachedModuleFiles:fileID,
1512+
JobID:jobID,
1513+
UpdatedAt:now,
1514+
CachedPlan:plan,
1515+
CachedModuleFiles:fileID,
1516+
ProvisionerdVersion:s.apiVersion,
15131517
})
15141518
iferr!=nil {
15151519
returnnil,xerrors.Errorf("insert template version terraform data: %w",err)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp