The Ratchet dependencies
Some of the most important dependencies are in these lines in ratchet.go, which includes:
github.com/containernetworking/cni/pkg/skel: Skeleton for CNI to read stdin & environment variables.
github.com/containernetworking/cni/pkg/invoke: Allows us to use the DelegateAdd method which we use to call other plugins.
github.com/containernetworking/cni/pkg/types: Some common types that are used by the CNI packages, including the NetConf type which defines our config JSON that we read from stdin.
There’s also a Docker client that we use to pick some additional metadata from the pod.
The main method
The main() method of the application is really just calling skel – as seen here, which looks like:
So we let skel do some work for us – it will call either of these methods (which are local to the Ratchet application), either cmdAdd or cmdDel (called on either creation or deletion of the pod). In those methods – we’re able to have a return from skel that includes the JSON config, which we can then parse and read to get some custom properties out of it.