added etcd support
This commit is contained in:
parent
59d44932a4
commit
85a8ba23bd
21 changed files with 767 additions and 247 deletions
|
|
@ -4,13 +4,19 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
RaftDir = "raft"
|
||||
RaftPort = 7001
|
||||
RaftDir = "raft"
|
||||
RaftPort = 7001
|
||||
RaftLogLevel = "off"
|
||||
|
||||
EtcdLogLevel = "error"
|
||||
EtcdPrefix = "/vipman"
|
||||
)
|
||||
|
||||
func ParseFile(file string) (cfg *Config, err error) {
|
||||
|
|
@ -35,14 +41,24 @@ func Validate(c *Config) error {
|
|||
if len(c.VirtualIPs) == 0 {
|
||||
return errors.New("missing virtualIPs config")
|
||||
}
|
||||
if c.LeaderHook != "" {
|
||||
if !filepath.IsAbs(c.LeaderHook) {
|
||||
return errors.New("leaderHook path must be absolute")
|
||||
}
|
||||
}
|
||||
if c.FollowerHook != "" {
|
||||
if !filepath.IsAbs(c.FollowerHook) {
|
||||
return errors.New("followerHook path must be absolute")
|
||||
}
|
||||
}
|
||||
raft := c.Cluster.Raft
|
||||
if raft != nil {
|
||||
if raft.LogLevel == "" {
|
||||
raft.LogLevel = RaftLogLevel
|
||||
}
|
||||
if raft.Dir == "" {
|
||||
raft.Dir = RaftDir
|
||||
}
|
||||
if raft.Level == "" {
|
||||
raft.Level = "off"
|
||||
}
|
||||
if raft.ID == "" {
|
||||
return errors.New("missing raft.id config")
|
||||
}
|
||||
|
|
@ -63,7 +79,29 @@ func Validate(c *Config) error {
|
|||
}
|
||||
etcd := c.Cluster.Etcd
|
||||
if etcd != nil {
|
||||
|
||||
if etcd.LogLevel == "" {
|
||||
etcd.LogLevel = EtcdLogLevel
|
||||
}
|
||||
if len(etcd.Endpoints) == 0 {
|
||||
return errors.New("missing etcd.endpoints config")
|
||||
}
|
||||
if etcd.Prefix == "" {
|
||||
etcd.Prefix = EtcdPrefix
|
||||
} else {
|
||||
if !strings.HasPrefix(etcd.Prefix, "/") {
|
||||
etcd.Prefix = "/" + etcd.Prefix
|
||||
}
|
||||
if strings.HasSuffix(etcd.Prefix, "/") {
|
||||
etcd.Prefix = strings.TrimSuffix(etcd.Prefix, "/")
|
||||
}
|
||||
}
|
||||
if etcd.ClusterName == "" {
|
||||
return errors.New("missing etcd.clusterName config")
|
||||
} else {
|
||||
if strings.HasSuffix(etcd.ClusterName, "/") {
|
||||
etcd.ClusterName = strings.TrimSuffix(etcd.ClusterName, "/")
|
||||
}
|
||||
}
|
||||
}
|
||||
if raft == nil && etcd == nil {
|
||||
return errors.New("missing cluster config: raft or etcd")
|
||||
|
|
@ -75,17 +113,12 @@ func Validate(c *Config) error {
|
|||
}
|
||||
|
||||
type Config struct {
|
||||
VirtualIPs []string `yaml:"virtualIPs"`
|
||||
|
||||
Interface string `yaml:"interface,omitempty"`
|
||||
|
||||
IPLabel string `yaml:"label,omitempty"`
|
||||
|
||||
LeaderHook string `yaml:"leaderHook,omitempty"`
|
||||
|
||||
FollowerHook string `yaml:"followerHook,omitempty"`
|
||||
|
||||
Cluster Cluster `yaml:"cluster"`
|
||||
VirtualIPs []string `yaml:"virtualIPs"`
|
||||
Interface string `yaml:"interface,omitempty"`
|
||||
Label string `yaml:"label,omitempty"`
|
||||
LeaderHook string `yaml:"leaderHook,omitempty"`
|
||||
FollowerHook string `yaml:"followerHook,omitempty"`
|
||||
Cluster Cluster `yaml:"cluster"`
|
||||
}
|
||||
|
||||
type Cluster struct {
|
||||
|
|
@ -94,17 +127,17 @@ type Cluster struct {
|
|||
}
|
||||
|
||||
type Raft struct {
|
||||
Dir string `yaml:"dir,omitempty"`
|
||||
ID string `yaml:"id"`
|
||||
Address string `yaml:"address"`
|
||||
Level string `yaml:"level"`
|
||||
Peers []RaftPeer `yaml:"peers"`
|
||||
TLS *TLS `yaml:"tls,omitempty"`
|
||||
Dir string `yaml:"dir,omitempty"`
|
||||
ID string `yaml:"id"`
|
||||
Address string `yaml:"address"`
|
||||
Peers []RaftPeer `yaml:"peers"`
|
||||
TLS *TLS `yaml:"tls,omitempty"`
|
||||
LogLevel string `yaml:"logLevel,omitempty"`
|
||||
}
|
||||
|
||||
type TLS struct {
|
||||
Cert string `yaml:"cert"`
|
||||
Key string `yaml:"key"`
|
||||
Cert string `yaml:"cert,omitempty"`
|
||||
Key string `yaml:"key,omitempty"`
|
||||
CA string `yaml:"ca,omitempty"`
|
||||
Insecure bool `yaml:"insecure,omitempty"`
|
||||
}
|
||||
|
|
@ -119,4 +152,8 @@ type Etcd struct {
|
|||
Endpoints []string `yaml:"endpoints"`
|
||||
Prefix string `yaml:"prefix"`
|
||||
ClusterName string `yaml:"clusterName"`
|
||||
Username string `yaml:"username,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
TLS *TLS `yaml:"tls,omitempty"`
|
||||
LogLevel string `yaml:"logLevel,omitempty"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue