mirror of
https://github.com/containers/podman.git
synced 2025-07-01 16:17:06 +08:00
Upgrade OCICNI vendor
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
This commit is contained in:
24
vendor/github.com/cri-o/ocicni/pkg/ocicni/noop.go
generated
vendored
24
vendor/github.com/cri-o/ocicni/pkg/ocicni/noop.go
generated
vendored
@ -1,24 +0,0 @@
|
|||||||
package ocicni
|
|
||||||
|
|
||||||
type cniNoOp struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
func (noop *cniNoOp) Name() string {
|
|
||||||
return "CNINoOp"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (noop *cniNoOp) SetUpPod(network PodNetwork) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (noop *cniNoOp) TearDownPod(network PodNetwork) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (noop *cniNoOp) GetPodNetworkStatus(network PodNetwork) (string, error) {
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (noop *cniNoOp) Status() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
66
vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go
generated
vendored
66
vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go
generated
vendored
@ -3,6 +3,7 @@ package ocicni
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -139,33 +140,11 @@ func (plugin *cniNetworkPlugin) monitorNetDir() {
|
|||||||
<-plugin.monitorNetDirChan
|
<-plugin.monitorNetDirChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitCNI takes the plugin directory and cni directories where the cni files should be searched for
|
// InitCNI takes the plugin directory and CNI directories where the CNI config
|
||||||
// Returns a valid plugin object and any error
|
// files should be searched for. If no valid CNI configs exist, network requests
|
||||||
|
// will fail until valid CNI config files are present in the config directory.
|
||||||
func InitCNI(pluginDir string, cniDirs ...string) (CNIPlugin, error) {
|
func InitCNI(pluginDir string, cniDirs ...string) (CNIPlugin, error) {
|
||||||
plugin := probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, cniDirs, "")
|
vendorCNIDirPrefix := ""
|
||||||
var err error
|
|
||||||
plugin.nsenterPath, err = exec.LookPath("nsenter")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if a default network exists, otherwise dump the CNI search and return a noop plugin
|
|
||||||
_, err = getDefaultCNINetwork(plugin.pluginDir, plugin.cniDirs, plugin.vendorCNIDirPrefix)
|
|
||||||
if err != nil {
|
|
||||||
if err != errMissingDefaultNetwork {
|
|
||||||
logrus.Warningf("Error in finding usable CNI plugin - %v", err)
|
|
||||||
// create a noop plugin instead
|
|
||||||
return &cniNoOp{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// We do not have a default network, we start the monitoring thread.
|
|
||||||
go plugin.monitorNetDir()
|
|
||||||
}
|
|
||||||
|
|
||||||
return plugin, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir string, cniDirs []string, vendorCNIDirPrefix string) *cniNetworkPlugin {
|
|
||||||
plugin := &cniNetworkPlugin{
|
plugin := &cniNetworkPlugin{
|
||||||
defaultNetwork: nil,
|
defaultNetwork: nil,
|
||||||
loNetwork: getLoNetwork(cniDirs, vendorCNIDirPrefix),
|
loNetwork: getLoNetwork(cniDirs, vendorCNIDirPrefix),
|
||||||
@ -176,11 +155,26 @@ func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir string, cniDirs []strin
|
|||||||
pods: make(map[string]*podLock),
|
pods: make(map[string]*podLock),
|
||||||
}
|
}
|
||||||
|
|
||||||
// sync NetworkConfig in best effort during probing.
|
var err error
|
||||||
if err := plugin.syncNetworkConfig(); err != nil {
|
plugin.nsenterPath, err = exec.LookPath("nsenter")
|
||||||
logrus.Error(err)
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return plugin
|
|
||||||
|
// Fail loudly if plugin directory doesn't exist, because fsnotify watcher
|
||||||
|
// won't be able to watch it.
|
||||||
|
if _, err := os.Stat(pluginDir); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := plugin.syncNetworkConfig(); err != nil {
|
||||||
|
// We do not have a valid default network, so start the
|
||||||
|
// monitoring thread. Network setup/teardown requests
|
||||||
|
// will fail until we have a valid default network.
|
||||||
|
go plugin.monitorNetDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
return plugin, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultCNINetwork(pluginDir string, cniDirs []string, vendorCNIDirPrefix string) (*cniNetwork, error) {
|
func getDefaultCNINetwork(pluginDir string, cniDirs []string, vendorCNIDirPrefix string) (*cniNetwork, error) {
|
||||||
@ -308,9 +302,9 @@ func (plugin *cniNetworkPlugin) Name() string {
|
|||||||
return CNIPluginName
|
return CNIPluginName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) error {
|
func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) (cnitypes.Result, error) {
|
||||||
if err := plugin.checkInitialized(); err != nil {
|
if err := plugin.checkInitialized(); err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.podLock(podNetwork).Lock()
|
plugin.podLock(podNetwork).Lock()
|
||||||
@ -319,16 +313,16 @@ func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) error {
|
|||||||
_, err := plugin.loNetwork.addToNetwork(podNetwork)
|
_, err := plugin.loNetwork.addToNetwork(podNetwork)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Error while adding to cni lo network: %s", err)
|
logrus.Errorf("Error while adding to cni lo network: %s", err)
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = plugin.getDefaultNetwork().addToNetwork(podNetwork)
|
result, err := plugin.getDefaultNetwork().addToNetwork(podNetwork)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("Error while adding to cni network: %s", err)
|
logrus.Errorf("Error while adding to cni network: %s", err)
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *cniNetworkPlugin) TearDownPod(podNetwork PodNetwork) error {
|
func (plugin *cniNetworkPlugin) TearDownPod(podNetwork PodNetwork) error {
|
||||||
|
6
vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go
generated
vendored
6
vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go
generated
vendored
@ -1,5 +1,9 @@
|
|||||||
package ocicni
|
package ocicni
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/containernetworking/cni/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// DefaultInterfaceName is the string to be used for the interface name inside the net namespace
|
// DefaultInterfaceName is the string to be used for the interface name inside the net namespace
|
||||||
DefaultInterfaceName = "eth0"
|
DefaultInterfaceName = "eth0"
|
||||||
@ -49,7 +53,7 @@ type CNIPlugin interface {
|
|||||||
// SetUpPod is the method called after the sandbox container of
|
// SetUpPod is the method called after the sandbox container of
|
||||||
// the pod has been created but before the other containers of the
|
// the pod has been created but before the other containers of the
|
||||||
// pod are launched.
|
// pod are launched.
|
||||||
SetUpPod(network PodNetwork) error
|
SetUpPod(network PodNetwork) (types.Result, error)
|
||||||
|
|
||||||
// TearDownPod is the method called before a pod's sandbox container will be deleted
|
// TearDownPod is the method called before a pod's sandbox container will be deleted
|
||||||
TearDownPod(network PodNetwork) error
|
TearDownPod(network PodNetwork) error
|
||||||
|
Reference in New Issue
Block a user