Move source-tag to toplevel maglev.source-tag config, defaulting to short hostname, v1.1.2
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
// Config is the top-level parsed and validated configuration.
|
||||
type Config struct {
|
||||
SourceTag string // this node's nginx source tag; defaults to the short hostname
|
||||
HealthChecker HealthCheckerConfig
|
||||
VPP VPPConfig
|
||||
HealthChecks map[string]HealthCheck
|
||||
@@ -123,7 +124,6 @@ type TCPParams struct {
|
||||
type Backend struct {
|
||||
Address net.IP
|
||||
HealthCheck string // name reference into Config.HealthChecks; "" = no probing, assume healthy
|
||||
SourceTag string // nginx source tag; defaults to the backend name if omitted from config
|
||||
Enabled bool // default true; false = exclude from serving entirely
|
||||
}
|
||||
|
||||
@@ -164,6 +164,7 @@ type rawConfig struct {
|
||||
}
|
||||
|
||||
type rawMaglev struct {
|
||||
SourceTag string `yaml:"source-tag"`
|
||||
HealthChecker rawHealthCheckerCfg `yaml:"healthchecker"`
|
||||
VPP rawVPPCfg `yaml:"vpp"`
|
||||
HealthChecks map[string]rawHealthCheck `yaml:"healthchecks"`
|
||||
@@ -219,8 +220,7 @@ type rawParams struct {
|
||||
type rawBackend struct {
|
||||
Address string `yaml:"address"`
|
||||
HealthCheck string `yaml:"healthcheck"`
|
||||
SourceTag string `yaml:"source-tag"` // defaults to backend name if omitted
|
||||
Enabled *bool `yaml:"enabled"` // nil → default true
|
||||
Enabled *bool `yaml:"enabled"` // nil → default true
|
||||
}
|
||||
|
||||
type rawPoolBackend struct {
|
||||
@@ -301,6 +301,18 @@ func parse(data []byte) (*Config, error) {
|
||||
func convert(r *rawMaglev) (*Config, error) {
|
||||
cfg := &Config{}
|
||||
|
||||
// ---- source-tag -----------------------------------------------------------
|
||||
cfg.SourceTag = r.SourceTag
|
||||
if cfg.SourceTag == "" {
|
||||
if h, err := os.Hostname(); err == nil {
|
||||
if dot := strings.IndexByte(h, '.'); dot > 0 {
|
||||
cfg.SourceTag = h[:dot]
|
||||
} else {
|
||||
cfg.SourceTag = h
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- healthchecker --------------------------------------------------------
|
||||
cfg.HealthChecker.Netns = r.HealthChecker.Netns
|
||||
cfg.HealthChecker.TransitionHistory = r.HealthChecker.TransitionHistory
|
||||
@@ -590,14 +602,9 @@ func convertBackend(name string, r *rawBackend, hcs map[string]HealthCheck) (Bac
|
||||
return Backend{}, fmt.Errorf("invalid address %q", r.Address)
|
||||
}
|
||||
|
||||
sourceTag := r.SourceTag
|
||||
if sourceTag == "" {
|
||||
sourceTag = name
|
||||
}
|
||||
b := Backend{
|
||||
Address: ip,
|
||||
HealthCheck: r.HealthCheck,
|
||||
SourceTag: sourceTag,
|
||||
Enabled: boolDefault(r.Enabled, true),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user