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

ar/bridge_networking: ensure cni configuration is loaded #7643

Merged
merged 4 commits into from
Apr 7, 2020
Merged
Changes from 3 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
14 changes: 13 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,21 @@ 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 err := b.cni.Status(); cni.IsCNINotInitialized(err) {
return b.cni.Load(cni.WithConfListBytes(b.buildNomadNetConfig()))
} else {
return err
}
}

// 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