Skip to content

Commit

Permalink
plugins/meta: stub CNI v1.1 implementation
Browse files Browse the repository at this point in the history
This adds a basic CNI v1.1 implementation to the meta plugins.

For the plugins which do have state (firewall, bandwidth, portmap) this
does *not* perform GC. That remains outstanding.

Signed-off-by: Casey Callendrello <[email protected]>
  • Loading branch information
squeed committed Mar 20, 2024
1 parent 34dca5b commit a0374ee
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
7 changes: 6 additions & 1 deletion plugins/ipam/static/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ type Address struct {
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("static"))
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
}, version.All, bv.BuildString("static"))
}

func loadNetConf(bytes []byte) (*types.NetConf, string, error) {
Expand Down
12 changes: 11 additions & 1 deletion plugins/meta/bandwidth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func cmdAdd(args *skel.CmdArgs) error {
result.Interfaces = append(result.Interfaces, &current.Interface{
Name: ifbDeviceName,
Mac: ifbDevice.Attrs().HardwareAddr.String(),
Mtu: mtu,
})
err = CreateEgressQdisc(bandwidth.EgressRate, bandwidth.EgressBurst, hostInterface.Name, ifbDeviceName)
if err != nil {
Expand All @@ -240,7 +241,16 @@ func cmdDel(args *skel.CmdArgs) error {
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.VersionsStartingFrom("0.3.0"), bv.BuildString("bandwidth"))
// TODO: clean up stale IFB devices via GC
// Cannot do this until we can filter out only ifb devices that belong
// to this network.
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
},
version.VersionsStartingFrom("0.3.0"), bv.BuildString("bandwidth"))
}

func SafeQdiscList(link netlink.Link) ([]netlink.Qdisc, error) {
Expand Down
20 changes: 19 additions & 1 deletion plugins/meta/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ func cmdDel(args *skel.CmdArgs) error {
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.VersionsStartingFrom("0.4.0"), bv.BuildString("firewall"))
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
Status: cmdStatus,
}, version.VersionsStartingFrom("0.4.0"), bv.BuildString("firewall"))
}

func cmdCheck(args *skel.CmdArgs) error {
Expand All @@ -200,3 +206,15 @@ func cmdCheck(args *skel.CmdArgs) error {

return backend.Check(conf, result)
}

func cmdStatus(args *skel.CmdArgs) error {
conf := FirewallNetConf{}
if err := json.Unmarshal(args.StdinData, &conf); err != nil {
return fmt.Errorf("failed to load netconf: %v", err)
}

if conf.Backend == "firewalld" && !isFirewalldRunning() {
return types.NewError(50, "firewalld down", "unable to connect to the firewalld backend")
}
return nil
}
7 changes: 6 additions & 1 deletion plugins/meta/portmap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ func cmdDel(args *skel.CmdArgs) error {
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("portmap"))
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
}, version.All, bv.BuildString("portmap"))
}

func cmdCheck(args *skel.CmdArgs) error {
Expand Down
7 changes: 6 additions & 1 deletion plugins/meta/sbr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,12 @@ RULE_LOOP:
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("sbr"))
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
}, version.All, bv.BuildString("sbr"))
}

func cmdCheck(_ *skel.CmdArgs) error {
Expand Down
7 changes: 6 additions & 1 deletion plugins/meta/tuning/tuning.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ func cmdDel(args *skel.CmdArgs) error {
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.All, bv.BuildString("tuning"))
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
}, version.All, bv.BuildString("tuning"))
}

func cmdCheck(args *skel.CmdArgs) error {
Expand Down
7 changes: 6 additions & 1 deletion plugins/meta/vrf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ type VRFNetConf struct {
}

func main() {
skel.PluginMain(cmdAdd, cmdCheck, cmdDel, version.VersionsStartingFrom("0.3.1"), bv.BuildString("vrf"))
skel.PluginMainFuncs(
skel.CNIFuncs{
Add: cmdAdd,
Check: cmdCheck,
Del: cmdDel,
}, version.VersionsStartingFrom("0.3.1"), bv.BuildString("vrf"))
}

func cmdAdd(args *skel.CmdArgs) error {
Expand Down

0 comments on commit a0374ee

Please sign in to comment.