Store endpointId in CNI requests to track addresses back to their endpoints
This commit is contained in:
Родитель
e0f0e1ca5f
Коммит
0f34eb5c6a
|
@ -178,8 +178,12 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error {
|
|||
log.Printf("[cni-ipam] Allocated address poolID %v with subnet %v.", poolID, subnet)
|
||||
}
|
||||
|
||||
// Store the endpoint ID in address request.
|
||||
options := make(map[string]string)
|
||||
options[ipam.OptAddressID] = plugin.GetEndpointID(args)
|
||||
|
||||
// Allocate an address for the endpoint.
|
||||
address, err := plugin.am.RequestAddress(nwCfg.Ipam.AddrSpace, nwCfg.Ipam.Subnet, nwCfg.Ipam.Address, nil)
|
||||
address, err := plugin.am.RequestAddress(nwCfg.Ipam.AddrSpace, nwCfg.Ipam.Subnet, nwCfg.Ipam.Address, options)
|
||||
if err != nil {
|
||||
err = plugin.Errorf("Failed to allocate address: %v", err)
|
||||
return err
|
||||
|
|
|
@ -82,16 +82,6 @@ func (plugin *netPlugin) Stop() {
|
|||
log.Printf("[cni-net] Plugin stopped.")
|
||||
}
|
||||
|
||||
// GetEndpointID returns a unique endpoint ID based on the CNI args.
|
||||
func (plugin *netPlugin) getEndpointID(args *cniSkel.CmdArgs) string {
|
||||
containerID := args.ContainerID
|
||||
if len(containerID) > 8 {
|
||||
containerID = containerID[:8]
|
||||
}
|
||||
|
||||
return containerID + "-" + args.IfName
|
||||
}
|
||||
|
||||
// FindMasterInterface returns the name of the master interface.
|
||||
func (plugin *netPlugin) findMasterInterface(nwCfg *cni.NetworkConfig, subnetPrefix *net.IPNet) string {
|
||||
// An explicit master configuration wins. Explicitly specifying a master is
|
||||
|
@ -146,7 +136,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
|
|||
|
||||
// Initialize values from network config.
|
||||
networkId := nwCfg.Name
|
||||
endpointId := plugin.getEndpointID(args)
|
||||
endpointId := plugin.GetEndpointID(args)
|
||||
|
||||
// Check whether the network already exists.
|
||||
nwInfo, err := plugin.nm.GetNetworkInfo(networkId)
|
||||
|
@ -307,7 +297,7 @@ func (plugin *netPlugin) Delete(args *cniSkel.CmdArgs) error {
|
|||
|
||||
// Initialize values from network config.
|
||||
networkId := nwCfg.Name
|
||||
endpointId := plugin.getEndpointID(args)
|
||||
endpointId := plugin.GetEndpointID(args)
|
||||
|
||||
// Query the network.
|
||||
nwInfo, err := plugin.nm.GetNetworkInfo(networkId)
|
||||
|
|
|
@ -139,6 +139,16 @@ func (plugin *Plugin) DelegateDel(pluginName string, nwCfg *NetworkConfig) error
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetEndpointID returns a unique endpoint ID based on the CNI args.
|
||||
func (plugin *Plugin) GetEndpointID(args *cniSkel.CmdArgs) string {
|
||||
containerID := args.ContainerID
|
||||
if len(containerID) > 8 {
|
||||
containerID = containerID[:8]
|
||||
}
|
||||
|
||||
return containerID + "-" + args.IfName
|
||||
}
|
||||
|
||||
// Error creates and logs a structured CNI error.
|
||||
func (plugin *Plugin) Error(err error) *cniTypes.Error {
|
||||
var cniErr *cniTypes.Error
|
||||
|
|
Загрузка…
Ссылка в новой задаче