mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: modify replicasync to handle NATS explicitly (#26666)
relates to GRU-69 Modifies replicasync to handle discovering NATS enabled primary replicas explicitly, and passing that info to the NATS Pubsub. This PR adds a new deployment value to explicitly represent the host or IP that the replica can be reached on. It isn't wired up to the CLI, but piggybacks on the DERP config for now. We learn the NATS port directly from NATS at runtime, and propagate it thru replicasync to learn all peers for clustering.
This commit is contained in:
@@ -32,18 +32,28 @@ import (
|
||||
|
||||
func (r *RootCmd) Server(_ func()) *serpent.Command {
|
||||
cmd := r.RootCmd.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
|
||||
var (
|
||||
derpURL *url.URL
|
||||
err error
|
||||
)
|
||||
if options.DeploymentValues.DERP.Server.RelayURL.String() != "" {
|
||||
_, err := url.Parse(options.DeploymentValues.DERP.Server.RelayURL.String())
|
||||
derpURL, err = url.Parse(options.DeploymentValues.DERP.Server.RelayURL.String())
|
||||
if err != nil {
|
||||
return nil, nil, xerrors.Errorf("derp-server-relay-address must be a valid HTTP URL: %w", err)
|
||||
}
|
||||
}
|
||||
clusterHost := options.DeploymentValues.Cluster.Host.String()
|
||||
if clusterHost == "" && derpURL != nil {
|
||||
// Use the DERP host if the operator didn't specify an explicit cluster host, since this is an older setting
|
||||
// and more likely to be configured by longtime HA customers.
|
||||
clusterHost = derpURL.Hostname()
|
||||
}
|
||||
|
||||
// Always generate a mesh key, even if the built-in DERP server is
|
||||
// disabled. This mesh key is still used by workspace proxies running
|
||||
// HA.
|
||||
var meshKey string
|
||||
err := options.Database.InTx(func(tx database.Store) error {
|
||||
err = options.Database.InTx(func(tx database.Store) error {
|
||||
// This will block until the lock is acquired, and will be
|
||||
// automatically released when the transaction ends.
|
||||
err := tx.AcquireLock(ctx, database.LockIDEnterpriseDeploymentSetup)
|
||||
@@ -97,6 +107,7 @@ func (r *RootCmd) Server(_ func()) *serpent.Command {
|
||||
SCIMAPIKey: []byte(options.DeploymentValues.SCIMAPIKey.Value()),
|
||||
UseLegacySCIM: options.DeploymentValues.UseLegacySCIM.Value(),
|
||||
RBAC: true,
|
||||
ClusterHost: clusterHost,
|
||||
DERPServerRelayAddress: options.DeploymentValues.DERP.Server.RelayURL.String(),
|
||||
DERPServerRegionID: int(options.DeploymentValues.DERP.Server.RegionID.Value()),
|
||||
ProxyHealthInterval: options.DeploymentValues.ProxyHealthStatusInterval.Value(),
|
||||
|
||||
Reference in New Issue
Block a user