diff --git a/src/runtime/virtcontainers/agent.go b/src/runtime/virtcontainers/agent.go index 8e95899461..0ada23c6b1 100644 --- a/src/runtime/virtcontainers/agent.go +++ b/src/runtime/virtcontainers/agent.go @@ -140,10 +140,10 @@ type agent interface { resumeContainer(ctx context.Context, sandbox *Sandbox, c Container) error // configure will update agent settings based on provided arguments - configure(ctx context.Context, h hypervisor, id, sharePath string, config KataAgentConfig) error + configure(ctx context.Context, h Hypervisor, id, sharePath string, config KataAgentConfig) error // configureFromGrpc will update agent settings based on provided arguments which from Grpc - configureFromGrpc(ctx context.Context, h hypervisor, id string, config KataAgentConfig) error + configureFromGrpc(ctx context.Context, h Hypervisor, id string, config KataAgentConfig) error // reseedRNG will reseed the guest random number generator reseedRNG(ctx context.Context, data []byte) error diff --git a/src/runtime/virtcontainers/api_test.go b/src/runtime/virtcontainers/api_test.go index 6790ce60b9..255314e79d 100644 --- a/src/runtime/virtcontainers/api_test.go +++ b/src/runtime/virtcontainers/api_test.go @@ -9,13 +9,13 @@ import ( "context" "encoding/json" "fmt" - "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/fs" "os" "path/filepath" "strings" "testing" ktu "github.com/kata-containers/kata-containers/src/runtime/pkg/katatestutils" + "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/fs" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/mock" diff --git a/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go b/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go index c0ec08ad5a..67b22a6910 100644 --- a/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go +++ b/src/runtime/virtcontainers/bridgedmacvlan_endpoint.go @@ -121,12 +121,12 @@ func (endpoint *BridgedMacvlanEndpoint) Detach(ctx context.Context, netNsCreated } // HotAttach for bridged macvlan endpoint not supported yet -func (endpoint *BridgedMacvlanEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *BridgedMacvlanEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot attach") } // HotDetach for bridged macvlan endpoint not supported yet -func (endpoint *BridgedMacvlanEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *BridgedMacvlanEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot detach") } diff --git a/src/runtime/virtcontainers/endpoint.go b/src/runtime/virtcontainers/endpoint.go index 5fbabd2f8f..21d0b2a0a3 100644 --- a/src/runtime/virtcontainers/endpoint.go +++ b/src/runtime/virtcontainers/endpoint.go @@ -26,8 +26,8 @@ type Endpoint interface { SetPciPath(vcTypes.PciPath) Attach(context.Context, *Sandbox) error Detach(ctx context.Context, netNsCreated bool, netNsPath string) error - HotAttach(ctx context.Context, h hypervisor) error - HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error + HotAttach(ctx context.Context, h Hypervisor) error + HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error save() persistapi.NetworkEndpoint load(persistapi.NetworkEndpoint) diff --git a/src/runtime/virtcontainers/hypervisor.go b/src/runtime/virtcontainers/hypervisor.go index 751d8d9ef3..7ac7739a41 100644 --- a/src/runtime/virtcontainers/hypervisor.go +++ b/src/runtime/virtcontainers/hypervisor.go @@ -186,7 +186,7 @@ func (hType *HypervisorType) String() string { } // NewHypervisor returns an hypervisor from and hypervisor type. -func NewHypervisor(hType HypervisorType) (hypervisor, error) { +func NewHypervisor(hType HypervisorType) (Hypervisor, error) { store, err := persist.GetDriver() if err != nil { return nil, err @@ -874,7 +874,7 @@ func RunningOnVMM(cpuInfoPath string) (bool, error) { return false, nil } -func GetHypervisorPid(h hypervisor) int { +func GetHypervisorPid(h Hypervisor) int { pids := h.GetPids() if len(pids) == 0 { return 0 @@ -897,8 +897,7 @@ func generateVMSocket(id string, vmStogarePath string) (interface{}, error) { // hypervisor is the virtcontainers hypervisor interface. // The default hypervisor implementation is Qemu. -type hypervisor interface { - setConfig(config *HypervisorConfig) error +type Hypervisor interface { CreateVM(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig) error StartVM(ctx context.Context, timeout int) error @@ -921,6 +920,7 @@ type hypervisor interface { Cleanup(ctx context.Context) error // getPids returns a slice of hypervisor related process ids. // The hypervisor pid must be put at index 0. + setConfig(config *HypervisorConfig) error GetPids() []int GetVirtioFsPid() *int fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, j []byte) error diff --git a/src/runtime/virtcontainers/hypervisor_test.go b/src/runtime/virtcontainers/hypervisor_test.go index 3eba751b14..c2eaa107cc 100644 --- a/src/runtime/virtcontainers/hypervisor_test.go +++ b/src/runtime/virtcontainers/hypervisor_test.go @@ -65,7 +65,7 @@ func TestStringFromUnknownHypervisorType(t *testing.T) { testStringFromHypervisorType(t, hypervisorType, "") } -func testNewHypervisorFromHypervisorType(t *testing.T, hypervisorType HypervisorType, expected hypervisor) { +func testNewHypervisorFromHypervisorType(t *testing.T, hypervisorType HypervisorType, expected Hypervisor) { assert := assert.New(t) hy, err := NewHypervisor(hypervisorType) assert.NoError(err) diff --git a/src/runtime/virtcontainers/ipvlan_endpoint.go b/src/runtime/virtcontainers/ipvlan_endpoint.go index 62480f15a6..45c5823d0a 100644 --- a/src/runtime/virtcontainers/ipvlan_endpoint.go +++ b/src/runtime/virtcontainers/ipvlan_endpoint.go @@ -93,6 +93,7 @@ func (endpoint *IPVlanEndpoint) NetworkPair() *NetworkInterfacePair { // Attach for ipvlan endpoint bridges the network pair and adds the // tap interface of the network pair to the hypervisor. +// tap interface of the network pair to the Hypervisor. func (endpoint *IPVlanEndpoint) Attach(ctx context.Context, s *Sandbox) error { span, ctx := ipvlanTrace(ctx, "Attach", endpoint) defer span.End() @@ -124,12 +125,12 @@ func (endpoint *IPVlanEndpoint) Detach(ctx context.Context, netNsCreated bool, n } // HotAttach for ipvlan endpoint not supported yet -func (endpoint *IPVlanEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *IPVlanEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { return fmt.Errorf("IPVlanEndpoint does not support Hot attach") } // HotDetach for ipvlan endpoint not supported yet -func (endpoint *IPVlanEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *IPVlanEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { return fmt.Errorf("IPVlanEndpoint does not support Hot detach") } diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index adeb24d84e..bf8dd1d600 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -333,7 +333,7 @@ func (k *kataAgent) capabilities() types.Capabilities { return caps } -func (k *kataAgent) internalConfigure(ctx context.Context, h hypervisor, id string, config KataAgentConfig) error { +func (k *kataAgent) internalConfigure(ctx context.Context, h Hypervisor, id string, config KataAgentConfig) error { span, _ := katatrace.Trace(ctx, k.Logger(), "configure", kataAgentTracingTags) defer span.End() @@ -421,7 +421,7 @@ func (k *kataAgent) cleanupSandboxBindMounts(sandbox *Sandbox) error { return retErr } -func (k *kataAgent) configure(ctx context.Context, h hypervisor, id, sharePath string, config KataAgentConfig) error { +func (k *kataAgent) configure(ctx context.Context, h Hypervisor, id, sharePath string, config KataAgentConfig) error { span, ctx := katatrace.Trace(ctx, k.Logger(), "configure", kataAgentTracingTags) defer span.End() @@ -466,7 +466,7 @@ func (k *kataAgent) configure(ctx context.Context, h hypervisor, id, sharePath s return h.AddDevice(ctx, sharedVolume, FsDev) } -func (k *kataAgent) configureFromGrpc(ctx context.Context, h hypervisor, id string, config KataAgentConfig) error { +func (k *kataAgent) configureFromGrpc(ctx context.Context, h Hypervisor, id string, config KataAgentConfig) error { return k.internalConfigure(ctx, h, id, config) } diff --git a/src/runtime/virtcontainers/macvtap_endpoint.go b/src/runtime/virtcontainers/macvtap_endpoint.go index 52be4e2454..28cb91b8fd 100644 --- a/src/runtime/virtcontainers/macvtap_endpoint.go +++ b/src/runtime/virtcontainers/macvtap_endpoint.go @@ -91,12 +91,12 @@ func (endpoint *MacvtapEndpoint) Detach(ctx context.Context, netNsCreated bool, } // HotAttach for macvtap endpoint not supported yet -func (endpoint *MacvtapEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *MacvtapEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { return fmt.Errorf("MacvtapEndpoint does not support Hot attach") } // HotDetach for macvtap endpoint not supported yet -func (endpoint *MacvtapEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *MacvtapEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { return fmt.Errorf("MacvtapEndpoint does not support Hot detach") } diff --git a/src/runtime/virtcontainers/mock_agent.go b/src/runtime/virtcontainers/mock_agent.go index 5be0b4a2f8..6bb450094c 100644 --- a/src/runtime/virtcontainers/mock_agent.go +++ b/src/runtime/virtcontainers/mock_agent.go @@ -173,11 +173,11 @@ func (n *mockAgent) resumeContainer(ctx context.Context, sandbox *Sandbox, c Con } // configure is the Noop agent configuration implementation. It does nothing. -func (n *mockAgent) configure(ctx context.Context, h hypervisor, id, sharePath string, config KataAgentConfig) error { +func (n *mockAgent) configure(ctx context.Context, h Hypervisor, id, sharePath string, config KataAgentConfig) error { return nil } -func (n *mockAgent) configureFromGrpc(ctx context.Context, h hypervisor, id string, config KataAgentConfig) error { +func (n *mockAgent) configureFromGrpc(ctx context.Context, h Hypervisor, id string, config KataAgentConfig) error { return nil } diff --git a/src/runtime/virtcontainers/mock_hypervisor_test.go b/src/runtime/virtcontainers/mock_hypervisor_test.go index e7da0e18a2..ad52b5d928 100644 --- a/src/runtime/virtcontainers/mock_hypervisor_test.go +++ b/src/runtime/virtcontainers/mock_hypervisor_test.go @@ -47,7 +47,7 @@ func TestMockHypervisorCreateVM(t *testing.T) { func TestMockHypervisorStartSandbox(t *testing.T) { var m *mockHypervisor - assert.NoError(t, m.StartVM(context.Background(), vmStartTimeout)) + assert.NoError(t, m.StartVM(context.Background(), VmStartTimeout)) } func TestMockHypervisorStopSandbox(t *testing.T) { diff --git a/src/runtime/virtcontainers/monitor.go b/src/runtime/virtcontainers/monitor.go index 0b9e5816a1..c711f95568 100644 --- a/src/runtime/virtcontainers/monitor.go +++ b/src/runtime/virtcontainers/monitor.go @@ -142,6 +142,7 @@ func (m *monitor) watchAgent(ctx context.Context) { func (m *monitor) watchHypervisor(ctx context.Context) error { if err := m.sandbox.hypervisor.Check(); err != nil { m.notify(ctx, errors.Wrapf(err, "failed to ping hypervisor process")) + m.notify(ctx, errors.Wrapf(err, "failed to ping Hypervisor process")) return err } return nil diff --git a/src/runtime/virtcontainers/network.go b/src/runtime/virtcontainers/network.go index c4229dd4fc..c682418f3b 100644 --- a/src/runtime/virtcontainers/network.go +++ b/src/runtime/virtcontainers/network.go @@ -426,7 +426,7 @@ func getLinkByName(netHandle *netlink.Handle, name string, expectedLink netlink. } // The endpoint type should dictate how the connection needs to happen. -func xConnectVMNetwork(ctx context.Context, endpoint Endpoint, h hypervisor) error { +func xConnectVMNetwork(ctx context.Context, endpoint Endpoint, h Hypervisor) error { var err error span, ctx := networkTrace(ctx, "xConnectVMNetwork", endpoint) @@ -701,7 +701,7 @@ func setupTCFiltering(ctx context.Context, endpoint Endpoint, queues int, disabl attrs = link.Attrs() // Save the veth MAC address to the TAP so that it can later be used - // to build the hypervisor command line. This MAC address has to be + // to build the Hypervisor command line. This MAC address has to be // the one inside the VM in order to avoid any firewall issues. The // bridge created by the network plugin on the host actually expects // to see traffic from this MAC address and not another one. @@ -1413,7 +1413,7 @@ func (n *Network) PostAdd(ctx context.Context, ns *NetworkNamespace, hotplug boo // Remove network endpoints in the network namespace. It also deletes the network // namespace in case the namespace has been created by us. -func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor hypervisor) error { +func (n *Network) Remove(ctx context.Context, ns *NetworkNamespace, hypervisor Hypervisor) error { span, ctx := n.trace(ctx, "Remove") defer span.End() diff --git a/src/runtime/virtcontainers/physical_endpoint.go b/src/runtime/virtcontainers/physical_endpoint.go index 96fa10944e..a8703aee2d 100644 --- a/src/runtime/virtcontainers/physical_endpoint.go +++ b/src/runtime/virtcontainers/physical_endpoint.go @@ -121,12 +121,12 @@ func (endpoint *PhysicalEndpoint) Detach(ctx context.Context, netNsCreated bool, } // HotAttach for physical endpoint not supported yet -func (endpoint *PhysicalEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *PhysicalEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { return fmt.Errorf("PhysicalEndpoint does not support Hot attach") } // HotDetach for physical endpoint not supported yet -func (endpoint *PhysicalEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *PhysicalEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { return fmt.Errorf("PhysicalEndpoint does not support Hot detach") } diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index 107474f77d..52ffb4b5a6 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -54,9 +54,9 @@ var sandboxTracingTags = map[string]string{ } const ( - // vmStartTimeout represents the time in seconds a sandbox can wait before + // VmStartTimeout represents the time in seconds a sandbox can wait before // to consider the VM starting operation failed. - vmStartTimeout = 10 + VmStartTimeout = 10 // DirMode is the permission bits used for creating a directory DirMode = os.FileMode(0750) | os.ModeDir @@ -171,7 +171,7 @@ type Sandbox struct { ctx context.Context devManager api.DeviceManager factory Factory - hypervisor hypervisor + hypervisor Hypervisor agent agent store persistapi.PersistDriver @@ -1199,7 +1199,7 @@ func (s *Sandbox) startVM(ctx context.Context) (err error) { return vm.assignSandbox(s) } - return s.hypervisor.StartVM(ctx, vmStartTimeout) + return s.hypervisor.StartVM(ctx, VmStartTimeout) }); err != nil { return err } diff --git a/src/runtime/virtcontainers/tap_endpoint.go b/src/runtime/virtcontainers/tap_endpoint.go index 9b40f218fa..5cbcb2532b 100644 --- a/src/runtime/virtcontainers/tap_endpoint.go +++ b/src/runtime/virtcontainers/tap_endpoint.go @@ -90,7 +90,7 @@ func (endpoint *TapEndpoint) Detach(ctx context.Context, netNsCreated bool, netN } // HotAttach for the tap endpoint uses hot plug device -func (endpoint *TapEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *TapEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { networkLogger().Info("Hot attaching tap endpoint") span, ctx := tapTrace(ctx, "HotAttach", endpoint) @@ -109,7 +109,7 @@ func (endpoint *TapEndpoint) HotAttach(ctx context.Context, h hypervisor) error } // HotDetach for the tap endpoint uses hot pull device -func (endpoint *TapEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *TapEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { networkLogger().Info("Hot detaching tap endpoint") span, ctx := tapTrace(ctx, "HotDetach", endpoint) diff --git a/src/runtime/virtcontainers/tuntap_endpoint.go b/src/runtime/virtcontainers/tuntap_endpoint.go index ed1e2d4db6..0e899c2b42 100644 --- a/src/runtime/virtcontainers/tuntap_endpoint.go +++ b/src/runtime/virtcontainers/tuntap_endpoint.go @@ -101,7 +101,7 @@ func (endpoint *TuntapEndpoint) Detach(ctx context.Context, netNsCreated bool, n } // HotAttach for the tun/tap endpoint uses hot plug device -func (endpoint *TuntapEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *TuntapEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { networkLogger().Info("Hot attaching tun/tap endpoint") span, ctx := tuntapTrace(ctx, "HotAttach", endpoint) @@ -120,7 +120,7 @@ func (endpoint *TuntapEndpoint) HotAttach(ctx context.Context, h hypervisor) err } // HotDetach for the tun/tap endpoint uses hot pull device -func (endpoint *TuntapEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *TuntapEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { networkLogger().Info("Hot detaching tun/tap endpoint") span, ctx := tuntapTrace(ctx, "HotDetach", endpoint) diff --git a/src/runtime/virtcontainers/veth_endpoint.go b/src/runtime/virtcontainers/veth_endpoint.go index 2caa50c843..8a566b13a9 100644 --- a/src/runtime/virtcontainers/veth_endpoint.go +++ b/src/runtime/virtcontainers/veth_endpoint.go @@ -124,7 +124,7 @@ func (endpoint *VethEndpoint) Detach(ctx context.Context, netNsCreated bool, net } // HotAttach for the veth endpoint uses hot plug device -func (endpoint *VethEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *VethEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { span, ctx := vethTrace(ctx, "HotAttach", endpoint) defer span.End() @@ -141,7 +141,7 @@ func (endpoint *VethEndpoint) HotAttach(ctx context.Context, h hypervisor) error } // HotDetach for the veth endpoint uses hot pull device -func (endpoint *VethEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *VethEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { if !netNsCreated { return nil } diff --git a/src/runtime/virtcontainers/vhostuser_endpoint.go b/src/runtime/virtcontainers/vhostuser_endpoint.go index d6f7d13941..4be986cb65 100644 --- a/src/runtime/virtcontainers/vhostuser_endpoint.go +++ b/src/runtime/virtcontainers/vhostuser_endpoint.go @@ -105,12 +105,12 @@ func (endpoint *VhostUserEndpoint) Detach(ctx context.Context, netNsCreated bool } // HotAttach for vhostuser endpoint not supported yet -func (endpoint *VhostUserEndpoint) HotAttach(ctx context.Context, h hypervisor) error { +func (endpoint *VhostUserEndpoint) HotAttach(ctx context.Context, h Hypervisor) error { return fmt.Errorf("VhostUserEndpoint does not support Hot attach") } // HotDetach for vhostuser endpoint not supported yet -func (endpoint *VhostUserEndpoint) HotDetach(ctx context.Context, h hypervisor, netNsCreated bool, netNsPath string) error { +func (endpoint *VhostUserEndpoint) HotDetach(ctx context.Context, h Hypervisor, netNsCreated bool, netNsPath string) error { return fmt.Errorf("VhostUserEndpoint does not support Hot detach") } diff --git a/src/runtime/virtcontainers/vm.go b/src/runtime/virtcontainers/vm.go index b77da81c30..13749941a5 100644 --- a/src/runtime/virtcontainers/vm.go +++ b/src/runtime/virtcontainers/vm.go @@ -23,7 +23,7 @@ var urandomDev = "/dev/urandom" // VM is abstraction of a virtual machine. type VM struct { - hypervisor hypervisor + hypervisor Hypervisor agent agent store persistapi.PersistDriver @@ -130,7 +130,7 @@ func NewVM(ctx context.Context, config VMConfig) (*VM, error) { } // 3. boot up guest vm - if err = hypervisor.StartVM(ctx, vmStartTimeout); err != nil { + if err = hypervisor.StartVM(ctx, VmStartTimeout); err != nil { return nil, err } @@ -233,7 +233,7 @@ func (v *VM) Resume(ctx context.Context) error { // Start kicks off a configured VM. func (v *VM) Start(ctx context.Context) error { v.logger().Info("start vm") - return v.hypervisor.StartVM(ctx, vmStartTimeout) + return v.hypervisor.StartVM(ctx, VmStartTimeout) } // Disconnect agent connections to a VM