Skip to content

Commit

Permalink
Re-introduce serial network setup
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Schwind <marc.schwind@de.ibm.com>
  • Loading branch information
marc-schwind committed May 17, 2022
1 parent b39860d commit ee1a707
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
type CNI interface {
// Setup setup the network for the namespace
Setup(ctx context.Context, id string, path string, opts ...NamespaceOpts) (*Result, error)
// SetupSerially sets up each of the network interfaces for the namespace in serial
SetupSerially(ctx context.Context, id string, path string, opts ...NamespaceOpts) (*Result, error)
// Remove tears down the network of the namespace.
Remove(ctx context.Context, id string, path string, opts ...NamespaceOpts) error
// Check checks if the network is still in desired state
Expand Down Expand Up @@ -165,6 +167,34 @@ func (c *libcni) Setup(ctx context.Context, id string, path string, opts ...Name
return c.createResult(result)
}

// SetupSerially setups the network in the namespace and returns a Result
func (c *libcni) SetupSerially(ctx context.Context, id string, path string, opts ...NamespaceOpts) (*Result, error) {
if err := c.Status(); err != nil {
return nil, err
}
ns, err := newNamespace(id, path, opts...)
if err != nil {
return nil, err
}
result, err := c.attachNetworksSerially(ctx, ns)
if err != nil {
return nil, err
}
return c.createResult(result)
}

func (c *libcni) attachNetworksSerially(ctx context.Context, ns *Namespace) ([]*types100.Result, error) {
var results []*types100.Result
for _, network := range c.Networks() {
r, err := network.Attach(ctx, ns)
if err != nil {
return nil, err
}
results = append(results, r)
}
return results, nil
}

type asynchAttachResult struct {
index int
res *types100.Result
Expand Down

0 comments on commit ee1a707

Please sign in to comment.