mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
libnetwork: provide endpoint name for IPAM drivers
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
This commit is contained in:
@@ -362,6 +362,34 @@ func TestAuxAddresses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointNameLabel(t *testing.T) {
|
||||
skip.If(t, runtime.GOOS == "windows", "test causes sync issue with Windows HNS")
|
||||
defer netnsutils.SetupTestOSContext(t)()
|
||||
|
||||
c, err := New(context.Background(), config.OptionDataDir(t.TempDir()))
|
||||
assert.NilError(t, err)
|
||||
defer c.Stop()
|
||||
|
||||
ipamOpt := NetworkOptionIpam(defaultipam.DriverName, "", []*IpamConf{{PreferredPool: "10.35.0.0/16", Gateway: "10.35.255.253"}}, nil, nil)
|
||||
gnw, err := c.NewNetwork(context.Background(), "bridge", "label-test", "",
|
||||
NetworkOptionEnableIPv4(true),
|
||||
ipamOpt,
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
defer func() {
|
||||
err := gnw.Delete()
|
||||
assert.NilError(t, err)
|
||||
}()
|
||||
|
||||
createOptions := CreateOptionIPAM(net.ParseIP("10.35.0.10"), nil, nil)
|
||||
ep, err := gnw.CreateEndpoint(context.Background(), "ep1", createOptions)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Check(t, is.Equal(ep.ipamOptions[netlabel.EndpointName], "ep1"), "got: %s; expected: ep1", ep.ipamOptions[netlabel.EndpointName])
|
||||
|
||||
defer ep.Delete(context.Background(), false) //nolint:errcheck
|
||||
}
|
||||
|
||||
func TestUpdateSvcRecord(t *testing.T) {
|
||||
skip.If(t, runtime.GOOS == "windows", "bridge driver and IPv6, only works on linux")
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ const (
|
||||
// DNSServers A list of DNS servers associated with the endpoint
|
||||
DNSServers = Prefix + ".endpoint.dnsservers"
|
||||
|
||||
// EndpointName constant represents the container's Name
|
||||
EndpointName = Prefix + ".endpoint.name"
|
||||
|
||||
// EndpointSysctls is a comma separated list interface-specific sysctls
|
||||
// where the interface name is represented by the string "IFNAME".
|
||||
EndpointSysctls = Prefix + ".endpoint.sysctls"
|
||||
|
||||
@@ -1217,13 +1217,11 @@ func (n *Network) createEndpoint(ctx context.Context, name string, options ...En
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ep.ipamOptions = map[string]string{netlabel.EndpointName: name}
|
||||
if capability.RequiresMACAddress {
|
||||
if ep.iface.mac == nil {
|
||||
ep.iface.mac = netutils.GenerateRandomMAC()
|
||||
}
|
||||
if ep.ipamOptions == nil {
|
||||
ep.ipamOptions = make(map[string]string)
|
||||
}
|
||||
ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user