Skip to content

Commit d19315c

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 d19315c

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

ipamapi/contract.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,7 @@ type Ipam interface {
7878

7979
// Capability represents the requirements and capabilities of the IPAM driver
8080
type Capability struct {
81-
RequiresMACAddress bool
81+
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
@@ -22,12 +22,17 @@ func (r *Response) GetError() string {
2222
// GetCapabilityResponse is the response of GetCapability request
2323
type GetCapabilityResponse struct {
2424
Response
25-
RequiresMACAddress bool
25+
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}
32+
return &ipamapi.Capability{
33+
RequiresMACAddress: capRes.RequiresMACAddress,
34+
RequiresEndpointInfo: capRes.RequiresEndpointInfo,
35+
RequiresNetworkInfo: capRes.RequiresNetworkInfo}
3136
}
3237

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

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+
// NetworkName constant represents the network name
28+
NetworkName = Prefix + ".name"
29+
30+
// NetworkID constant represents the network ID
31+
NetworkID = Prefix + ".id"
32+
33+
// NetworkType constant represents the network type/driver name
34+
NetworkType = Prefix + ".type"
35+
36+
// EndpointName constant represents the endpoint/container name
37+
EndpointName = Prefix + ".endpoint.name"
38+
39+
// EndpointHost constant represents the 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)