Exemple #1
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))
}
Exemple #2
0
func (c *CNIConfig) AddNetwork(net *NetworkConfig, rt *RuntimeConf) (*types.Result, error) {
	pluginPath, err := invoke.FindInPath(net.Network.Type, c.Path)
	if err != nil {
		return nil, err
	}

	return invoke.ExecPluginWithResult(pluginPath, net.Bytes, c.args("ADD", rt))
}
Exemple #3
0
// GetVersionInfo reports which versions of the CNI spec are supported by
// the given plugin.
func (c *CNIConfig) GetVersionInfo(pluginType string) (version.PluginInfo, error) {
	pluginPath, err := invoke.FindInPath(pluginType, c.Path)
	if err != nil {
		return nil, err
	}

	return invoke.GetVersionInfo(pluginPath)
}
Exemple #4
0
// Find the proxied plugin from the CNI_PATH environment var
func findRealPlugin() string {
	pluginName := getArgOrFail("X_REAL_PLUGIN")
	paths := strings.Split(os.Getenv("CNI_PATH"), ":")

	pluginPath, err := invoke.FindInPath(pluginName, paths)

	if err != nil {
		fail("Could not find plugin in CNI_PATH", err)
	}
	return pluginPath
}
Exemple #5
0
	BeforeEach(func() {
		tempDir, err := ioutil.TempDir("", "cni-find")
		Expect(err).NotTo(HaveOccurred())

		plugin, err := ioutil.TempFile(tempDir, "a-cni-plugin")

		anotherTempDir, err = ioutil.TempDir("", "nothing-here")

		multiplePaths = []string{anotherTempDir, tempDir}
		pluginDir, pluginName = filepath.Split(plugin.Name())
	})

	Context("when multiple paths are provided", func() {
		It("returns only the path to the plugin", func() {
			pluginPath, err := invoke.FindInPath(pluginName, multiplePaths)
			Expect(err).NotTo(HaveOccurred())
			Expect(pluginPath).To(Equal(filepath.Join(pluginDir, pluginName)))
		})
	})

	Context("when an error occurs", func() {
		Context("when no paths are provided", func() {
			It("returns an error noting no paths were provided", func() {
				_, err := invoke.FindInPath(pluginName, []string{})
				Expect(err).To(MatchError("no paths provided"))
			})
		})

		Context("when no plugin is provided", func() {
			It("returns an error noting the plugin name wasn't found", func() {