diff --git a/CHANGELOG b/CHANGELOG index b537ccdf..fd201d7a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.1] - 2020-10-19 +### Change +* Fix GUBER_PEER_PICKER_HASH and GUBER_PEER_PICKER +* Now warns if GUBER_PEER_PICKER value is incorrect +* Now ignoring spaces between `key = value` in config file + ## [0.9.0] - 2020-10-13 ### Change * Fix GUBER_MEMBERLIST_ADVERTISE_PORT value type diff --git a/cmd/gubernator/config.go b/cmd/gubernator/config.go index 844ec6b4..19674352 100644 --- a/cmd/gubernator/config.go +++ b/cmd/gubernator/config.go @@ -146,12 +146,12 @@ func confFromEnv() (ServerConfig, error) { "fnv1": fnv1.HashBytes32, "crc32": nil, } - if fn, ok := hashFuncs[hash]; ok { - conf.Picker = gubernator.NewConsistantHash(fn) - return conf, nil + fn, ok := hashFuncs[hash] + if !ok { + return conf, errors.Errorf("'GUBER_PEER_PICKER_HASH=%s' is invalid; choices are [%s]", + hash, validHashKeys(hashFuncs)) } - return conf, errors.Errorf("'GUBER_PEER_PICKER_HASH=%s' is invalid; choices are [%s]", - hash, validHashKeys(hashFuncs)) + conf.Picker = gubernator.NewConsistantHash(fn) case "replicated-hash": setter.SetDefault(&replicas, getEnvInteger("GUBER_REPLICATED_HASH_REPLICAS"), 1) @@ -161,12 +161,14 @@ func confFromEnv() (ServerConfig, error) { "fnv1a": fnv1a.HashBytes64, "fnv1": fnv1.HashBytes64, } - if fn, ok := hashFuncs[hash]; ok { - conf.Picker = gubernator.NewReplicatedConsistantHash(fn, replicas) - return conf, nil + fn, ok := hashFuncs[hash] + if !ok { + return conf, errors.Errorf("'GUBER_PEER_PICKER_HASH=%s' is invalid; choices are [%s]", + hash, validHash64Keys(hashFuncs)) } - return conf, errors.Errorf("'GUBER_PEER_PICKER_HASH=%s' is invalid; choices are [%s]", - hash, validHash64Keys(hashFuncs)) + conf.Picker = gubernator.NewReplicatedConsistantHash(fn, replicas) + default: + return conf, errors.Errorf("'GUBER_PEER_PICKER=%s' is invalid; choices are ['replicated-hash', 'consistent-hash']", pp) } } @@ -328,7 +330,7 @@ func fromEnvFile(configFile string) error { return errors.Errorf("malformed key=value on line '%d'", i) } - if err := os.Setenv(parts[0], parts[1]); err != nil { + if err := os.Setenv(strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])); err != nil { return errors.Wrapf(err, "while settings environ for '%s=%s'", parts[0], parts[1]) } } diff --git a/example.conf b/example.conf index e1c3cf33..72b3b355 100644 --- a/example.conf +++ b/example.conf @@ -100,14 +100,14 @@ GUBER_ETCD_ADVERTISE_ADDRESS=localhost:81 # GUBER_PEER_PICKER=consistent-hash # Choose the hash algorithm for `consistent-hash` (crc32, fnv1a, fnv1) -# GUBER_PEER_PICKER_HASH = crc32 +# GUBER_PEER_PICKER_HASH=crc32 # Choose which picker algorithm to use # GUBER_PEER_PICKER=replicated-hash # Choose the hash algorithm for `replicated-hash` (fnv1a, fnv1) -# GUBER_PEER_PICKER_HASH = fnv1a +# GUBER_PEER_PICKER_HASH=fnv1a # Choose the number of replications -# GUBER_REPLICATED_HASH_REPLICAS = 1 +# GUBER_REPLICATED_HASH_REPLICAS=1