allow configuration of Docker hostnames in bridge mode (#11173)

Add a new hostname string parameter to the network block which
allows operators to specify the hostname of the network namespace.
Changing this causes a destructive update to the allocation and it
is omitted if empty from API responses. This parameter also supports
interpolation.

In order to have a hostname passed as a configuration param when
creating an allocation network, the CreateNetwork func of the
DriverNetworkManager interface needs to be updated. In order to
minimize the disruption of future changes, rather than add another
string func arg, the function now accepts a request struct along with
the allocID param. The struct has the hostname as a field.

The in-tree implementations of DriverNetworkManager.CreateNetwork
have been modified to account for the function signature change.
In updating for the change, the enhancement of adding hostnames to
network namespaces has also been added to the Docker driver, whilst
the default Linux manager does not current implement it.
This commit is contained in:
James Rasell
2021-09-16 08:13:09 +02:00
committed by GitHub
parent b7d2da3a9e
commit e34fa583f9
31 changed files with 947 additions and 290 deletions

View File

@@ -1200,10 +1200,11 @@ func ApiNetworkResourceToStructs(in []*api.NetworkResource) []*structs.NetworkRe
out = make([]*structs.NetworkResource, len(in))
for i, nw := range in {
out[i] = &structs.NetworkResource{
Mode: nw.Mode,
CIDR: nw.CIDR,
IP: nw.IP,
MBits: nw.Megabits(),
Mode: nw.Mode,
CIDR: nw.CIDR,
IP: nw.IP,
Hostname: nw.Hostname,
MBits: nw.Megabits(),
}
if nw.DNS != nil {

View File

@@ -2210,8 +2210,9 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
MemoryMB: helper.IntToPtr(10),
Networks: []*api.NetworkResource{
{
IP: "10.10.11.1",
MBits: helper.IntToPtr(10),
IP: "10.10.11.1",
MBits: helper.IntToPtr(10),
Hostname: "foobar",
ReservedPorts: []api.Port{
{
Label: "http",
@@ -2602,8 +2603,9 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
MemoryMB: 10,
Networks: []*structs.NetworkResource{
{
IP: "10.10.11.1",
MBits: 10,
IP: "10.10.11.1",
MBits: 10,
Hostname: "foobar",
ReservedPorts: []structs.Port{
{
Label: "http",