virtcontainers: update KataAgentConfig to support vsocks

add extra field in KataAgentConfig structure to specify if the
kata agent have to use a vsock instead of serial port.

Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
Julio Montes 2018-07-25 07:58:23 -05:00
parent 3adc8626e8
commit 1515bd07a1
4 changed files with 13 additions and 11 deletions

View File

@ -428,8 +428,9 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
case kataAgentTableType: case kataAgentTableType:
config.AgentType = kataAgentTableType config.AgentType = kataAgentTableType
config.AgentConfig = vc.KataAgentConfig{} config.AgentConfig = vc.KataAgentConfig{
UseVSock: config.HypervisorConfig.UseVSock,
}
} }
} }

View File

@ -128,7 +128,7 @@ func TestNewAgentConfigFromHyperstartAgentType(t *testing.T) {
} }
func TestNewAgentConfigFromKataAgentType(t *testing.T) { func TestNewAgentConfigFromKataAgentType(t *testing.T) {
agentConfig := KataAgentConfig{} agentConfig := KataAgentConfig{UseVSock: true}
sandboxConfig := SandboxConfig{ sandboxConfig := SandboxConfig{
AgentType: KataContainersAgent, AgentType: KataContainersAgent,

View File

@ -60,6 +60,7 @@ var (
// to reach the Kata Containers agent. // to reach the Kata Containers agent.
type KataAgentConfig struct { type KataAgentConfig struct {
LongLiveConn bool LongLiveConn bool
UseVSock bool
} }
type kataVSOCK struct { type kataVSOCK struct {
@ -128,8 +129,13 @@ func (k *kataAgent) getSharePath(id string) string {
} }
func (k *kataAgent) generateVMSocket(id string, c KataAgentConfig) error { func (k *kataAgent) generateVMSocket(id string, c KataAgentConfig) error {
cid, port, err := parseVSOCKAddr(c.GRPCSocket) if c.UseVSock {
if err != nil { // We want to go through VSOCK. The VM VSOCK endpoint will be our gRPC.
k.Logger().Debug("agent: Using vsock VM socket endpoint")
// We dont know yet the context ID - set empty vsock configuration
k.vmSocket = kataVSOCK{}
} else {
k.Logger().Debug("agent: Using unix socket form VM socket endpoint")
// We need to generate a host UNIX socket path for the emulated serial port. // We need to generate a host UNIX socket path for the emulated serial port.
kataSock, err := utils.BuildSocketPath(k.getVMPath(id), defaultKataSocketName) kataSock, err := utils.BuildSocketPath(k.getVMPath(id), defaultKataSocketName)
if err != nil { if err != nil {
@ -142,12 +148,6 @@ func (k *kataAgent) generateVMSocket(id string, c KataAgentConfig) error {
HostPath: kataSock, HostPath: kataSock,
Name: defaultKataChannel, Name: defaultKataChannel,
} }
} else {
// We want to go through VSOCK. The VM VSOCK endpoint will be our gRPC.
k.vmSocket = kataVSOCK{
contextID: cid,
port: port,
}
} }
return nil return nil

View File

@ -676,6 +676,7 @@ func TestAgentPathAPI(t *testing.T) {
_, ok := k1.vmSocket.(Socket) _, ok := k1.vmSocket.(Socket)
assert.True(ok) assert.True(ok)
c.UseVSock = true
err = k2.generateVMSocket(id, c) err = k2.generateVMSocket(id, c)
assert.Nil(err) assert.Nil(err)
_, ok = k2.vmSocket.(kataVSOCK) _, ok = k2.vmSocket.(kataVSOCK)