CNI (Container Network Interface) is a Cloud Native Computing Foundation project that provides a specification and libraries for writing plugins to configure network interfaces in Linux containers. It focuses solely on the network connectivity of containers and the release of allocated resources upon container deletion.
CNI plugins are typically implemented in Go and interact with the container runtime through a standardized interface. Here's a conceptual example of a CNI plugin's `Add` function:
```go func CmdAdd(args *skel.CmdArgs) error {
// Parse network configuration from args.StdinData netConf := ...
// Create network interface and configure IP address interface := ...
// Set up routing and any additional network configuration // ...
// Return the result (including the assigned IP address) result := ¤t.Result{ CNIVersion: current.ImplementedSpecVersion, Interfaces: []*current.Interface{interface}, IPs: []*current.IPConfig{ipConfig}, // ... other fields ... } return result.Print()} ```
This `Add` function receives network configuration data, creates a network interface, configures the IP address, and returns the result to the container runtime.