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.
This commit is contained in:
Luiz Aoqui 2023-06-14 10:22:38 -04:00 committed by GitHub
parent 70fc0fd701
commit ec80d051d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -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) {