Skip to content

Commit da5610c

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 da5610c

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
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+
RequiresEndpointID bool
83+
RequiresNetworkID bool
8284
}

ipams/remote/api/api.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ func (r *Response) GetError() string {
2323
type GetCapabilityResponse struct {
2424
Response
2525
RequiresMACAddress bool
26+
RequiresEndpointID bool
27+
RequiresNetworkID 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}
32+
return &ipamapi.Capability{
33+
RequiresMACAddress: capRes.RequiresMACAddress,
34+
RequiresEndpointID: capRes.RequiresEndpointID,
35+
RequiresNetworkID: capRes.RequiresNetworkID}
3136
}
3237

3338
// GetAddressSpacesResponse is the response to the ``get default address spaces`` request message

netlabel/labels.go

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

27+
// NetworkID constant represents the network ID
28+
NetworkID = Prefix + ".id"
29+
30+
// EndpointID constant represents the endpoint ID
31+
EndpointID = Prefix + ".endpoint.id"
32+
2733
// ExposedPorts constant represents the container's Exposed Ports
2834
ExposedPorts = Prefix + ".endpoint.exposedports"
2935

network.go

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

739+
if ipam.capability.RequiresEndpointID {
740+
if ep.ipamOptions == nil {
741+
ep.ipamOptions = make(map[string]string)
742+
}
743+
ep.ipamOptions[netlabel.EndpointID] = ep.id
744+
}
745+
739746
if err = ep.assignAddress(ipam.driver, true, !n.postIPv6); err != nil {
740747
return nil, err
741748
}
@@ -1009,6 +1016,18 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
10091016

10101017
*infoList = make([]*IpamInfo, len(*cfgList))
10111018

1019+
id, err := n.getController().getIPAM(n.ipamType)
1020+
if err != nil {
1021+
return err
1022+
}
1023+
1024+
if id.capability.RequiresNetworkID {
1025+
if n.ipamOptions == nil {
1026+
n.ipamOptions = make(map[string]string)
1027+
}
1028+
n.ipamOptions[netlabel.NetworkID] = n.ID()
1029+
}
1030+
10121031
log.Debugf("Allocating IPv%d pools for network %s (%s)", ipVer, n.Name(), n.ID())
10131032

10141033
for i, cfg := range *cfgList {

0 commit comments

Comments
 (0)