Skip to content

Commit 49fe545

Browse files
spicysharkcomlguerrero12
authored andcommitted
bridge: skip the IPAM CHECK when no IPAM plugin is configured
A bridge config without an ipam type is an L2-only network. ADD, DEL and STATUS already skip IPAM for it, but CHECK always called the IPAM plugin with an empty name and failed with "no plugin name provided" for a healthy L2-only bridge. Only call the IPAM plugin in CHECK when an ipam type is set, as macvlan, ipvlan, tap and host-device do. The remaining prevResult checks still run. Add an ADD/DEL/CHECK spec for an L2-only bridge and let cmdAddDelCheckTest skip the host-local config load for it. Signed-off-by: spicysharkco <321699413+spicysharkco@users.noreply.github.com>
1 parent f63af46 commit 49fe545

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

‎plugins/main/bridge/bridge.go‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,10 +1016,14 @@ func cmdCheck(args *skel.CmdArgs) error {
10161016
}
10171017
defer netns.Close()
10181018

1019-
// run the IPAM plugin and get back the config to apply
1020-
err = ipam.ExecCheck(n.IPAM.Type, args.StdinData)
1021-
if err != nil {
1022-
return err
1019+
isLayer3 := n.IPAM.Type != ""
1020+
1021+
if isLayer3 {
1022+
// run the IPAM plugin and get back the config to apply
1023+
err = ipam.ExecCheck(n.IPAM.Type, args.StdinData)
1024+
if err != nil {
1025+
return err
1026+
}
10231027
}
10241028

10251029
// Parse previous result.

‎plugins/main/bridge/bridge_test.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,8 +1835,10 @@ func cmdAddDelCheckTest(origNS, targetNS ns.NetNS, tc testCase, dataDir string)
18351835
err = json.Unmarshal([]byte(confString), &conf)
18361836
Expect(err).NotTo(HaveOccurred())
18371837

1838-
conf.IPAM, _, err = allocator.LoadIPAMConfig([]byte(confString), "")
1839-
Expect(err).NotTo(HaveOccurred())
1838+
if !tc.isLayer2 {
1839+
conf.IPAM, _, err = allocator.LoadIPAMConfig([]byte(confString), "")
1840+
Expect(err).NotTo(HaveOccurred())
1841+
}
18401842

18411843
newConf, err := buildOneConfig("testConfig", tc.cniVersion, conf, prevResult)
18421844
Expect(err).NotTo(HaveOccurred())
@@ -2718,6 +2720,14 @@ var _ = Describe("bridge Operations", func() {
27182720
cmdAddDelCheckTest(originalNS, targetNS, tc, dataDir)
27192721
})
27202722
}
2723+
2724+
It(fmt.Sprintf("[%s] configures and deconfigures a l2 bridge and veth with ADD/DEL/CHECK", ver), func() {
2725+
tc := testCase{
2726+
cniVersion: ver,
2727+
isLayer2: true,
2728+
}
2729+
cmdAddDelCheckTest(originalNS, targetNS, tc, dataDir)
2730+
})
27212731
}
27222732

27232733
It(fmt.Sprintf("[%s] configures mac spoof-check (no mac spoofing)", ver), func() {

0 commit comments

Comments
 (0)