mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-07 14:36:43 +00:00
virtcontainers: Define a Network interface
And move the Linux implementation into a GOOS specific file. Fixes #3005 Signed-off-by: Samuel Ortiz <s.ortiz@apple.com>
This commit is contained in:
parent
5e119e90e8
commit
e0b264430d
@ -356,7 +356,7 @@ func (a *Acrn) setConfig(config *HypervisorConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateVM is the VM creation
|
// CreateVM is the VM creation
|
||||||
func (a *Acrn) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
|
func (a *Acrn) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
|
||||||
// Save the tracing context
|
// Save the tracing context
|
||||||
a.ctx = ctx
|
a.ctx = ctx
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ func (clh *cloudHypervisor) setConfig(config *HypervisorConfig) error {
|
|||||||
|
|
||||||
// For cloudHypervisor this call only sets the internal structure up.
|
// For cloudHypervisor this call only sets the internal structure up.
|
||||||
// The VM will be created and started through StartVM().
|
// The VM will be created and started through StartVM().
|
||||||
func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
|
func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
|
||||||
clh.ctx = ctx
|
clh.ctx = ctx
|
||||||
|
|
||||||
span, newCtx := katatrace.Trace(clh.ctx, clh.Logger(), "CreateVM", clhTracingTags, map[string]string{"sandbox_id": clh.id})
|
span, newCtx := katatrace.Trace(clh.ctx, clh.Logger(), "CreateVM", clhTracingTags, map[string]string{"sandbox_id": clh.id})
|
||||||
|
@ -199,7 +199,7 @@ func (fc *firecracker) setConfig(config *HypervisorConfig) error {
|
|||||||
|
|
||||||
// CreateVM For firecracker this call only sets the internal structure up.
|
// CreateVM For firecracker this call only sets the internal structure up.
|
||||||
// The sandbox will be created and started through startSandbox().
|
// The sandbox will be created and started through startSandbox().
|
||||||
func (fc *firecracker) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
|
func (fc *firecracker) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
|
||||||
fc.ctx = ctx
|
fc.ctx = ctx
|
||||||
|
|
||||||
span, _ := katatrace.Trace(ctx, fc.Logger(), "CreateVM", fcTracingTags, map[string]string{"sandbox_id": fc.id})
|
span, _ := katatrace.Trace(ctx, fc.Logger(), "CreateVM", fcTracingTags, map[string]string{"sandbox_id": fc.id})
|
||||||
|
@ -910,7 +910,7 @@ func generateVMSocket(id string, vmStogarePath string) (interface{}, error) {
|
|||||||
// hypervisor is the virtcontainers hypervisor interface.
|
// hypervisor is the virtcontainers hypervisor interface.
|
||||||
// The default hypervisor implementation is Qemu.
|
// The default hypervisor implementation is Qemu.
|
||||||
type Hypervisor interface {
|
type Hypervisor interface {
|
||||||
CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error
|
CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error
|
||||||
StartVM(ctx context.Context, timeout int) error
|
StartVM(ctx context.Context, timeout int) error
|
||||||
|
|
||||||
// If wait is set, don't actively stop the sandbox:
|
// If wait is set, don't actively stop the sandbox:
|
||||||
|
@ -38,7 +38,7 @@ func (m *mockHypervisor) setConfig(config *HypervisorConfig) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockHypervisor) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
|
func (m *mockHypervisor) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
|
||||||
if err := m.setConfig(hypervisorConfig); err != nil {
|
if err := m.setConfig(hypervisorConfig); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
1403
src/runtime/virtcontainers/network_linux.go
Normal file
1403
src/runtime/virtcontainers/network_linux.go
Normal file
File diff suppressed because it is too large
Load Diff
@ -75,7 +75,7 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
|
|||||||
|
|
||||||
nns, err := NewNetwork(&NetworkConfig{NetworkID: "foobar", NetworkCreated: true})
|
nns, err := NewNetwork(&NetworkConfig{NetworkID: "foobar", NetworkCreated: true})
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
nns.eps = endpoints
|
nns.SetEndpoints(endpoints)
|
||||||
|
|
||||||
resInterfaces, resRoutes, resNeighs, err := generateVCNetworkStructures(context.Background(), nns)
|
resInterfaces, resRoutes, resNeighs, err := generateVCNetworkStructures(context.Background(), nns)
|
||||||
|
|
||||||
|
@ -468,7 +468,7 @@ func (q *qemu) setConfig(config *HypervisorConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateVM is the Hypervisor VM creation implementation for govmmQemu.
|
// CreateVM is the Hypervisor VM creation implementation for govmmQemu.
|
||||||
func (q *qemu) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
|
func (q *qemu) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
|
||||||
// Save the tracing context
|
// Save the tracing context
|
||||||
q.ctx = ctx
|
q.ctx = ctx
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ type Sandbox struct {
|
|||||||
|
|
||||||
id string
|
id string
|
||||||
|
|
||||||
network *Network
|
network Network
|
||||||
|
|
||||||
state types.SandboxState
|
state types.SandboxState
|
||||||
|
|
||||||
@ -873,14 +873,14 @@ func (s *Sandbox) AddInterface(ctx context.Context, inf *pbTypes.Interface) (*pb
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint, err := s.network.attachEndpoint(ctx, s, netInfo, nil, true)
|
endpoint, err := s.network.AddEndpoint(ctx, s, netInfo, nil, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errDetach := s.network.detachEndpoint(ctx, s, len(s.network.Endpoints())-1, true); err != nil {
|
if errDetach := s.network.RemoveEndpoint(ctx, s, len(s.network.Endpoints())-1, true); err != nil {
|
||||||
s.Logger().WithField("endpoint-type", endpoint.Type()).WithError(errDetach).Error("rollback hot attaching endpoint failed")
|
s.Logger().WithField("endpoint-type", endpoint.Type()).WithError(errDetach).Error("rollback hot attaching endpoint failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -906,7 +906,7 @@ func (s *Sandbox) RemoveInterface(ctx context.Context, inf *pbTypes.Interface) (
|
|||||||
for i, endpoint := range s.network.Endpoints() {
|
for i, endpoint := range s.network.Endpoints() {
|
||||||
if endpoint.HardwareAddr() == inf.HwAddr {
|
if endpoint.HardwareAddr() == inf.HwAddr {
|
||||||
s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint")
|
s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint")
|
||||||
if err := s.network.detachEndpoint(ctx, s, i, true); err != nil {
|
if err := s.network.RemoveEndpoint(ctx, s, i, true); err != nil {
|
||||||
return inf, err
|
return inf, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user