Skip to content

Commit

Permalink
Add socket path and pciid to CNI interface result
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Zappa <michaelzappa@microsoft.com>
  • Loading branch information
MikeZappa87 committed Feb 26, 2024
1 parent b62753a commit 330a4a7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 24 deletions.
8 changes: 5 additions & 3 deletions SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,11 @@ Plugins must output a JSON object with the following keys upon a successful `ADD

- `cniVersion`: The same version supplied on input - the string "1.1.0"
- `interfaces`: An array of all interfaces created by the attachment, including any host-level interfaces:
- `name`: The name of the interface.
- `mac`: The hardware address of the interface (if applicable).
- `sandbox`: The isolation domain reference (e.g. path to network namespace) for the interface, or empty if on the host. For interfaces created inside the container, this should be the value passed via `CNI_NETNS`.
- `name` (string): The name of the interface.
- `mac` (string): The hardware address of the interface (if applicable).
- `sandbox` (string): The isolation domain reference (e.g. path to network namespace) for the interface, or empty if on the host. For interfaces created inside the container, this should be the value passed via `CNI_NETNS`.
- `socket_path` (string): The path of the socket that can be passed down to OCI runtimes.
- `pci_id` (string): The combination of vendor id and device id to uniquely identify a device.
- `ips`: IPs assigned by this attachment. Plugins may include IPs assigned external to the container.
- `address` (string): an IP address in CIDR notation (eg "192.168.1.3/24").
- `gateway` (string): the default gateway for this subnet, if one exists.
Expand Down
8 changes: 5 additions & 3 deletions pkg/types/100/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,11 @@ func (r *Result) PrintTo(writer io.Writer) error {

// Interface contains values about the created interfaces
type Interface struct {
Name string `json:"name"`
Mac string `json:"mac,omitempty"`
Sandbox string `json:"sandbox,omitempty"`
Name string `json:"name"`
Mac string `json:"mac,omitempty"`
Sandbox string `json:"sandbox,omitempty"`
SocketPath string `json:"socket_path,omitempty"`
PciID string `json:"pci_id,omitempty"`
}

func (i *Interface) String() string {
Expand Down
17 changes: 10 additions & 7 deletions pkg/types/100/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ func testResult() *current.Result {
Expect(err).NotTo(HaveOccurred())
Expect(routev6).NotTo(BeNil())
Expect(routegwv6).NotTo(BeNil())

// Set every field of the struct to ensure source compatibility
return &current.Result{
CNIVersion: current.ImplementedSpecVersion,
Interfaces: []*current.Interface{
{
Name: "eth0",
Mac: "00:11:22:33:44:55",
Sandbox: "/proc/3553/ns/net",
Name: "eth0",
Mac: "00:11:22:33:44:55",
Sandbox: "/proc/3553/ns/net",
PciID: "8086:9a01",
SocketPath: "/path/to/vhost/fd",
},
},
IPs: []*current.IPConfig{
Expand Down Expand Up @@ -104,9 +105,11 @@ var _ = Describe("Current types operations", func() {
"cniVersion": "` + current.ImplementedSpecVersion + `",
"interfaces": [
{
"name": "eth0",
"mac": "00:11:22:33:44:55",
"sandbox": "/proc/3553/ns/net"
"name": "eth0",
"mac": "00:11:22:33:44:55",
"sandbox": "/proc/3553/ns/net",
"pci_id": "8086:9a01",
"socket_path": "/path/to/vhost/fd"
}
],
"ips": [
Expand Down
9 changes: 5 additions & 4 deletions pkg/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,15 @@ var _ = Describe("Types", func() {
ipv6, err := types.ParseCIDR("abcd:1234:ffff::cdde/64")
Expect(err).NotTo(HaveOccurred())
Expect(ipv6).NotTo(BeNil())

result = &current.Result{
CNIVersion: "1.0.0",
Interfaces: []*current.Interface{
{
Name: "eth0",
Mac: "00:11:22:33:44:55",
Sandbox: "/proc/3553/ns/net",
Name: "eth0",
Mac: "00:11:22:33:44:55",
Sandbox: "/proc/3553/ns/net",
PciID: "8086:9a01",
SocketPath: "/path/to/vhost/fd",
},
},
IPs: []*current.IPConfig{
Expand Down
17 changes: 10 additions & 7 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ var _ = Describe("Version operations", func() {
"cniVersion": "1.0.0",
"interfaces": [
{
"name": "eth0",
"mac": "00:11:22:33:44:55",
"sandbox": "/proc/3553/ns/net"
"name": "eth0",
"mac": "00:11:22:33:44:55",
"sandbox": "/proc/3553/ns/net",
"pci_id": "8086:9a01",
"socket_path": "/path/to/vhost/fd"
}
],
"ips": [
Expand All @@ -66,14 +68,15 @@ var _ = Describe("Version operations", func() {

err = version.ParsePrevResult(conf)
Expect(err).NotTo(HaveOccurred())

expectedResult := &cniv1.Result{
CNIVersion: "1.0.0",
Interfaces: []*cniv1.Interface{
{
Name: "eth0",
Mac: "00:11:22:33:44:55",
Sandbox: "/proc/3553/ns/net",
Name: "eth0",
Mac: "00:11:22:33:44:55",
Sandbox: "/proc/3553/ns/net",
PciID: "8086:9a01",
SocketPath: "/path/to/vhost/fd",
},
},
IPs: []*cniv1.IPConfig{
Expand Down

0 comments on commit 330a4a7

Please sign in to comment.