Skip to content

Commit 337da7e

Browse files
committed
Allow publishing of additional information to IPAM
Adds an IPAM driver capability that allows libnetwork to send additional information during subnet and address allocation. Signed-off-by: John Belamaric <[email protected]>
1 parent 9994ce1 commit 337da7e

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

ipamapi/contract.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ type Ipam interface {
7979
// Capability represents the requirements and capabilities of the IPAM driver
8080
type Capability struct {
8181
RequiresMACAddress bool
82+
RequiresEndpointInfo bool
83+
RequiresNetworkInfo bool
8284
}

ipams/remote/api/api.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ func (r *Response) GetError() string {
2323
type GetCapabilityResponse struct {
2424
Response
2525
RequiresMACAddress bool
26+
RequiresEndpointInfo bool
27+
RequiresNetworkInfo bool
2628
}
2729

2830
// ToCapability converts the capability response into the internal ipam driver capaility structure
2931
func (capRes GetCapabilityResponse) ToCapability() *ipamapi.Capability {
30-
return &ipamapi.Capability{RequiresMACAddress: capRes.RequiresMACAddress}
31-
}
32+
return &ipamapi.Capability{
33+
RequiresMACAddress: capRes.RequiresMACAddress,
34+
RequiresEndpointInfo: capRes.RequiresEndpointInfo,
35+
RequiresNetworkInfo: capRes.RequiresNetworkInfo}
36+
}
3237

3338
// GetAddressSpacesResponse is the response to the ``get default address spaces`` request message
3439
type GetAddressSpacesResponse struct {

netlabel/labels.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ const (
2424
// MacAddress constant represents Mac Address config of a Container
2525
MacAddress = Prefix + ".endpoint.macaddress"
2626

27+
// Network name
28+
NetworkName = Prefix + ".name"
29+
30+
// Network ID
31+
NetworkID = Prefix + ".id"
32+
33+
// Network type
34+
NetworkType = Prefix + ".type"
35+
36+
// Endpoint name
37+
EndpointName = Prefix + ".endpoint.name"
38+
39+
// Endpoint cluster host ID
40+
EndpointHost = Prefix + ".endpoint.cluster_host_id"
41+
2742
// ExposedPorts constant represents the container's Exposed Ports
2843
ExposedPorts = Prefix + ".endpoint.exposedports"
2944

network.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
736736
ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
737737
}
738738

739+
if ipam.capability.RequiresEndpointInfo {
740+
if ep.ipamOptions == nil {
741+
ep.ipamOptions = make(map[string]string)
742+
}
743+
log.Debugf("Endpoint: %s", ep)
744+
ep.ipamOptions[netlabel.EndpointName] = name
745+
ep.ipamOptions[netlabel.EndpointHost] = ep.locator
746+
}
747+
739748
if err = ep.assignAddress(ipam.driver, true, !n.postIPv6); err != nil {
740749
return nil, err
741750
}
@@ -1009,6 +1018,20 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
10091018

10101019
*infoList = make([]*IpamInfo, len(*cfgList))
10111020

1021+
id, err := n.getController().getIPAM(n.ipamType)
1022+
if err != nil {
1023+
return err
1024+
}
1025+
1026+
if id.capability.RequiresNetworkInfo {
1027+
if n.ipamOptions == nil {
1028+
n.ipamOptions = make(map[string]string)
1029+
}
1030+
n.ipamOptions[netlabel.NetworkName] = n.Name()
1031+
n.ipamOptions[netlabel.NetworkID] = n.ID()
1032+
n.ipamOptions[netlabel.NetworkType] = n.Type()
1033+
}
1034+
10121035
log.Debugf("Allocating IPv%d pools for network %s (%s)", ipVer, n.Name(), n.ID())
10131036

10141037
for i, cfg := range *cfgList {

0 commit comments

Comments
 (0)