diff --git a/plugins/main/bridge/bridge.go b/plugins/main/bridge/bridge.go index 03d14e7ee..d0e8bcf25 100644 --- a/plugins/main/bridge/bridge.go +++ b/plugins/main/bridge/bridge.go @@ -56,9 +56,13 @@ type NetConf struct { PromiscMode bool `json:"promiscMode"` Vlan int `json:"vlan"` Mac string `json:"mac,omitempty"` + Args struct { Cni BridgeArgs `json:"cni,omitempty"` } `json:"args,omitempty"` + RuntimeConfig struct { + Mac string `json:"mac,omitempty"` + } `json:"runtimeConfig,omitempty"` } type BridgeArgs struct { @@ -110,6 +114,10 @@ func loadNetConf(bytes []byte, envArgs string) (*NetConf, string, error) { n.Mac = mac } + if mac := n.RuntimeConfig.Mac; mac != "" { + n.Mac = mac + } + return n, n.CNIVersion, nil } diff --git a/plugins/main/bridge/bridge_test.go b/plugins/main/bridge/bridge_test.go index f6c738b3a..658325330 100644 --- a/plugins/main/bridge/bridge_test.go +++ b/plugins/main/bridge/bridge_test.go @@ -174,6 +174,11 @@ const ( "mac": %q } }` + + runtimeConfig = `, + "RuntimeConfig": { + "mac": %q + }` ) // netConfJSON() generates a JSON network configuration string @@ -192,6 +197,9 @@ func (tc testCase) netConfJSON(dataDir string) string { if tc.args.cni.mac != "" { conf += fmt.Sprintf(argsFormat, tc.args.cni.mac) } + if tc.runtimeConfig.mac != "" { + conf += fmt.Sprintf(runtimeConfig, tc.runtimeConfig.mac) + } if !tc.isLayer2 { conf += netDefault @@ -2069,6 +2077,28 @@ var _ = Describe("bridge Operations", func() { Expect(err).NotTo(HaveOccurred()) }) + It(fmt.Sprintf("[%s] uses an explicit MAC addresses for the container iface (from RuntimeConfig)", ver), func() { + err := originalNS.Do(func(ns.NetNS) error { + defer GinkgoRecover() + + const expectedMac = "02:00:00:00:00:00" + tc := testCase{ + cniVersion: ver, + subnet: "10.1.2.0/24", + mac: "02:00:00:00:01:23", + envArgs: "MAC=" + "02:00:00:00:04:56", + + expectedMac: expectedMac, + } + tc.args.cni.mac = "02:00:00:00:07:89" + tc.runtimeConfig.mac = expectedMac + cmdAddDelTest(originalNS, targetNS, tc, dataDir) + + return nil + }) + Expect(err).NotTo(HaveOccurred()) + }) + It(fmt.Sprintf("[%s] checks ip release in case of error", ver), func() { err := originalNS.Do(func(ns.NetNS) error { defer GinkgoRecover()