containerd / go-cni

A generic CNI library to provide APIs for CNI plugin interactions
Apache License 2.0
146 stars 56 forks source link

Re-introduce serial network setup #99

Closed marc-schwind closed 2 years ago

marc-schwind commented 2 years ago

Some use cases require serialized network setup to ensure proper network namespace switching on the same thread.

As ns.Set() cannot be relied upon when goroutines switch OS threads callers of CNI.Setup(...) may want to wrap the setup network creation in a closure locking the OS thread, as described here: https://github.com/containernetworking/plugins/tree/main/pkg/ns#do-the-recommended-thing

For more details and background also see https://github.com/containernetworking/plugins/tree/main/pkg/ns#namespace-switching

With the performance improvements introduced with PR76 such use cases break.

This PR re-introduces an additional serialized version SetupSerially(...) of CNI network setup/attach to accommodate the above mentioned use cases, while leaving the main code path untouched to ensure the non-edge cases can benefit from the performance recent enhancement.

dims commented 2 years ago

LGTM