api,libcni: add network config list-based plugin chaining

Using a new ".configlist" file format that allows specifying
a list of CNI network configurations to run, add new libcni
helper functions to call each plugin in the list, injecting
the overall name, CNI version, and previous plugin's Result
structure into the configuration of the next plugin.
This commit is contained in:
Dan Williams
2016-12-16 18:56:39 -06:00
parent 7e16c86a52
commit 0c2a034f01
7 changed files with 696 additions and 153 deletions

View File

@ -96,6 +96,45 @@ var _ = Describe("No-op plugin", func() {
Eventually(session).Should(gexec.Exit(2))
})
It("pass previous result through when ReportResult is PASSTHROUGH", func() {
debug = &noop_debug.Debug{ReportResult: "PASSTHROUGH"}
Expect(debug.WriteDebug(debugFileName)).To(Succeed())
cmd.Stdin = strings.NewReader(`{
"some":"stdin-json",
"cniVersion": "0.2.0",
"prevResult": {
"ip4": {"ip": "10.1.2.15/24"}
}
}`)
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(session.Out.Contents()).To(MatchJSON(`{"ip4": {"ip": "10.1.2.15/24"}, "dns": {}}`))
})
It("injects DNS into previous result when ReportResult is INJECT-DNS", func() {
debug = &noop_debug.Debug{ReportResult: "INJECT-DNS"}
Expect(debug.WriteDebug(debugFileName)).To(Succeed())
cmd.Stdin = strings.NewReader(`{
"some":"stdin-json",
"cniVersion": "0.2.0",
"prevResult": {
"ip4": {"ip": "10.1.2.3/24"},
"dns": {}
}
}`)
session, err := gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
Eventually(session).Should(gexec.Exit(0))
Expect(session.Out.Contents()).To(MatchJSON(`{
"ip4": {"ip": "10.1.2.3/24"},
"dns": {"nameservers": ["1.2.3.4"]}
}`))
})
It("allows passing debug file in config JSON", func() {
// Remove the DEBUG option from CNI_ARGS and regular args
newArgs := "FOO=BAR"