From ec80d051d8b5d4754721b2ff52c2d0503d6a31bd Mon Sep 17 00:00:00 2001 From: Luiz Aoqui Date: Wed, 14 Jun 2023 10:22:38 -0400 Subject: [PATCH] client: fix panic on alloc stop in non-Linux environments (#17515) Provide a no-op implementation of the drivers.DriverNetoworkManager interface to be used by systems that don't support network isolation and prevent panics where a network manager is expected. --- client/allocrunner/network_manager_nonlinux.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/allocrunner/network_manager_nonlinux.go b/client/allocrunner/network_manager_nonlinux.go index a7a278936..859dacf4c 100644 --- a/client/allocrunner/network_manager_nonlinux.go +++ b/client/allocrunner/network_manager_nonlinux.go @@ -14,9 +14,21 @@ import ( "github.com/hashicorp/nomad/plugins/drivers" ) +// noopNetworkManager implements the drivers.DriverNetoworkManager interface to +// provide a no-op manager for systems that don't support network isolation. +type noopNetworkManager struct{} + +func (*noopNetworkManager) CreateNetwork(_ string, _ *drivers.NetworkCreateRequest) (*drivers.NetworkIsolationSpec, bool, error) { + return nil, false, nil +} + +func (*noopNetworkManager) DestroyNetwork(_ string, _ *drivers.NetworkIsolationSpec) error { + return nil +} + // TODO: Support windows shared networking func newNetworkManager(alloc *structs.Allocation, driverManager drivermanager.Manager) (nm drivers.DriverNetworkManager, err error) { - return nil, nil + return &noopNetworkManager{}, nil } func newNetworkConfigurator(log hclog.Logger, alloc *structs.Allocation, config *clientconfig.Config) (NetworkConfigurator, error) {