mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-23 00:04:24 +01:00
Merge pull request #384 from liubin/377/delete-agent-abstraction
runtime: remove agent abstraction
This commit is contained in:
@@ -166,7 +166,6 @@ var initFactoryCommand = cli.Command{
|
||||
VMConfig: vc.VMConfig{
|
||||
HypervisorType: runtimeConfig.HypervisorType,
|
||||
HypervisorConfig: runtimeConfig.HypervisorConfig,
|
||||
AgentType: runtimeConfig.AgentType,
|
||||
AgentConfig: runtimeConfig.AgentConfig,
|
||||
ProxyType: runtimeConfig.ProxyType,
|
||||
ProxyConfig: runtimeConfig.ProxyConfig,
|
||||
@@ -256,7 +255,6 @@ var destroyFactoryCommand = cli.Command{
|
||||
VMConfig: vc.VMConfig{
|
||||
HypervisorType: runtimeConfig.HypervisorType,
|
||||
HypervisorConfig: runtimeConfig.HypervisorConfig,
|
||||
AgentType: runtimeConfig.AgentType,
|
||||
AgentConfig: runtimeConfig.AgentConfig,
|
||||
ProxyType: runtimeConfig.ProxyType,
|
||||
ProxyConfig: runtimeConfig.ProxyConfig,
|
||||
@@ -314,7 +312,6 @@ var statusFactoryCommand = cli.Command{
|
||||
VMConfig: vc.VMConfig{
|
||||
HypervisorType: runtimeConfig.HypervisorType,
|
||||
HypervisorConfig: runtimeConfig.HypervisorConfig,
|
||||
AgentType: runtimeConfig.AgentType,
|
||||
AgentConfig: runtimeConfig.AgentConfig,
|
||||
ProxyType: runtimeConfig.ProxyType,
|
||||
ProxyConfig: runtimeConfig.ProxyConfig,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -73,11 +74,19 @@ func TestFactoryCLIFunctionInit(t *testing.T) {
|
||||
runtimeConfig.FactoryConfig.Template = true
|
||||
runtimeConfig.FactoryConfig.TemplatePath = "/run/vc/vm/template"
|
||||
runtimeConfig.HypervisorType = vc.MockHypervisor
|
||||
runtimeConfig.AgentType = vc.NoopAgentType
|
||||
runtimeConfig.ProxyType = vc.NoopProxyType
|
||||
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||
fn, ok = initFactoryCommand.Action.(func(context *cli.Context) error)
|
||||
assert.True(ok)
|
||||
|
||||
// config mock agent
|
||||
stdCtx, err := cliContextToContext(ctx)
|
||||
if err != nil {
|
||||
stdCtx = context.Background()
|
||||
}
|
||||
stdCtx = vc.WithNewAgentFunc(stdCtx, vc.NewMockAgent)
|
||||
ctx.App.Metadata["context"] = stdCtx
|
||||
|
||||
err = fn(ctx)
|
||||
assert.Nil(err)
|
||||
}
|
||||
@@ -109,7 +118,6 @@ func TestFactoryCLIFunctionDestroy(t *testing.T) {
|
||||
// With template
|
||||
runtimeConfig.FactoryConfig.Template = true
|
||||
runtimeConfig.HypervisorType = vc.MockHypervisor
|
||||
runtimeConfig.AgentType = vc.NoopAgentType
|
||||
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||
fn, ok = destroyFactoryCommand.Action.(func(context *cli.Context) error)
|
||||
assert.True(ok)
|
||||
@@ -145,7 +153,6 @@ func TestFactoryCLIFunctionStatus(t *testing.T) {
|
||||
// With template
|
||||
runtimeConfig.FactoryConfig.Template = true
|
||||
runtimeConfig.HypervisorType = vc.MockHypervisor
|
||||
runtimeConfig.AgentType = vc.NoopAgentType
|
||||
ctx.App.Metadata["runtimeConfig"] = runtimeConfig
|
||||
err = fn(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
@@ -114,7 +114,6 @@ type ProxyInfo struct {
|
||||
|
||||
// AgentInfo stores agent details
|
||||
type AgentInfo struct {
|
||||
Type string
|
||||
Debug bool
|
||||
Trace bool
|
||||
TraceMode string
|
||||
@@ -296,23 +295,13 @@ func getCommandVersion(cmd string) (string, error) {
|
||||
}
|
||||
|
||||
func getAgentInfo(config oci.RuntimeConfig) (AgentInfo, error) {
|
||||
agent := AgentInfo{
|
||||
Type: string(config.AgentType),
|
||||
}
|
||||
agent := AgentInfo{}
|
||||
|
||||
switch config.AgentType {
|
||||
case vc.KataContainersAgent:
|
||||
agentConfig, ok := config.AgentConfig.(vc.KataAgentConfig)
|
||||
if !ok {
|
||||
return AgentInfo{}, errors.New("cannot determine Kata agent config")
|
||||
}
|
||||
agent.Debug = agentConfig.Debug
|
||||
agent.Trace = agentConfig.Trace
|
||||
agent.TraceMode = agentConfig.TraceMode
|
||||
agent.TraceType = agentConfig.TraceType
|
||||
default:
|
||||
// Nothing useful to report for the other agent types
|
||||
}
|
||||
agentConfig := config.AgentConfig
|
||||
agent.Debug = agentConfig.Debug
|
||||
agent.Trace = agentConfig.Trace
|
||||
agent.TraceMode = agentConfig.TraceMode
|
||||
agent.TraceType = agentConfig.TraceType
|
||||
|
||||
return agent, nil
|
||||
}
|
||||
|
||||
@@ -198,13 +198,8 @@ func getExpectedNetmonDetails(config oci.RuntimeConfig) (NetmonInfo, error) {
|
||||
|
||||
func getExpectedAgentDetails(config oci.RuntimeConfig) (AgentInfo, error) {
|
||||
|
||||
agentConfig, ok := config.AgentConfig.(vc.KataAgentConfig)
|
||||
if !ok {
|
||||
return AgentInfo{}, fmt.Errorf("expected KataAgentConfig, got %T", config.AgentConfig)
|
||||
}
|
||||
|
||||
agentConfig := config.AgentConfig
|
||||
return AgentInfo{
|
||||
Type: string(config.AgentType),
|
||||
Debug: agentConfig.Debug,
|
||||
Trace: agentConfig.Trace,
|
||||
|
||||
@@ -490,7 +485,6 @@ func TestEnvGetEnvInfo(t *testing.T) {
|
||||
runtimeDebug = toggle
|
||||
runtimeTrace = toggle
|
||||
agentDebug = toggle
|
||||
agentTrace = toggle
|
||||
|
||||
configFile, config, err := makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(t, err)
|
||||
@@ -536,13 +530,8 @@ func TestEnvGetEnvInfoAgentError(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
configFile, config, err := makeRuntimeConfig(tmpdir)
|
||||
_, _, err = makeRuntimeConfig(tmpdir)
|
||||
assert.NoError(err)
|
||||
|
||||
config.AgentConfig = "invalid agent config"
|
||||
|
||||
_, err = getEnvInfo(configFile, config)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestEnvGetEnvInfoNoOSRelease(t *testing.T) {
|
||||
@@ -728,8 +717,7 @@ func TestEnvGetAgentInfo(t *testing.T) {
|
||||
|
||||
assert.Equal(t, expectedAgent, agent)
|
||||
|
||||
agentConfig, ok := config.AgentConfig.(vc.KataAgentConfig)
|
||||
assert.True(t, ok)
|
||||
agentConfig := config.AgentConfig
|
||||
|
||||
agentConfig.Debug = true
|
||||
config.AgentConfig = agentConfig
|
||||
@@ -746,10 +734,6 @@ func TestEnvGetAgentInfo(t *testing.T) {
|
||||
assert.True(t, agent.Trace)
|
||||
assert.Equal(t, agent.TraceMode, "traceMode")
|
||||
assert.Equal(t, agent.TraceType, "traceType")
|
||||
|
||||
config.AgentConfig = "I am the wrong type"
|
||||
_, err = getAgentInfo(config)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func testEnvShowTOMLSettings(t *testing.T, tmpdir string, tmpfile *os.File) error {
|
||||
@@ -777,9 +761,7 @@ func testEnvShowTOMLSettings(t *testing.T, tmpdir string, tmpfile *os.File) erro
|
||||
Debug: false,
|
||||
}
|
||||
|
||||
agent := AgentInfo{
|
||||
Type: "agent-type",
|
||||
}
|
||||
agent := AgentInfo{}
|
||||
|
||||
expectedHostDetails, err := getExpectedHostDetails(tmpdir)
|
||||
assert.NoError(t, err)
|
||||
@@ -839,9 +821,7 @@ func testEnvShowJSONSettings(t *testing.T, tmpdir string, tmpfile *os.File) erro
|
||||
Debug: false,
|
||||
}
|
||||
|
||||
agent := AgentInfo{
|
||||
Type: "agent-type",
|
||||
}
|
||||
agent := AgentInfo{}
|
||||
|
||||
expectedHostDetails, err := getExpectedHostDetails(tmpdir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -242,7 +242,6 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf
|
||||
return oci.RuntimeConfig{
|
||||
HypervisorType: vc.QemuHypervisor,
|
||||
HypervisorConfig: hypervisorConfig,
|
||||
AgentType: vc.KataContainersAgent,
|
||||
ProxyType: vc.KataProxyType,
|
||||
Console: consolePath,
|
||||
}, nil
|
||||
|
||||
Reference in New Issue
Block a user