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

Commit6587920

Browse files
committed
feat: persist generated coder_app id
Signed-off-by: Danny Kopping <dannykopping@gmail.com>
1 parent725bc37 commit6587920

File tree

8 files changed

+48
-4
lines changed

8 files changed

+48
-4
lines changed

‎coderd/agentapi/apps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (a *AppsAPI) BatchUpdateAppHealths(ctx context.Context, req *agentproto.Bat
9292
Health:app.Health,
9393
})
9494
iferr!=nil {
95-
returnnil,xerrors.Errorf("update workspace app health for app %q (%q): %w",err,app.ID,app.Slug)
95+
returnnil,xerrors.Errorf("update workspace app health for app %q (%q): %w",app.ID,app.Slug,err)
9696
}
9797
}
9898

‎coderd/provisionerdserver/provisionerdserver.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2595,8 +2595,19 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
25952595
openIn=database.WorkspaceAppOpenInSlimWindow
25962596
}
25972597

2598+
varappIDstring
2599+
ifapp.Id==""||app.Id==uuid.Nil.String() {
2600+
appID=uuid.NewString()
2601+
}else {
2602+
appID=app.Id
2603+
}
2604+
id,err:=uuid.Parse(appID)
2605+
iferr!=nil {
2606+
returnxerrors.Errorf("parse app uuid: %w",err)
2607+
}
2608+
25982609
dbApp,err:=db.InsertWorkspaceApp(ctx, database.InsertWorkspaceAppParams{
2599-
ID:uuid.New(),
2610+
ID:id,
26002611
CreatedAt:dbtime.Now(),
26012612
AgentID:dbAgent.ID,
26022613
Slug:slug,

‎provisioner/terraform/resources.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88

99
"github.com/awalterschulze/gographviz"
10+
"github.com/google/uuid"
1011
tfjson"github.com/hashicorp/terraform-json"
1112
"github.com/mitchellh/mapstructure"
1213
"golang.org/x/xerrors"
@@ -93,6 +94,7 @@ type agentDisplayAppsAttributes struct {
9394

9495
// A mapping of attributes on the "coder_app" resource.
9596
typeagentAppAttributesstruct {
97+
IDstring`mapstructure:"id"`
9698
AgentIDstring`mapstructure:"agent_id"`
9799
// Slug is required in terraform, but to avoid breaking existing users we
98100
// will default to the resource name if it is not specified.
@@ -522,7 +524,17 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
522524
continue
523525
}
524526

527+
id:=attrs.ID
528+
ifid=="" {
529+
// This should never happen since the "id" attribute is set on creation:
530+
// https://github.com/coder/terraform-provider-coder/blob/cfa101df4635e405e66094fa7779f9a89d92f400/provider/app.go#L37
531+
logger.Warn(ctx,"coder_app's id was unexpectedly empty",slog.F("name",attrs.Name))
532+
533+
id=uuid.NewString()
534+
}
535+
525536
agent.Apps=append(agent.Apps,&proto.App{
537+
Id:id,
526538
Slug:attrs.Slug,
527539
DisplayName:attrs.DisplayName,
528540
Command:attrs.Command,

‎provisioner/terraform/resources_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,9 @@ func TestConvertResources(t *testing.T) {
967967
ifagent.GetInstanceId()!="" {
968968
agent.Auth=&proto.Agent_InstanceId{}
969969
}
970+
for_,app:=rangeagent.Apps {
971+
app.Id=""
972+
}
970973
}
971974
}
972975

@@ -1037,6 +1040,9 @@ func TestConvertResources(t *testing.T) {
10371040
ifagent.GetInstanceId()!="" {
10381041
agent.Auth=&proto.Agent_InstanceId{}
10391042
}
1043+
for_,app:=rangeagent.Apps {
1044+
app.Id=""
1045+
}
10401046
}
10411047
}
10421048
// Convert expectedNoMetadata and resources into a

‎provisionerd/proto/version.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import "github.com/coder/coder/v2/apiversion"
3737
// - Add new field named `scheduling` to `Prebuild`, with fields for timezone
3838
// and schedule rules to define cron-based scaling of prebuilt workspace
3939
// instances based on time patterns.
40+
// - Added new field named `id` to `App`, which transports the ID generated by the coder_app provider to be persisted.
4041
const (
4142
CurrentMajor=1
4243
CurrentMinor=7

‎provisionersdk/proto/provisioner.pb.go

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

‎provisionersdk/proto/provisioner.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ message App {
266266
boolhidden=11;
267267
AppOpenInopen_in=12;
268268
stringgroup=13;
269+
stringid=14;
269270
}
270271

271272
// Healthcheck represents configuration for checking for app readiness.

‎site/e2e/provisionerGenerated.ts

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp