diff --git a/CHANGELOG.md b/CHANGELOG.md index 57684e25..495080f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changed from version 0.12.0 to master +- Added advertised endpoint to coordinators and active failover servers. + - Database upgrade procedure has changed. It is now much more automated and can be triggered using an `arangodb upgrade --starter.endpoint=...` command. diff --git a/main.go b/main.go index cfd99f50..e8c4ca9c 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ import ( "context" "fmt" "io/ioutil" + "net/url" "os" "os/signal" "path/filepath" @@ -86,6 +87,7 @@ var ( logService logging.Service showVersion bool id string + advertisedEndpoint string agencySize int arangodPath string arangodJSPath string @@ -192,7 +194,7 @@ func init() { pf.StringVar(&logDir, "log.dir", getEnvVar("LOG_DIR", ""), "Custom log file directory.") f.IntVar(&logRotateFilesToKeep, "log.rotate-files-to-keep", defaultLogRotateFilesToKeep, "Number of files to keep when rotating log files") f.DurationVar(&logRotateInterval, "log.rotate-interval", defaultLogRotateInterval, "Time between log rotations (0 disables log rotation)") - + f.StringVar(&advertisedEndpoint, "cluster.advertised-endpoint", "", "An external endpoint for the servers started by this Starter") f.IntVar(&agencySize, "cluster.agency-size", 3, "Number of agents in the cluster") f.BoolSliceVar(&startAgent, "cluster.start-agent", nil, "should an agent instance be started") f.BoolSliceVar(&startDBserver, "cluster.start-dbserver", nil, "should a dbserver instance be started") @@ -568,6 +570,11 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo log.Fatal().Err(err).Msgf("Unsupport image pull policy '%s'", dockerImagePullPolicy) } + // Sanity checking URL scheme on advertised endpoints + if _, err := url.Parse(advertisedEndpoint); err != nil { + log.Fatal().Err(err).Msgf("Advertised cluster endpoint %s does not meet URL standards", advertisedEndpoint) + } + // Expand home-dis (~) in paths arangodPath = mustExpand(arangodPath) arangodJSPath = mustExpand(arangodJSPath) @@ -707,6 +714,7 @@ func mustPrepareService(generateAutoKeyFile bool) (*service.Service, service.Boo ArangodPath: arangodPath, ArangoSyncPath: arangoSyncPath, ArangodJSPath: arangodJSPath, + AdvertisedEndpoint: advertisedEndpoint, MasterPort: masterPort, RrPath: rrPath, DataDir: dataDir, diff --git a/service/arangod_config_builder.go b/service/arangod_config_builder.go index 1e9cca56..86010de6 100644 --- a/service/arangod_config_builder.go +++ b/service/arangod_config_builder.go @@ -45,6 +45,19 @@ import ( "github.com/rs/zerolog" ) +var ( + urlFixer = strings.NewReplacer( + "http://", "tcp://", + "https://", "ssl://", + ) +) + +// fixupEndpointURLSchemeForArangod changes endpoint URL schemes used by Starter to ones used by arangodb. +// E.g. "http://localhost:8529" -> "tcp://localhost:8529" +func fixupEndpointURLSchemeForArangod(u string) string { + return urlFixer.Replace(u) +} + // createArangodConf creates an arangod.conf file in the given host directory if it does not yet exists. // The arangod.conf file contains all settings that are considered static for the lifetime of the server. func createArangodConf(log zerolog.Logger, bsCfg BootstrapConfig, myHostDir, myContainerDir, myPort string, serverType ServerType, features DatabaseFeatures) ([]Volume, configFile, error) { @@ -216,6 +229,13 @@ func createArangodArgs(log zerolog.Logger, config Config, clusterConfig ClusterC optionPair{"--cluster.my-role", "SINGLE"}, ) } + if serverType == ServerTypeCoordinator || serverType == ServerTypeResilientSingle { + if config.AdvertisedEndpoint != "" { + options = append(options, + optionPair{"--cluster.my-advertised-endpoint", fixupEndpointURLSchemeForArangod(config.AdvertisedEndpoint)}, + ) + } + } if serverType != ServerTypeAgent && serverType != ServerTypeSingle { for _, p := range clusterConfig.AllAgents() { options = append(options, diff --git a/service/service.go b/service/service.go index 8d55d2b1..87c450c8 100644 --- a/service/service.go +++ b/service/service.go @@ -58,6 +58,7 @@ type Config struct { ArangodPath string ArangodJSPath string ArangoSyncPath string + AdvertisedEndpoint string MasterPort int RrPath string DataDir string