-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
etcdbackend: support version auto discovery #2299
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,51 @@ func newEtcd2Backend(conf map[string]string, logger log.Logger) (Backend, error) | |
path = "/" + path | ||
} | ||
|
||
c, err := newEtcdV2Client(conf) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
haEnabled := os.Getenv("ETCD_HA_ENABLED") | ||
if haEnabled == "" { | ||
haEnabled = conf["ha_enabled"] | ||
} | ||
haEnabledBool, _ := strconv.ParseBool(haEnabled) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we catch the error here? |
||
|
||
// Should we sync the cluster state? There are three available options | ||
// for our client library: don't sync (required for some proxies), sync | ||
// once, or sync periodically with AutoSync. We currently support the | ||
// first two. | ||
sync, ok := conf["sync"] | ||
if !ok { | ||
sync = "yes" | ||
} | ||
switch sync { | ||
case "yes", "true", "y", "1": | ||
ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) | ||
syncErr := c.Sync(ctx) | ||
cancel() | ||
if syncErr != nil { | ||
return nil, fmt.Errorf("%s: %s", EtcdSyncClusterError, syncErr) | ||
} | ||
case "no", "false", "n", "0": | ||
default: | ||
return nil, fmt.Errorf("value of 'sync' could not be understood") | ||
} | ||
|
||
kAPI := client.NewKeysAPI(c) | ||
|
||
// Setup the backend. | ||
return &Etcd2Backend{ | ||
path: path, | ||
kAPI: kAPI, | ||
permitPool: NewPermitPool(DefaultParallelOperations), | ||
logger: logger, | ||
haEnabled: haEnabledBool, | ||
}, nil | ||
} | ||
|
||
func newEtcdV2Client(conf map[string]string) (client.Client, error) { | ||
// Set a default machines list and check for an overriding address value. | ||
machines := "http://127.0.0.1:2379" | ||
if address, ok := conf["address"]; ok { | ||
|
@@ -86,12 +131,6 @@ func newEtcd2Backend(conf map[string]string, logger log.Logger) (Backend, error) | |
} | ||
} | ||
|
||
haEnabled := os.Getenv("ETCD_HA_ENABLED") | ||
if haEnabled == "" { | ||
haEnabled = conf["ha_enabled"] | ||
} | ||
haEnabledBool, _ := strconv.ParseBool(haEnabled) | ||
|
||
// Create a new client from the supplied address and attempt to sync with the | ||
// cluster. | ||
var cTransport client.CancelableTransport | ||
|
@@ -135,42 +174,7 @@ func newEtcd2Backend(conf map[string]string, logger log.Logger) (Backend, error) | |
cfg.Password = password | ||
} | ||
|
||
c, err := client.New(cfg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Should we sync the cluster state? There are three available options | ||
// for our client library: don't sync (required for some proxies), sync | ||
// once, or sync periodically with AutoSync. We currently support the | ||
// first two. | ||
sync, ok := conf["sync"] | ||
if !ok { | ||
sync = "yes" | ||
} | ||
switch sync { | ||
case "yes", "true", "y", "1": | ||
ctx, cancel := context.WithTimeout(context.Background(), client.DefaultRequestTimeout) | ||
syncErr := c.Sync(ctx) | ||
cancel() | ||
if syncErr != nil { | ||
return nil, fmt.Errorf("%s: %s", EtcdSyncClusterError, syncErr) | ||
} | ||
case "no", "false", "n", "0": | ||
default: | ||
return nil, fmt.Errorf("value of 'sync' could not be understood") | ||
} | ||
|
||
kAPI := client.NewKeysAPI(c) | ||
|
||
// Setup the backend. | ||
return &Etcd2Backend{ | ||
path: path, | ||
kAPI: kAPI, | ||
permitPool: NewPermitPool(DefaultParallelOperations), | ||
logger: logger, | ||
haEnabled: haEnabledBool, | ||
}, nil | ||
return client.New(cfg) | ||
} | ||
|
||
// Put is used to insert or update an entry. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments on this function as to how the version is computed might be helpful.