Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CNI STATUS #120

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion 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 @@ -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()
Expand Down Expand Up @@ -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
}
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
}
Loading