Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix!: enforce unique agent names per workspace #5497

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
Dec 22, 2022
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
10 changes: 9 additions & 1 deletion coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,16 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
}
snapshot.WorkspaceResources = append(snapshot.WorkspaceResources, telemetry.ConvertWorkspaceResource(resource))

appSlugs := make(map[string]struct{})
var (
agentNames = make(map[string]struct{})
appSlugs = make(map[string]struct{})
)
for _, prAgent := range protoResource.Agents {
if _, ok := agentNames[prAgent.Name]; ok {
return xerrors.Errorf("duplicate agent name %q", prAgent.Name)
}
agentNames[prAgent.Name] = struct{}{}

var instanceID sql.NullString
if prAgent.GetInstanceId() != "" {
instanceID = sql.NullString{
Expand Down
7 changes: 7 additions & 0 deletions provisioner/terraform/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
findTerraformResources(module)

// Find all agents!
agentNames := map[string]struct{}{}
for _, tfResource := range tfResourceByLabel {
if tfResource.Type != "coder_agent" {
continue
Expand All @@ -110,6 +111,12 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
if err != nil {
return nil, xerrors.Errorf("decode agent attributes: %w", err)
}

if _, ok := agentNames[tfResource.Name]; ok {
return nil, xerrors.Errorf("duplicate agent name: %s", tfResource.Name)
}
agentNames[tfResource.Name] = struct{}{}

agent := &proto.Agent{
Name: tfResource.Name,
Id: attrs.ID,
Expand Down