Skip to content

Commit

Permalink
ar/bridge: ensure cni configuration is always loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
nickethier committed Apr 7, 2020
1 parent 9df9e5e commit f68b85b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion client/allocrunner/networking_bridge_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (b *bridgeNetworkConfigurator) Setup(ctx context.Context, alloc *structs.Al
return fmt.Errorf("failed to initialize table forwarding rules: %v", err)
}

if err := b.cni.Load(cni.WithConfListBytes(b.buildNomadNetConfig())); err != nil {
if err := b.ensureCNIInitialized(); err != nil {
return err
}

Expand Down Expand Up @@ -176,9 +176,20 @@ func (b *bridgeNetworkConfigurator) Setup(ctx context.Context, alloc *structs.Al

// Teardown calls the CNI plugins with the delete action
func (b *bridgeNetworkConfigurator) Teardown(ctx context.Context, alloc *structs.Allocation, spec *drivers.NetworkIsolationSpec) error {
if err := b.ensureCNIInitialized(); err != nil {
return err
}

return b.cni.Remove(ctx, alloc.ID, spec.Path, cni.WithCapabilityPortMap(getPortMapping(alloc)))
}

func (b *bridgeNetworkConfigurator) ensureCNIInitialized() error {
if b.cni.Status() == cni.ErrCNINotInitialized {

This comment has been minimized.

Copy link
@shoenig

shoenig Apr 7, 2020

Member
return b.cni.Load(cni.WithConfListBytes(b.buildNomadNetConfig()))
}
return nil
}

// getPortMapping builds a list of portMapping structs that are used as the
// portmapping capability arguments for the portmap CNI plugin
func getPortMapping(alloc *structs.Allocation) []cni.PortMapping {
Expand Down

0 comments on commit f68b85b

Please sign in to comment.