containernetworking / cni

Container Network Interface - networking for Linux containers
https://cni.dev
Apache License 2.0
5.47k stars 1.07k forks source link

2.0: Protobuf / gRPC: how to pass network configuration to plugins? #887

Open squeed opened 2 years ago

squeed commented 2 years ago

Assuming we move forward with daemonization (#821), then we will have to write a protobuf schema for the CNI protocol. This tpresents a few awkward edges around network configuration.

The gist of the issue is this:

  1. A "network" and a "configuration" are the same thing
  2. The same plugin can be used by multiple "networks" 2.1. The same plugin can be used in different networks in the same container.
  3. A network configuration contains arbitrary, plugin-specific rich data.

So, we need some way to ergonomically pass, to a plugin, a network configuration. This configuration is user-defined but plugin specific.

Options

  1. Embed json in protobuf
  2. The protobuf any type, which supports embedding arbitrary protobuf messages.
  3. ???
robberphex commented 2 years ago

In CNI 2.0, we provide gRPC/Protobuf definition, so I think use protobuf any type is nature.

Example network configuration could be like:

{
"cniVersion": "1.0.0",
"name": "dbnet",
"plugins": [
{
"type": "bridge",
"bridge": "cni0",
"extra": [
{
// **plugin specific parameters for nerdctl**
"@type": "type.googleapis.com/helloworld.NerdctlNetworkConfig",
"NerdctlID": 112233,
"NerdctlLabels": {
"bob": "11"
}
},
{
// **plugin specific parameters for bridge**
"@type": "type.googleapis.com/k8s.cni.cncf.io/v1.0.0.BridgeNetworkConfig",
"configKey": "configValue"
}
],
"ipam": {
"type": "host-local",
// ipam specific
"subnet": "10.1.0.0/16",
"gateway": "10.1.0.1",
"routes": [
{
"dst": "0.0.0.0/0"
}
]
},
"dns": {
"nameservers": [
"10.1.0.1"
]
}
},
{
"type": "tuning",
"capabilities": {
"mac": true
},
"sysctl": {
"net.core.somaxconn": "500"
}
},
{
"type": "portmap",
"capabilities": {
"portMappings": true
}
}
]
}

And protobuf any type can be converted to json.

I submitted a pr, https://github.com/containernetworking/cni/pull/874 .