diff --git a/cni.go b/cni.go index b10af47..b1fbbe0 100644 --- a/cni.go +++ b/cni.go @@ -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 { @@ -133,7 +135,6 @@ func (c *libcni) Load(opts ...Opt) error { return nil } -// Status returns the status of CNI initialization. func (c *libcni) Status() error { c.RLock() defer c.RUnlock() @@ -310,3 +311,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 +} diff --git a/namespace.go b/namespace.go index 319182b..af3c866 100644 --- a/namespace.go +++ b/namespace.go @@ -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 diff --git a/types.go b/types.go index 18616c0..92c6254 100644 --- a/types.go +++ b/types.go @@ -60,3 +60,8 @@ type DNS struct { // List of DNS options. Options []string } + +type NetworkStatus struct { + Network *Network + Status error +}