Skip to content

Commit 67c32dd

Browse files
Implement STATUS
This commit implements the STATUS CNI verb. It adds a new function StatusDetail which returns a list with the status of each network. Signed-off-by: Michael Zappa <michael.zappa@gmail.com> Signed-off-by: Archit Kulkarni <architkulkarni@google.com> Co-authored-by: Michael Zappa <michael.zappa@gmail.com>
1 parent 1c1be5e commit 67c32dd

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

cni.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ type CNI interface {
4545
Status() error
4646
// GetConfig returns a copy of the CNI plugin configurations as parsed by CNI
4747
GetConfig() *ConfigResult
48+
// Status executes the status verb of the cni plugin
49+
StatusDetail(context.Context) ([]*NetworkStatus, error)
4850
}
4951

5052
type ConfigResult struct {
@@ -310,3 +312,23 @@ func (c *libcni) GetConfig() *ConfigResult {
310312
func (c *libcni) reset() {
311313
c.networks = nil
312314
}
315+
316+
// StatusDetail returns a slice of network statuses
317+
func (c *libcni) StatusDetail(ctx context.Context) ([]*NetworkStatus, error) {
318+
err := c.Status()
319+
320+
if err != nil {
321+
return nil, err
322+
}
323+
324+
var networks []*NetworkStatus
325+
326+
for _, network := range c.Networks() {
327+
networks = append(networks, &NetworkStatus{
328+
Network: network,
329+
Status: network.Status(ctx),
330+
})
331+
}
332+
333+
return networks, nil
334+
}

cni_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ func TestLibCNIType120(t *testing.T) {
342342
Args: [][2]string(nil),
343343
CapabilityArgs: map[string]interface{}{},
344344
}
345+
mockCNI.On("GetStatusNetworkList", l.networks[1].config).Return(nil)
345346
mockCNI.On("AddNetworkList", l.networks[1].config, expectedRT).Return(&types100.Result{
346347
CNIVersion: "1.1.0",
347348
Interfaces: []*types100.Interface{

namespace.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func (n *Network) Check(ctx context.Context, ns *Namespace) error {
4545
return n.cni.CheckNetworkList(ctx, n.config, ns.config(n.ifName))
4646
}
4747

48+
func (n *Network) Status(ctx context.Context) error {
49+
return n.cni.GetStatusNetworkList(ctx, n.config)
50+
}
51+
4852
type Namespace struct {
4953
id string
5054
path string

types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ type DNS struct {
6060
// List of DNS options.
6161
Options []string
6262
}
63+
64+
type NetworkStatus struct {
65+
Network *Network
66+
Status error
67+
}

0 commit comments

Comments
 (0)