versioning: plugins report a list of supported versions
Further progress on versioning support (Issue #266). Bump CNI spec version to 0.3.0
This commit is contained in:
@ -19,6 +19,7 @@ import (
|
||||
|
||||
"github.com/containernetworking/cni/pkg/invoke"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
)
|
||||
|
||||
type RuntimeConf struct {
|
||||
@ -60,6 +61,17 @@ func (c *CNIConfig) DelNetwork(net *NetworkConfig, rt *RuntimeConf) error {
|
||||
return invoke.ExecPluginWithoutResult(pluginPath, net.Bytes, c.args("DEL", rt))
|
||||
}
|
||||
|
||||
func (c *CNIConfig) GetVersionInfo(pluginType string) (version.PluginInfo, error) {
|
||||
pluginPath, err := invoke.FindInPath(pluginType, c.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: if error is because plugin is old and VERSION command is unrecognized
|
||||
// then do the right thing and return version.PluginSupports("0.1.0"), nil
|
||||
return invoke.ExecPluginForVersion(pluginPath)
|
||||
}
|
||||
|
||||
// =====
|
||||
func (c *CNIConfig) args(action string, rt *RuntimeConf) *invoke.Args {
|
||||
return &invoke.Args{
|
||||
|
@ -155,4 +155,23 @@ var _ = Describe("Invoking the plugin", func() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("GetVersionInfo", func() {
|
||||
It("executes the plugin with the command VERSION", func() {
|
||||
versionInfo, err := cniConfig.GetVersionInfo("noop")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
Expect(versionInfo).NotTo(BeNil())
|
||||
Expect(versionInfo.SupportedVersions()).To(Equal([]string{
|
||||
"0.-42.0", "0.1.0", "0.2.0", "0.3.0",
|
||||
}))
|
||||
})
|
||||
|
||||
Context("when finding the plugin fails", func() {
|
||||
It("returns the error", func() {
|
||||
_, err := cniConfig.GetVersionInfo("does-not-exist")
|
||||
Expect(err).To(MatchError(ContainSubstring(`failed to find plugin "does-not-exist"`)))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user