mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix(enterprise): make coderd options own replica ID
This commit is contained in:
@@ -653,6 +653,7 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
|
||||
}
|
||||
|
||||
options := &coderd.Options{
|
||||
ID: uuid.New(),
|
||||
AccessURL: vals.AccessURL.Value(),
|
||||
AppHostname: appHostname,
|
||||
AppHostnameRegex: appHostnameRegex,
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/xerrors"
|
||||
"tailscale.com/derp"
|
||||
"tailscale.com/types/key"
|
||||
@@ -138,10 +137,8 @@ func (r *RootCmd) Server(_ func()) *serpent.Command {
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("create DERP mesh TLS config: %w", err)
|
||||
}
|
||||
replicaID := uuid.New()
|
||||
options.ID = replicaID
|
||||
replicaManager, err := replicasync.New(ctx, options.Logger, options.Database, options.Pubsub, &replicasync.Options{
|
||||
ID: replicaID,
|
||||
ID: options.ID,
|
||||
RelayAddress: options.DeploymentValues.DERP.Server.RelayURL.String(),
|
||||
// #nosec G115 - DERP region IDs are small and fit in int32
|
||||
RegionID: int32(options.DeploymentValues.DERP.Server.RegionID.Value()),
|
||||
|
||||
@@ -226,11 +226,8 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
|
||||
|
||||
// The API replica ID must match the replica manager ID because other
|
||||
// replicas use this ID to relay work back to the owning API instance.
|
||||
if options.ReplicaManager == nil {
|
||||
return nil, xerrors.New("replica manager is required")
|
||||
}
|
||||
if options.Options.ID == uuid.Nil {
|
||||
options.Options.ID = options.ReplicaManager.ID()
|
||||
if options.Options.ID != options.ReplicaManager.ID() {
|
||||
return nil, xerrors.Errorf("replica manager ID %s does not match coderd ID %s", options.ReplicaManager.ID(), options.Options.ID)
|
||||
}
|
||||
|
||||
api := &API{
|
||||
|
||||
@@ -105,10 +105,17 @@ func NewWithAPI(t *testing.T, options *Options) (
|
||||
}
|
||||
require.False(t, options.DontAddFirstUser && !options.DontAddLicense, "DontAddFirstUser requires DontAddLicense")
|
||||
setHandler, cancelFunc, serverURL, oop := coderdtest.NewOptions(t, options.Options)
|
||||
if oop.ID == uuid.Nil {
|
||||
oop.ID = uuid.New()
|
||||
}
|
||||
replicaManager := options.ReplicaManager
|
||||
if replicaManager != nil {
|
||||
oop.ID = replicaManager.ID()
|
||||
}
|
||||
if replicaManager == nil {
|
||||
var err error
|
||||
replicaManager, err = replicasync.New(context.Background(), oop.Logger, oop.Database, oop.Pubsub, &replicasync.Options{
|
||||
ID: oop.ID,
|
||||
RelayAddress: serverURL.String(),
|
||||
// #nosec G115 - DERP region IDs are small and fit in int32.
|
||||
RegionID: int32(oop.DeploymentValues.DERP.Server.RegionID.Value()),
|
||||
|
||||
Reference in New Issue
Block a user