mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
interpolate network.dns block on client (#12021)
This commit is contained in:
3
.changelog/12021.txt
Normal file
3
.changelog/12021.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
```release-note:improvement
|
||||||
|
client: Allow interpolation of the network.dns block
|
||||||
|
```
|
||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
//
|
//
|
||||||
// Current interoperable fields:
|
// Current interoperable fields:
|
||||||
// - Hostname
|
// - Hostname
|
||||||
|
// - DNS
|
||||||
func InterpolateNetworks(taskEnv *TaskEnv, networks structs.Networks) structs.Networks {
|
func InterpolateNetworks(taskEnv *TaskEnv, networks structs.Networks) structs.Networks {
|
||||||
|
|
||||||
// Guard against not having a valid taskEnv. This can be the case if the
|
// 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.
|
// Iterate the copy and perform the interpolation.
|
||||||
for i := range interpolated {
|
for i := range interpolated {
|
||||||
interpolated[i].Hostname = taskEnv.ReplaceEnv(interpolated[i].Hostname)
|
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
|
return interpolated
|
||||||
|
|||||||
@@ -34,6 +34,50 @@ func Test_InterpolateNetworks(t *testing.T) {
|
|||||||
},
|
},
|
||||||
name: "interpolated hostname",
|
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 {
|
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
|
- `searches` `(array<string>: nil)` - Sets the search list for hostname lookup
|
||||||
- `options` `(array<string>: nil)` - Sets internal resolver variables.
|
- `options` `(array<string>: nil)` - Sets internal resolver variables.
|
||||||
|
|
||||||
|
These parameters support [interpolation](/docs/runtime/interpolation).
|
||||||
|
|
||||||
## `network` Examples
|
## `network` Examples
|
||||||
|
|
||||||
The following examples only show the `network` stanzas. Remember that the
|
The following examples only show the `network` stanzas. Remember that the
|
||||||
|
|||||||
Reference in New Issue
Block a user