示例#1
0
// Run CNI IPAM for the container, either allocating an IP address and returning
// it (for ADD) or releasing the lease and cleaning up (for DEL)
func (m *podManager) runIPAM(netnsPath string, action cniserver.CNICommand, id string) (*cnitypes.Result, error) {
	args := &invoke.Args{
		Command:     string(action),
		ContainerID: id,
		NetNS:       netnsPath,
		IfName:      podInterfaceName,
		Path:        "/opt/cni/bin",
	}

	if action == cniserver.CNI_ADD {
		result, err := invoke.ExecPluginWithResult("/opt/cni/bin/host-local", m.ipamConfig, args)
		if err != nil {
			return nil, fmt.Errorf("failed to run CNI IPAM ADD: %v", err)
		}

		if result.IP4 == nil {
			return nil, fmt.Errorf("failed to obtain IP address from CNI IPAM")
		}

		return result, nil
	} else if action == cniserver.CNI_DEL {
		err := invoke.ExecPluginWithoutResult("/opt/cni/bin/host-local", m.ipamConfig, args)
		if err != nil {
			return nil, fmt.Errorf("failed to run CNI IPAM DEL: %v", err)
		}
		return nil, nil
	}

	return nil, fmt.Errorf("invalid IPAM action %v", action)
}
示例#2
0
// Run CNI IPAM release for the container
func (m *podManager) ipamDel(id string) error {
	args := createIPAMArgs("", cniserver.CNI_DEL, id)
	err := invoke.ExecPluginWithoutResult("/opt/cni/bin/host-local", m.ipamConfig, args)
	if err != nil {
		return fmt.Errorf("failed to run CNI IPAM DEL: %v", err)
	}
	return nil
}
示例#3
0
func (c *CNIConfig) DelNetwork(net *NetworkConfig, rt *RuntimeConf) error {
	pluginPath, err := invoke.FindInPath(net.Network.Type, c.Path)
	if err != nil {
		return err
	}

	return invoke.ExecPluginWithoutResult(pluginPath, net.Bytes, c.args("DEL", rt))
}