more work done

This commit is contained in:
ston1th 2021-03-06 16:51:36 +01:00
commit 6fda229a8e
23 changed files with 384 additions and 177 deletions

View file

@ -17,7 +17,9 @@ const (
RaftLogLevel = "off"
EtcdLogLevel = "error"
EtcdPrefix = "/vipman"
EtcdPrefix = "/haproxy-lb"
HAProxyConfigFile = "/etc/haproxy/haproxy.cf"
)
func ParseFile(file string) (cfg *Config, err error) {
@ -39,8 +41,14 @@ func ParseFile(file string) (cfg *Config, err error) {
}
func Validate(c *Config) error {
if len(c.VirtualIPs) == 0 {
return errors.New("missing virtualIPs config")
if c.HAProxyConfig == "" {
c.HAProxyConfig = HAProxyConfigFile
}
if len(c.VIP.VirtualIPs) == 0 {
return errors.New("missing server.virtualIPs config")
}
if c.VIP.Gateway == "" {
return errors.New("missing server.gateway config")
}
if c.LeaderHook != "" {
if !filepath.IsAbs(c.LeaderHook) {
@ -110,10 +118,10 @@ func Validate(c *Config) error {
if raft != nil && etcd != nil {
return errors.New("only one cluster config allowed: raft or etcd")
}
if len(c.BasicAuth) == 0 {
if len(c.Server.BasicAuth) == 0 {
return errors.New("missing basic auth configuration for api users")
}
for _, u := range c.BasicAuth {
for _, u := range c.Server.BasicAuth {
if u.User == "" {
return errors.New("basic auth username can not be empty")
}
@ -126,13 +134,25 @@ func Validate(c *Config) error {
}
type Config struct {
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"`
BasicAuth []BasicAuth `yaml:"basicAuth"`
LeaderHook string `yaml:"leaderHook,omitempty"`
FollowerHook string `yaml:"followerHook,omitempty"`
HAProxyConfig string `yaml:"haproxyConfig,omitempty"`
VIP VIP `yaml:"vip"`
Cluster Cluster `yaml:"cluster"`
Server Server `yaml:"server"`
}
type Server struct {
Listen string `yaml:"listen"`
TLS TLS `yaml:"tls"`
BasicAuth []BasicAuth `yaml:"basicAuth"`
}
type VIP struct {
VirtualIPs []string `yaml:"virtualIPs"`
Gateway string `yaml:"gateway"`
Interface string `yaml:"interface,omitempty"`
Label string `yaml:"label,omitempty"`
}
type BasicAuth struct {