Skip to content

Commit

Permalink
Implement STATUS
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Archit Kulkarni <[email protected]>
Co-authored-by: Michael Zappa <[email protected]>
  • Loading branch information
architkulkarni and MikeZappa87 committed Oct 14, 2024
1 parent 1c1be5e commit 67c32dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type CNI interface {
Status() error
// GetConfig returns a copy of the CNI plugin configurations as parsed by CNI
GetConfig() *ConfigResult
// Status executes the status verb of the cni plugin
StatusDetail(context.Context) ([]*NetworkStatus, error)
}

type ConfigResult struct {
Expand Down Expand Up @@ -310,3 +312,23 @@ func (c *libcni) GetConfig() *ConfigResult {
func (c *libcni) reset() {
c.networks = nil
}

// StatusDetail returns a slice of network statuses
func (c *libcni) StatusDetail(ctx context.Context) ([]*NetworkStatus, error) {
err := c.Status()

if err != nil {
return nil, err
}

var networks []*NetworkStatus

for _, network := range c.Networks() {
networks = append(networks, &NetworkStatus{
Network: network,
Status: network.Status(ctx),
})
}

return networks, nil
}
1 change: 1 addition & 0 deletions cni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ func TestLibCNIType120(t *testing.T) {
Args: [][2]string(nil),
CapabilityArgs: map[string]interface{}{},
}
mockCNI.On("GetStatusNetworkList", l.networks[1].config).Return(nil)
mockCNI.On("AddNetworkList", l.networks[1].config, expectedRT).Return(&types100.Result{
CNIVersion: "1.1.0",
Interfaces: []*types100.Interface{
Expand Down
4 changes: 4 additions & 0 deletions namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func (n *Network) Check(ctx context.Context, ns *Namespace) error {
return n.cni.CheckNetworkList(ctx, n.config, ns.config(n.ifName))
}

func (n *Network) Status(ctx context.Context) error {
return n.cni.GetStatusNetworkList(ctx, n.config)
}

type Namespace struct {
id string
path string
Expand Down
5 changes: 5 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,8 @@ type DNS struct {
// List of DNS options.
Options []string
}

type NetworkStatus struct {
Network *Network
Status error
}

0 comments on commit 67c32dd

Please sign in to comment.