plugins: update to spec version 1.0.0
Signed-off-by: Dan Williams <dcbw@redhat.com>
This commit is contained in:
@@ -189,7 +189,7 @@ func consumeScratchNetConf(containerID, dataDir string) (func(error), []byte, er
|
||||
return cleanup, netConfBytes, err
|
||||
}
|
||||
|
||||
func delegateAdd(cid, dataDir string, netconf map[string]interface{}) error {
|
||||
func delegateAdd(cid, dataDir, cniVersion string, netconf map[string]interface{}) error {
|
||||
netconfBytes, err := json.Marshal(netconf)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error serializing delegate netconf: %v", err)
|
||||
@@ -205,7 +205,7 @@ func delegateAdd(cid, dataDir string, netconf map[string]interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return result.Print()
|
||||
return types.PrintResult(result, cniVersion)
|
||||
}
|
||||
|
||||
func hasKey(m map[string]interface{}, k string) bool {
|
||||
@@ -247,7 +247,10 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
n.Delegate["runtimeConfig"] = n.RuntimeConfig
|
||||
}
|
||||
|
||||
return doCmdAdd(args, n, fenv)
|
||||
// Delegate CNI config version must match flannel plugin config version
|
||||
n.Delegate["cniVersion"] = n.CNIVersion
|
||||
|
||||
return doCmdAdd(args, n.CNIVersion, n, fenv)
|
||||
}
|
||||
|
||||
func cmdDel(args *skel.CmdArgs) error {
|
||||
|
||||
@@ -72,7 +72,7 @@ func getDelegateIPAM(n *NetConf, fenv *subnetEnv) (map[string]interface{}, error
|
||||
return ipam, nil
|
||||
}
|
||||
|
||||
func doCmdAdd(args *skel.CmdArgs, n *NetConf, fenv *subnetEnv) error {
|
||||
func doCmdAdd(args *skel.CmdArgs, cniVersion string, n *NetConf, fenv *subnetEnv) error {
|
||||
n.Delegate["name"] = n.Name
|
||||
|
||||
if !hasKey(n.Delegate, "type") {
|
||||
@@ -105,7 +105,7 @@ func doCmdAdd(args *skel.CmdArgs, n *NetConf, fenv *subnetEnv) error {
|
||||
}
|
||||
n.Delegate["ipam"] = ipam
|
||||
|
||||
return delegateAdd(args.ContainerID, n.DataDir, n.Delegate)
|
||||
return delegateAdd(args.ContainerID, n.DataDir, cniVersion, n.Delegate)
|
||||
}
|
||||
|
||||
func doCmdDel(args *skel.CmdArgs, n *NetConf) (err error) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/containernetworking/cni/pkg/skel"
|
||||
"github.com/containernetworking/cni/pkg/types/current"
|
||||
current "github.com/containernetworking/cni/pkg/types/100"
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
"github.com/containernetworking/plugins/pkg/testutils"
|
||||
|
||||
@@ -50,12 +50,12 @@ var _ = Describe("Flannel", func() {
|
||||
Expect(originalNS.Close()).To(Succeed())
|
||||
})
|
||||
|
||||
const inputTemplate = `
|
||||
{
|
||||
"name": "cni-flannel",
|
||||
"type": "flannel",
|
||||
"subnetFile": "%s",
|
||||
"dataDir": "%s"%s
|
||||
const inputTemplate = `{
|
||||
"name": "cni-flannel",
|
||||
"type": "flannel",
|
||||
"cniVersion": "%s",
|
||||
"subnetFile": "%s",
|
||||
"dataDir": "%s"%s
|
||||
}`
|
||||
|
||||
const inputIPAMTemplate = `
|
||||
@@ -120,7 +120,7 @@ FLANNEL_IPMASQ=true
|
||||
ipamPart = ",\n \"ipam\":\n" + inputIPAM
|
||||
}
|
||||
|
||||
return fmt.Sprintf(inputTemplate, subnetFile, dataDir, ipamPart)
|
||||
return fmt.Sprintf(inputTemplate, current.ImplementedSpecVersion, subnetFile, dataDir, ipamPart)
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
@@ -176,7 +176,8 @@ FLANNEL_IPMASQ=true
|
||||
|
||||
netConfBytes, err := ioutil.ReadFile(path)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
expected := `{
|
||||
expected := fmt.Sprintf(`{
|
||||
"cniVersion": "%s",
|
||||
"ipMasq": false,
|
||||
"ipam": {
|
||||
"routes": [
|
||||
@@ -195,8 +196,7 @@ FLANNEL_IPMASQ=true
|
||||
"mtu": 1472,
|
||||
"name": "cni-flannel",
|
||||
"type": "bridge"
|
||||
}
|
||||
`
|
||||
}`, current.ImplementedSpecVersion)
|
||||
Expect(netConfBytes).Should(MatchJSON(expected))
|
||||
|
||||
result, err := current.NewResultFromResult(resI)
|
||||
@@ -255,7 +255,8 @@ FLANNEL_IPMASQ=true
|
||||
|
||||
netConfBytes, err := ioutil.ReadFile(path)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
expected := `{
|
||||
expected := fmt.Sprintf(`{
|
||||
"cniVersion": "%s",
|
||||
"ipMasq": false,
|
||||
"ipam": {
|
||||
"routes": [
|
||||
@@ -274,8 +275,7 @@ FLANNEL_IPMASQ=true
|
||||
"mtu": 1472,
|
||||
"name": "cni-flannel",
|
||||
"type": "bridge"
|
||||
}
|
||||
`
|
||||
}`, current.ImplementedSpecVersion)
|
||||
Expect(netConfBytes).Should(MatchJSON(expected))
|
||||
|
||||
result, err := current.NewResultFromResult(resI)
|
||||
@@ -334,7 +334,8 @@ FLANNEL_IPMASQ=true
|
||||
|
||||
netConfBytes, err := ioutil.ReadFile(path)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
expected := `{
|
||||
expected := fmt.Sprintf(`{
|
||||
"cniVersion": "%s",
|
||||
"ipMasq": false,
|
||||
"ipam": {
|
||||
"routes": [
|
||||
@@ -359,8 +360,7 @@ FLANNEL_IPMASQ=true
|
||||
"mtu": 1472,
|
||||
"name": "cni-flannel",
|
||||
"type": "bridge"
|
||||
}
|
||||
`
|
||||
}`, current.ImplementedSpecVersion)
|
||||
Expect(netConfBytes).Should(MatchJSON(expected))
|
||||
|
||||
result, err := current.NewResultFromResult(resI)
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func doCmdAdd(args *skel.CmdArgs, n *NetConf, fenv *subnetEnv) error {
|
||||
func doCmdAdd(args *skel.CmdArgs, cniVersion string, n *NetConf, fenv *subnetEnv) error {
|
||||
n.Delegate["name"] = n.Name
|
||||
|
||||
if !hasKey(n.Delegate, "type") {
|
||||
@@ -52,7 +52,8 @@ func doCmdAdd(args *skel.CmdArgs, n *NetConf, fenv *subnetEnv) error {
|
||||
"subnet": fenv.sn.String(),
|
||||
}
|
||||
|
||||
return delegateAdd(hns.GetSandboxContainerID(args.ContainerID, args.Netns), n.DataDir, n.Delegate)
|
||||
sandboxID := hns.GetSandboxContainerID(args.ContainerID, args.Netns)
|
||||
return delegateAdd(sandboxID, n.DataDir, cniVersion, n.Delegate)
|
||||
}
|
||||
|
||||
func doCmdDel(args *skel.CmdArgs, n *NetConf) (err error) {
|
||||
|
||||
Reference in New Issue
Block a user