From 444afa65c5faa07d384e021a387880d0b4699203 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 11 Jan 2018 10:00:01 -0500 Subject: Upgrade OCICNI vendor Signed-off-by: Matthew Heon --- vendor/github.com/cri-o/ocicni/pkg/ocicni/noop.go | 24 -------- .../github.com/cri-o/ocicni/pkg/ocicni/ocicni.go | 64 ++++++++++------------ vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go | 6 +- 3 files changed, 34 insertions(+), 60 deletions(-) delete mode 100644 vendor/github.com/cri-o/ocicni/pkg/ocicni/noop.go diff --git a/vendor/github.com/cri-o/ocicni/pkg/ocicni/noop.go b/vendor/github.com/cri-o/ocicni/pkg/ocicni/noop.go deleted file mode 100644 index 9f315a7c6..000000000 --- a/vendor/github.com/cri-o/ocicni/pkg/ocicni/noop.go +++ /dev/null @@ -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 -} diff --git a/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go b/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go index 03918bfa4..8c7ce5571 100644 --- a/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go +++ b/vendor/github.com/cri-o/ocicni/pkg/ocicni/ocicni.go @@ -3,6 +3,7 @@ package ocicni import ( "errors" "fmt" + "os" "os/exec" "sort" "strings" @@ -139,33 +140,11 @@ func (plugin *cniNetworkPlugin) monitorNetDir() { <-plugin.monitorNetDirChan } -// InitCNI takes the plugin directory and cni directories where the cni files should be searched for -// Returns a valid plugin object and any error +// InitCNI takes the plugin directory and CNI directories where the CNI config +// 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) { - plugin := probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir, cniDirs, "") - 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 { + vendorCNIDirPrefix := "" plugin := &cniNetworkPlugin{ defaultNetwork: nil, loNetwork: getLoNetwork(cniDirs, vendorCNIDirPrefix), @@ -176,11 +155,26 @@ func probeNetworkPluginsWithVendorCNIDirPrefix(pluginDir string, cniDirs []strin pods: make(map[string]*podLock), } - // sync NetworkConfig in best effort during probing. + var err error + plugin.nsenterPath, err = exec.LookPath("nsenter") + if err != nil { + return nil, err + } + + // 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 { - logrus.Error(err) + // 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 + + return plugin, nil } func getDefaultCNINetwork(pluginDir string, cniDirs []string, vendorCNIDirPrefix string) (*cniNetwork, error) { @@ -308,9 +302,9 @@ func (plugin *cniNetworkPlugin) Name() string { return CNIPluginName } -func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) error { +func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) (cnitypes.Result, error) { if err := plugin.checkInitialized(); err != nil { - return err + return nil, err } plugin.podLock(podNetwork).Lock() @@ -319,16 +313,16 @@ func (plugin *cniNetworkPlugin) SetUpPod(podNetwork PodNetwork) error { _, err := plugin.loNetwork.addToNetwork(podNetwork) if err != nil { 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 { 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 { diff --git a/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go b/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go index a272e92e7..60816d179 100644 --- a/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go +++ b/vendor/github.com/cri-o/ocicni/pkg/ocicni/types.go @@ -1,5 +1,9 @@ package ocicni +import ( + "github.com/containernetworking/cni/pkg/types" +) + const ( // DefaultInterfaceName is the string to be used for the interface name inside the net namespace DefaultInterfaceName = "eth0" @@ -49,7 +53,7 @@ type CNIPlugin interface { // SetUpPod is the method called after the sandbox container of // the pod has been created but before the other containers of the // 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(network PodNetwork) error -- cgit v1.2.3-54-g00ecf From 5bc4d1d315b69a7aff60b049434e716eaccdeb05 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 11 Jan 2018 10:03:16 -0500 Subject: Fix build error after updating CNI vendor Signed-off-by: Matthew Heon --- libpod/networking.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libpod/networking.go b/libpod/networking.go index 456830708..6e82cba3f 100644 --- a/libpod/networking.go +++ b/libpod/networking.go @@ -38,7 +38,8 @@ func (r *Runtime) createNetNS(ctr *Container) (err error) { podNetwork := getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.PortMappings) - if err := r.netPlugin.SetUpPod(podNetwork); err != nil { + _, err := r.netPlugin.SetUpPod(podNetwork) + if err != nil { return errors.Wrapf(err, "error configuring network namespace for container %s", ctr.ID()) } -- cgit v1.2.3-54-g00ecf From 240e5789d409d82453b72f87862f7e71efa381e4 Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 11 Jan 2018 10:10:46 -0500 Subject: Update CNI plugin directories to search default location as well Signed-off-by: Matthew Heon --- libpod/networking.go | 2 +- libpod/options.go | 2 +- libpod/runtime.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libpod/networking.go b/libpod/networking.go index 6e82cba3f..41bd65d25 100644 --- a/libpod/networking.go +++ b/libpod/networking.go @@ -38,7 +38,7 @@ func (r *Runtime) createNetNS(ctr *Container) (err error) { podNetwork := getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.PortMappings) - _, err := r.netPlugin.SetUpPod(podNetwork) + _, err = r.netPlugin.SetUpPod(podNetwork) if err != nil { return errors.Wrapf(err, "error configuring network namespace for container %s", ctr.ID()) } diff --git a/libpod/options.go b/libpod/options.go index 199bf9ee9..081a20f37 100644 --- a/libpod/options.go +++ b/libpod/options.go @@ -275,7 +275,7 @@ func WithCNIPluginDir(dir string) RuntimeOption { return ErrRuntimeFinalized } - rt.config.CNIPluginDir = dir + rt.config.CNIPluginDir = []string{dir} return nil } diff --git a/libpod/runtime.go b/libpod/runtime.go index aed6acd86..d0aa481cf 100644 --- a/libpod/runtime.go +++ b/libpod/runtime.go @@ -51,7 +51,7 @@ type RuntimeConfig struct { MaxLogSize int64 NoPivotRoot bool CNIConfigDir string - CNIPluginDir string + CNIPluginDir []string } var ( @@ -73,7 +73,7 @@ var ( MaxLogSize: -1, NoPivotRoot: false, CNIConfigDir: "/etc/cni/net.d/", - CNIPluginDir: "/usr/libexec/cni", + CNIPluginDir: []string{"/usr/libexec/cni", "/opt/cni/bin"}, } ) @@ -173,7 +173,7 @@ func NewRuntime(options ...RuntimeOption) (runtime *Runtime, err error) { } // Set up the CNI net plugin - netPlugin, err := ocicni.InitCNI(runtime.config.CNIConfigDir, runtime.config.CNIPluginDir) + netPlugin, err := ocicni.InitCNI(runtime.config.CNIConfigDir, runtime.config.CNIPluginDir...) if err != nil { return nil, errors.Wrapf(err, "error configuring CNI network plugin") } -- cgit v1.2.3-54-g00ecf