interpolate network.dns block on client (#12021)
This commit is contained in:
parent
27bb2da5ee
commit
c30b4617aa
|
@ -0,0 +1,3 @@
|
|||
```release-note:improvement
|
||||
client: Allow interpolation of the network.dns block
|
||||
```
|
|
@ -9,6 +9,7 @@ import (
|
|||
//
|
||||
// Current interoperable fields:
|
||||
// - Hostname
|
||||
// - DNS
|
||||
func InterpolateNetworks(taskEnv *TaskEnv, networks structs.Networks) structs.Networks {
|
||||
|
||||
// Guard against not having a valid taskEnv. This can be the case if the
|
||||
|
@ -23,6 +24,11 @@ func InterpolateNetworks(taskEnv *TaskEnv, networks structs.Networks) structs.Ne
|
|||
// Iterate the copy and perform the interpolation.
|
||||
for i := range interpolated {
|
||||
interpolated[i].Hostname = taskEnv.ReplaceEnv(interpolated[i].Hostname)
|
||||
if interpolated[i].DNS != nil {
|
||||
interpolated[i].DNS.Servers = taskEnv.ParseAndReplace(interpolated[i].DNS.Servers)
|
||||
interpolated[i].DNS.Searches = taskEnv.ParseAndReplace(interpolated[i].DNS.Searches)
|
||||
interpolated[i].DNS.Options = taskEnv.ParseAndReplace(interpolated[i].DNS.Options)
|
||||
}
|
||||
}
|
||||
|
||||
return interpolated
|
||||
|
|
|
@ -34,6 +34,50 @@ func Test_InterpolateNetworks(t *testing.T) {
|
|||
},
|
||||
name: "interpolated hostname",
|
||||
},
|
||||
{
|
||||
inputTaskEnv: testEnv,
|
||||
inputNetworks: structs.Networks{
|
||||
{
|
||||
DNS: &structs.DNSConfig{
|
||||
Servers: []string{"127.0.0.1"},
|
||||
Options: []string{"some-opt"},
|
||||
Searches: []string{"example.com"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedOutputNetworks: structs.Networks{
|
||||
{
|
||||
DNS: &structs.DNSConfig{
|
||||
Servers: []string{"127.0.0.1"},
|
||||
Options: []string{"some-opt"},
|
||||
Searches: []string{"example.com"},
|
||||
},
|
||||
},
|
||||
},
|
||||
name: "non-interpolated dns servers",
|
||||
},
|
||||
{
|
||||
inputTaskEnv: testEnv,
|
||||
inputNetworks: structs.Networks{
|
||||
{
|
||||
DNS: &structs.DNSConfig{
|
||||
Servers: []string{"${foo}"},
|
||||
Options: []string{"${foo}-opt"},
|
||||
Searches: []string{"${foo}.example.com"},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedOutputNetworks: structs.Networks{
|
||||
{
|
||||
DNS: &structs.DNSConfig{
|
||||
Servers: []string{"bar"},
|
||||
Options: []string{"bar-opt"},
|
||||
Searches: []string{"bar.example.com"},
|
||||
},
|
||||
},
|
||||
},
|
||||
name: "interpolated dns servers",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
@ -120,6 +120,8 @@ The label of the port is just text - it has no special meaning to Nomad.
|
|||
- `searches` `(array<string>: nil)` - Sets the search list for hostname lookup
|
||||
- `options` `(array<string>: nil)` - Sets internal resolver variables.
|
||||
|
||||
These parameters support [interpolation](/docs/runtime/interpolation).
|
||||
|
||||
## `network` Examples
|
||||
|
||||
The following examples only show the `network` stanzas. Remember that the
|
||||
|
|
Loading…
Reference in New Issue