Skip to content

Commit

Permalink
Allow CNI runtime capabilities to be configuratble from CNIConfiguration
Browse files Browse the repository at this point in the history
In this change we add CapabilityArgs into the CNIConfiguration to allow CNI runtime capabilities to be
configurable from the firecracker-go-sdk.

Signed-off-by: Jingkai He <[email protected]>
  • Loading branch information
jingkaihe committed Jul 30, 2021
1 parent abd0815 commit 9a293a1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions network.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ type CNIConfiguration struct {
// configuration directory.
NetworkConfig *libcni.NetworkConfigList

// CapabilityArgs (optional) is a dictionary of capability-specific
// data passed by the runtime to plugins as top-level keys in the
// 'runtimeConfig' dictionary of the plugin's stdin data. libcni
// will ensure that only keys in this map which match the capabilities
// of the plugin are passed to the plugin.
CapabilityArgs map[string]interface{}

// IfName (optional) corresponds to the CNI_IFNAME parameter as specified
// in the CNI spec. It generally specifies the name of the interface to be
// created by a CNI plugin being invoked.
Expand Down Expand Up @@ -316,10 +323,11 @@ func (cniConf *CNIConfiguration) setDefaults() {

func (cniConf CNIConfiguration) asCNIRuntimeConf() *libcni.RuntimeConf {
return &libcni.RuntimeConf{
ContainerID: cniConf.containerID,
NetNS: cniConf.netNSPath,
IfName: cniConf.IfName,
Args: cniConf.Args,
ContainerID: cniConf.containerID,
NetNS: cniConf.netNSPath,
IfName: cniConf.IfName,
Args: cniConf.Args,
CapabilityArgs: cniConf.CapabilityArgs,
}
}

Expand Down
13 changes: 13 additions & 0 deletions network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ func testNetworkMachineCNI(t *testing.T, useConfFile bool) {
},
{
"type": "tc-redirect-tap"
},
{
"type": "portmap",
"capabilities": {"portMappings": true}
}
]
}`, networkName)
Expand Down Expand Up @@ -424,6 +428,15 @@ func newCNIMachine(t *testing.T,
NetworkConfig: networkConf,
IfName: ifName,
VMIfName: "eth0",
CapabilityArgs: map[string]interface{}{
"portMappings": []interface{}{
map[string]interface{}{
"hostPort": 8080,
"containerPort": 80,
"protocol": "tcp",
},
},
},
},
}},
VMID: vmID,
Expand Down

0 comments on commit 9a293a1

Please sign in to comment.