mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
fix: enforce unique agent names per workspace (#5497)
This commit is contained in:
@ -854,8 +854,16 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
|
|||||||
}
|
}
|
||||||
snapshot.WorkspaceResources = append(snapshot.WorkspaceResources, telemetry.ConvertWorkspaceResource(resource))
|
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 {
|
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
|
var instanceID sql.NullString
|
||||||
if prAgent.GetInstanceId() != "" {
|
if prAgent.GetInstanceId() != "" {
|
||||||
instanceID = sql.NullString{
|
instanceID = sql.NullString{
|
||||||
|
@ -101,6 +101,7 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
|
|||||||
findTerraformResources(module)
|
findTerraformResources(module)
|
||||||
|
|
||||||
// Find all agents!
|
// Find all agents!
|
||||||
|
agentNames := map[string]struct{}{}
|
||||||
for _, tfResource := range tfResourceByLabel {
|
for _, tfResource := range tfResourceByLabel {
|
||||||
if tfResource.Type != "coder_agent" {
|
if tfResource.Type != "coder_agent" {
|
||||||
continue
|
continue
|
||||||
@ -110,6 +111,12 @@ func ConvertResources(module *tfjson.StateModule, rawGraph string) ([]*proto.Res
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("decode agent attributes: %w", err)
|
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{
|
agent := &proto.Agent{
|
||||||
Name: tfResource.Name,
|
Name: tfResource.Name,
|
||||||
Id: attrs.ID,
|
Id: attrs.ID,
|
||||||
|
Reference in New Issue
Block a user