mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 08:55:43 +03:00
Restore AtlasConfig
This commit is contained in:
@@ -388,6 +388,14 @@ func (a *Config) Merge(b *Config) *Config {
|
||||
result.AdvertiseAddrs = result.AdvertiseAddrs.Merge(b.AdvertiseAddrs)
|
||||
}
|
||||
|
||||
// Apply the Atlas configuration
|
||||
if result.Atlas == nil && b.Atlas != nil {
|
||||
atlasConfig := *b.Atlas
|
||||
result.Atlas = &atlasConfig
|
||||
} else if b.Atlas != nil {
|
||||
result.Atlas = result.Atlas.Merge(b.Atlas)
|
||||
}
|
||||
|
||||
return &result
|
||||
}
|
||||
|
||||
@@ -549,6 +557,25 @@ func (a *AdvertiseAddrs) Merge(b *AdvertiseAddrs) *AdvertiseAddrs {
|
||||
return &result
|
||||
}
|
||||
|
||||
// Merge merges two Atlas configurations together.
|
||||
func (a *AtlasConfig) Merge(b *AtlasConfig) *AtlasConfig {
|
||||
var result AtlasConfig = *a
|
||||
|
||||
if b.Infrastructure != "" {
|
||||
result.Infrastructure = b.Infrastructure
|
||||
}
|
||||
if b.Token != "" {
|
||||
result.Token = b.Token
|
||||
}
|
||||
if b.Join {
|
||||
result.Join = true
|
||||
}
|
||||
if b.Endpoint != "" {
|
||||
result.Endpoint = b.Endpoint
|
||||
}
|
||||
return &result
|
||||
}
|
||||
|
||||
// LoadConfig loads the configuration at the given path, regardless if
|
||||
// its a file or directory.
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
|
||||
@@ -64,6 +64,12 @@ func TestConfig_Merge(t *testing.T) {
|
||||
RPC: "127.0.0.1",
|
||||
Serf: "127.0.0.1",
|
||||
},
|
||||
Atlas: &AtlasConfig{
|
||||
Infrastructure: "hashicorp/test1",
|
||||
Token: "abc",
|
||||
Join: false,
|
||||
Endpoint: "foo",
|
||||
},
|
||||
}
|
||||
|
||||
c2 := &Config{
|
||||
@@ -129,6 +135,12 @@ func TestConfig_Merge(t *testing.T) {
|
||||
RPC: "127.0.0.2",
|
||||
Serf: "127.0.0.2",
|
||||
},
|
||||
Atlas: &AtlasConfig{
|
||||
Infrastructure: "hashicorp/test2",
|
||||
Token: "xyz",
|
||||
Join: true,
|
||||
Endpoint: "bar",
|
||||
},
|
||||
}
|
||||
|
||||
result := c1.Merge(c2)
|
||||
|
||||
Reference in New Issue
Block a user