Merge pull request #287 from rosenhouse/multi-version
Plugins report a list of supported versions
This commit is contained in:
@ -22,6 +22,7 @@ import (
|
||||
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
)
|
||||
|
||||
const socketPath = "/run/cni/dhcp.sock"
|
||||
@ -30,7 +31,7 @@ func main() {
|
||||
if len(os.Args) > 1 && os.Args[1] == "daemon" {
|
||||
runDaemon()
|
||||
} else {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,10 +19,11 @@ import (
|
||||
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
)
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
||||
func cmdAdd(args *skel.CmdArgs) error {
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/utils"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
@ -354,5 +355,5 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/ns"
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
@ -171,5 +172,5 @@ func renameLink(curName, newName string) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/ns"
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
@ -67,5 +68,5 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/utils/sysctl"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
@ -193,5 +194,5 @@ func renameLink(curName, newName string) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/utils"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -236,5 +237,5 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/invoke"
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -249,5 +250,5 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import (
|
||||
"github.com/containernetworking/cni/pkg/ns"
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
)
|
||||
|
||||
// TuningConf represents the network tuning configuration.
|
||||
@ -78,5 +79,5 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.Legacy)
|
||||
}
|
||||
|
@ -24,11 +24,17 @@ import (
|
||||
|
||||
// Debug is used to control and record the behavior of the noop plugin
|
||||
type Debug struct {
|
||||
ReportResult string
|
||||
ReportError string
|
||||
ReportStderr string
|
||||
Command string
|
||||
CmdArgs skel.CmdArgs
|
||||
// Report* fields allow the test to control the behavior of the no-op plugin
|
||||
ReportResult string
|
||||
ReportError string
|
||||
ReportStderr string
|
||||
ReportVersionSupport []string
|
||||
|
||||
// Command stores the CNI command that the plugin received
|
||||
Command string
|
||||
|
||||
// CmdArgs stores the CNI Args and Env Vars that the plugin recieved
|
||||
CmdArgs skel.CmdArgs
|
||||
}
|
||||
|
||||
// ReadDebug will return a debug file recorded by the noop plugin
|
||||
|
@ -28,6 +28,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
"github.com/containernetworking/cni/plugins/test/noop/debug"
|
||||
)
|
||||
|
||||
@ -62,6 +63,23 @@ func debugBehavior(args *skel.CmdArgs, command string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func debugGetSupportedVersions() []string {
|
||||
vers := []string{"0.-42.0", "0.1.0", "0.2.0"}
|
||||
cniArgs := os.Getenv("CNI_ARGS")
|
||||
if cniArgs == "" {
|
||||
return vers
|
||||
}
|
||||
debugFilePath := strings.TrimPrefix(cniArgs, "DEBUG=")
|
||||
debug, err := debug.ReadDebug(debugFilePath)
|
||||
if err != nil {
|
||||
panic("test setup error: unable to read debug file: " + err.Error())
|
||||
}
|
||||
if debug.ReportVersionSupport == nil {
|
||||
return vers
|
||||
}
|
||||
return debug.ReportVersionSupport
|
||||
}
|
||||
|
||||
func cmdAdd(args *skel.CmdArgs) error {
|
||||
return debugBehavior(args, "ADD")
|
||||
}
|
||||
@ -71,5 +89,6 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
func main() {
|
||||
skel.PluginMain(cmdAdd, cmdDel)
|
||||
supportedVersions := debugGetSupportedVersions()
|
||||
skel.PluginMain(cmdAdd, cmdDel, version.PluginSupports(supportedVersions...))
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
noop_debug "github.com/containernetworking/cni/plugins/test/noop/debug"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -38,7 +39,10 @@ var _ = Describe("No-op plugin", func() {
|
||||
const reportResult = `{ "ip4": { "ip": "10.1.2.3/24" }, "dns": {} }`
|
||||
|
||||
BeforeEach(func() {
|
||||
debug = &noop_debug.Debug{ReportResult: reportResult}
|
||||
debug = &noop_debug.Debug{
|
||||
ReportResult: reportResult,
|
||||
ReportVersionSupport: []string{"0.1.0", "0.2.0", "0.3.0"},
|
||||
}
|
||||
|
||||
debugFile, err := ioutil.TempFile("", "cni_debug")
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
@ -122,6 +126,25 @@ var _ = Describe("No-op plugin", func() {
|
||||
Expect(debug.Command).To(Equal("DEL"))
|
||||
Expect(debug.CmdArgs).To(Equal(expectedCmdArgs))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when the CNI_COMMAND is VERSION", func() {
|
||||
BeforeEach(func() {
|
||||
cmd.Env[0] = "CNI_COMMAND=VERSION"
|
||||
debug.ReportVersionSupport = []string{"0.123.0", "0.2.0"}
|
||||
|
||||
Expect(debug.WriteDebug(debugFileName)).To(Succeed())
|
||||
})
|
||||
|
||||
It("claims to support the specified versions", func() {
|
||||
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Eventually(session).Should(gexec.Exit(0))
|
||||
decoder := &version.PluginDecoder{}
|
||||
pluginInfo, err := decoder.Decode(session.Out.Contents())
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(pluginInfo.SupportedVersions()).To(ConsistOf(
|
||||
"0.123.0", "0.2.0"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user