mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-07 16:34:28 +01:00
Merge pull request #365 from liubin/feature/delete-shim-364
runtime: clean up shim abstraction
This commit is contained in:
@@ -30,7 +30,6 @@ const (
|
||||
|
||||
var (
|
||||
defaultProxy = vc.KataProxyType
|
||||
defaultShim = vc.KataShimType
|
||||
|
||||
// if true, enable opentracing support.
|
||||
tracing = false
|
||||
@@ -42,7 +41,7 @@ var (
|
||||
//
|
||||
// [<component>.<type>]
|
||||
//
|
||||
// The components are hypervisor, proxy, shim and agent. For example,
|
||||
// The components are hypervisor, proxy and agent. For example,
|
||||
//
|
||||
// [proxy.kata]
|
||||
//
|
||||
@@ -57,9 +56,6 @@ const (
|
||||
// supported proxy component types
|
||||
kataProxyTableType = "kata"
|
||||
|
||||
// supported shim component types
|
||||
kataShimTableType = "kata"
|
||||
|
||||
// supported agent component types
|
||||
kataAgentTableType = "kata"
|
||||
|
||||
@@ -70,7 +66,6 @@ const (
|
||||
type tomlConfig struct {
|
||||
Hypervisor map[string]hypervisor
|
||||
Proxy map[string]proxy
|
||||
Shim map[string]shim
|
||||
Agent map[string]agent
|
||||
Runtime runtime
|
||||
Factory factory
|
||||
@@ -150,12 +145,6 @@ type runtime struct {
|
||||
InterNetworkModel string `toml:"internetworking_model"`
|
||||
}
|
||||
|
||||
type shim struct {
|
||||
Path string `toml:"path"`
|
||||
Debug bool `toml:"enable_debug"`
|
||||
Tracing bool `toml:"enable_tracing"`
|
||||
}
|
||||
|
||||
type agent struct {
|
||||
Debug bool `toml:"enable_debug"`
|
||||
Tracing bool `toml:"enable_tracing"`
|
||||
@@ -474,24 +463,6 @@ func (p proxy) debug() bool {
|
||||
return p.Debug
|
||||
}
|
||||
|
||||
func (s shim) path() (string, error) {
|
||||
p := s.Path
|
||||
|
||||
if p == "" {
|
||||
p = defaultShimPath
|
||||
}
|
||||
|
||||
return ResolvePath(p)
|
||||
}
|
||||
|
||||
func (s shim) debug() bool {
|
||||
return s.Debug
|
||||
}
|
||||
|
||||
func (s shim) trace() bool {
|
||||
return s.Tracing
|
||||
}
|
||||
|
||||
func (a agent) debug() bool {
|
||||
return a.Debug
|
||||
}
|
||||
@@ -898,19 +869,6 @@ func newFactoryConfig(f factory) (oci.FactoryConfig, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newShimConfig(s shim) (vc.ShimConfig, error) {
|
||||
path, err := s.path()
|
||||
if err != nil {
|
||||
return vc.ShimConfig{}, err
|
||||
}
|
||||
|
||||
return vc.ShimConfig{
|
||||
Path: path,
|
||||
Debug: s.debug(),
|
||||
Trace: s.trace(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func updateRuntimeConfigHypervisor(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
|
||||
for k, hypervisor := range tomlConf.Hypervisor {
|
||||
var err error
|
||||
@@ -1011,32 +969,6 @@ func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oc
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateRuntimeConfigShim(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig, builtIn bool) error {
|
||||
if builtIn {
|
||||
config.ShimType = vc.KataBuiltInShimType
|
||||
config.ShimConfig = vc.ShimConfig{}
|
||||
return nil
|
||||
}
|
||||
|
||||
for k, shim := range tomlConf.Shim {
|
||||
switch k {
|
||||
case kataShimTableType:
|
||||
config.ShimType = vc.KataShimType
|
||||
default:
|
||||
return fmt.Errorf("%s shim is not supported", k)
|
||||
}
|
||||
|
||||
shConfig, err := newShimConfig(shim)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %v", configPath, err)
|
||||
}
|
||||
|
||||
config.ShimConfig = shConfig
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetKernelParams adds the user-specified kernel parameters (from the
|
||||
// configuration file) to the defaults so that the former take priority.
|
||||
func SetKernelParams(runtimeConfig *oci.RuntimeConfig) error {
|
||||
@@ -1111,10 +1043,6 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
|
||||
return err
|
||||
}
|
||||
|
||||
if err := updateRuntimeConfigShim(configPath, tomlConf, config, builtIn); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fConfig, err := newFactoryConfig(tomlConf.Factory)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%v: %v", configPath, err)
|
||||
@@ -1193,7 +1121,6 @@ func initConfig() (config oci.RuntimeConfig, err error) {
|
||||
AgentType: defaultAgent,
|
||||
AgentConfig: defaultAgentConfig,
|
||||
ProxyType: defaultProxy,
|
||||
ShimType: defaultShim,
|
||||
}
|
||||
|
||||
return config, nil
|
||||
@@ -1336,11 +1263,6 @@ func checkNetNsConfig(config oci.RuntimeConfig) error {
|
||||
if config.InterNetworkModel != vc.NetXConnectNoneModel {
|
||||
return fmt.Errorf("config disable_new_netns only works with 'none' internetworking_model")
|
||||
}
|
||||
} else if shim, ok := config.ShimConfig.(vc.ShimConfig); ok && shim.Trace {
|
||||
// Normally, the shim runs in a separate network namespace.
|
||||
// But when tracing, the shim process needs to be able to talk
|
||||
// to the Jaeger agent running in the host network namespace.
|
||||
return errors.New("Shim tracing requires disable_new_netns for Jaeger agent communication")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -31,7 +31,6 @@ var (
|
||||
proxyDebug = false
|
||||
runtimeDebug = false
|
||||
runtimeTrace = false
|
||||
shimDebug = false
|
||||
netmonDebug = false
|
||||
agentDebug = false
|
||||
agentTrace = false
|
||||
@@ -72,7 +71,6 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
kernelPath := path.Join(dir, "kernel")
|
||||
kernelParams := "foo=bar xyz"
|
||||
imagePath := path.Join(dir, "image")
|
||||
shimPath := path.Join(dir, "shim")
|
||||
proxyPath := path.Join(dir, "proxy")
|
||||
netmonPath := path.Join(dir, "netmon")
|
||||
logDir := path.Join(dir, "logs")
|
||||
@@ -94,7 +92,6 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
ImagePath: imagePath,
|
||||
KernelParams: kernelParams,
|
||||
MachineType: machineType,
|
||||
ShimPath: shimPath,
|
||||
ProxyPath: proxyPath,
|
||||
NetmonPath: netmonPath,
|
||||
LogPath: logPath,
|
||||
@@ -113,7 +110,6 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
RuntimeDebug: runtimeDebug,
|
||||
RuntimeTrace: runtimeTrace,
|
||||
ProxyDebug: proxyDebug,
|
||||
ShimDebug: shimDebug,
|
||||
NetmonDebug: netmonDebug,
|
||||
AgentDebug: agentDebug,
|
||||
AgentTrace: agentTrace,
|
||||
@@ -137,7 +133,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
return config, err
|
||||
}
|
||||
|
||||
files := []string{hypervisorPath, kernelPath, imagePath, shimPath, proxyPath}
|
||||
files := []string{hypervisorPath, kernelPath, imagePath, proxyPath}
|
||||
|
||||
for _, file := range files {
|
||||
// create the resource (which must be >0 bytes)
|
||||
@@ -179,10 +175,6 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
Path: proxyPath,
|
||||
}
|
||||
|
||||
shimConfig := vc.ShimConfig{
|
||||
Path: shimPath,
|
||||
}
|
||||
|
||||
netmonConfig := vc.NetmonConfig{
|
||||
Path: netmonPath,
|
||||
Debug: false,
|
||||
@@ -204,9 +196,6 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
|
||||
ProxyType: defaultProxy,
|
||||
ProxyConfig: proxyConfig,
|
||||
|
||||
ShimType: defaultShim,
|
||||
ShimConfig: shimConfig,
|
||||
|
||||
NetmonConfig: netmonConfig,
|
||||
DisableNewNetNs: disableNewNetNs,
|
||||
|
||||
@@ -410,28 +399,6 @@ func TestConfigLoadConfigurationFailMissingKernel(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestConfigLoadConfigurationFailMissingShim(t *testing.T) {
|
||||
tmpdir, err := ioutil.TempDir(testDir, "runtime-config-")
|
||||
assert.NoError(t, err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
testLoadConfiguration(t, tmpdir,
|
||||
func(config testRuntimeConfig, configFile string, ignoreLogging bool) (bool, error) {
|
||||
expectFail := true
|
||||
|
||||
shimConfig, ok := config.RuntimeConfig.ShimConfig.(vc.ShimConfig)
|
||||
if !ok {
|
||||
return expectFail, fmt.Errorf("cannot determine shim config")
|
||||
}
|
||||
err = os.Remove(shimConfig.Path)
|
||||
if err != nil {
|
||||
return expectFail, err
|
||||
}
|
||||
|
||||
return expectFail, nil
|
||||
})
|
||||
}
|
||||
|
||||
func TestConfigLoadConfigurationFailUnreadableConfig(t *testing.T) {
|
||||
if tc.NotValid(ktu.NeedNonRoot()) {
|
||||
t.Skip(ktu.TestDisabledNeedNonRoot)
|
||||
@@ -517,7 +484,6 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
shimPath := path.Join(dir, "shim")
|
||||
proxyPath := path.Join(dir, "proxy")
|
||||
hypervisorPath := path.Join(dir, "hypervisor")
|
||||
defaultHypervisorPath = hypervisorPath
|
||||
@@ -565,9 +531,6 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
||||
[proxy.kata]
|
||||
path = "` + proxyPath + `"
|
||||
|
||||
[shim.kata]
|
||||
path = "` + shimPath + `"
|
||||
|
||||
[agent.kata]
|
||||
|
||||
[netmon]
|
||||
@@ -580,16 +543,6 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, config, err := LoadConfiguration(configPath, false, false)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected loadConfiguration to fail as shim path does not exist: %+v", config)
|
||||
}
|
||||
|
||||
err = createEmptyFile(shimPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = createEmptyFile(proxyPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -610,7 +563,7 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, config, err = LoadConfiguration(configPath, false, false)
|
||||
_, config, err := LoadConfiguration(configPath, false, false)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -641,10 +594,6 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
||||
Path: proxyPath,
|
||||
}
|
||||
|
||||
expectedShimConfig := vc.ShimConfig{
|
||||
Path: shimPath,
|
||||
}
|
||||
|
||||
expectedNetmonConfig := vc.NetmonConfig{
|
||||
Path: netmonPath,
|
||||
Debug: false,
|
||||
@@ -666,9 +615,6 @@ func TestMinimalRuntimeConfig(t *testing.T) {
|
||||
ProxyType: defaultProxy,
|
||||
ProxyConfig: expectedProxyConfig,
|
||||
|
||||
ShimType: defaultShim,
|
||||
ShimConfig: expectedShimConfig,
|
||||
|
||||
NetmonConfig: expectedNetmonConfig,
|
||||
|
||||
FactoryConfig: expectedFactoryConfig,
|
||||
@@ -693,7 +639,6 @@ func TestMinimalRuntimeConfigWithVsock(t *testing.T) {
|
||||
imagePath := path.Join(dir, "image.img")
|
||||
initrdPath := path.Join(dir, "initrd.img")
|
||||
proxyPath := path.Join(dir, "proxy")
|
||||
shimPath := path.Join(dir, "shim")
|
||||
hypervisorPath := path.Join(dir, "hypervisor")
|
||||
kernelPath := path.Join(dir, "kernel")
|
||||
|
||||
@@ -716,7 +661,7 @@ func TestMinimalRuntimeConfigWithVsock(t *testing.T) {
|
||||
defaultHypervisorPath = hypervisorPath
|
||||
defaultKernelPath = kernelPath
|
||||
|
||||
for _, file := range []string{proxyPath, shimPath, hypervisorPath, kernelPath, imagePath} {
|
||||
for _, file := range []string{proxyPath, hypervisorPath, kernelPath, imagePath} {
|
||||
err = WriteFile(file, "foo", testFileMode)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -733,9 +678,6 @@ func TestMinimalRuntimeConfigWithVsock(t *testing.T) {
|
||||
[proxy.kata]
|
||||
path = "` + proxyPath + `"
|
||||
|
||||
[shim.kata]
|
||||
path = "` + shimPath + `"
|
||||
|
||||
[agent.kata]
|
||||
`
|
||||
orgVHostVSockDevicePath := utils.VHostVSockDevicePath
|
||||
@@ -1073,39 +1015,6 @@ func TestNewClhHypervisorConfig(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestNewShimConfig(t *testing.T) {
|
||||
dir, err := ioutil.TempDir(testDir, "shim-config-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
shimPath := path.Join(dir, "shim")
|
||||
|
||||
shim := shim{
|
||||
Path: shimPath,
|
||||
}
|
||||
|
||||
_, err = newShimConfig(shim)
|
||||
if err == nil {
|
||||
t.Fatalf("Expected newShimConfig to fail as no paths exist")
|
||||
}
|
||||
|
||||
err = createEmptyFile(shimPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
shConfig, err := newShimConfig(shim)
|
||||
if err != nil {
|
||||
t.Fatalf("newShimConfig failed unexpectedly: %v", err)
|
||||
}
|
||||
|
||||
if shConfig.Path != shimPath {
|
||||
t.Errorf("Expected shim path %v, got %v", shimPath, shConfig.Path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHypervisorDefaults(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -1368,50 +1277,6 @@ func TestProxyDefaults(t *testing.T) {
|
||||
assert.True(p.debug())
|
||||
}
|
||||
|
||||
func TestShimDefaults(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tmpdir, err := ioutil.TempDir(testDir, "")
|
||||
assert.NoError(err)
|
||||
defer os.RemoveAll(tmpdir)
|
||||
|
||||
testShimPath := filepath.Join(tmpdir, "shim")
|
||||
testShimLinkPath := filepath.Join(tmpdir, "shim-link")
|
||||
|
||||
err = createEmptyFile(testShimPath)
|
||||
assert.NoError(err)
|
||||
|
||||
err = syscall.Symlink(testShimPath, testShimLinkPath)
|
||||
assert.NoError(err)
|
||||
|
||||
savedShimPath := defaultShimPath
|
||||
|
||||
defer func() {
|
||||
defaultShimPath = savedShimPath
|
||||
}()
|
||||
|
||||
defaultShimPath = testShimPath
|
||||
s := shim{}
|
||||
p, err := s.path()
|
||||
assert.NoError(err)
|
||||
assert.Equal(p, defaultShimPath, "default shim path wrong")
|
||||
|
||||
// test path resolution
|
||||
defaultShimPath = testShimLinkPath
|
||||
s = shim{}
|
||||
p, err = s.path()
|
||||
assert.NoError(err)
|
||||
assert.Equal(p, testShimPath)
|
||||
|
||||
assert.False(s.debug())
|
||||
s.Debug = true
|
||||
assert.True(s.debug())
|
||||
|
||||
assert.False(s.trace())
|
||||
s.Tracing = true
|
||||
assert.True(s.trace())
|
||||
}
|
||||
|
||||
func TestAgentDefaults(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -1912,41 +1777,3 @@ func TestCheckFactoryConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckNetNsConfigShimTrace(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
type testData struct {
|
||||
networkModel vc.NetInterworkingModel
|
||||
disableNetNs bool
|
||||
shimTrace bool
|
||||
expectError bool
|
||||
}
|
||||
|
||||
data := []testData{
|
||||
{vc.NetXConnectMacVtapModel, false, false, false},
|
||||
{vc.NetXConnectMacVtapModel, false, true, true},
|
||||
{vc.NetXConnectMacVtapModel, true, true, true},
|
||||
{vc.NetXConnectMacVtapModel, true, false, true},
|
||||
{vc.NetXConnectNoneModel, true, false, false},
|
||||
{vc.NetXConnectNoneModel, true, true, false},
|
||||
}
|
||||
|
||||
for i, d := range data {
|
||||
config := oci.RuntimeConfig{
|
||||
DisableNewNetNs: d.disableNetNs,
|
||||
InterNetworkModel: d.networkModel,
|
||||
ShimConfig: vc.ShimConfig{
|
||||
Trace: d.shimTrace,
|
||||
},
|
||||
}
|
||||
|
||||
err := checkNetNsConfig(config)
|
||||
|
||||
if d.expectError {
|
||||
assert.Error(err, "test %d (%+v)", i, d)
|
||||
} else {
|
||||
assert.NoError(err, "test %d (%+v)", i, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,6 @@ func newTestRuntimeConfig(dir, consolePath string, create bool) (oci.RuntimeConf
|
||||
HypervisorConfig: hypervisorConfig,
|
||||
AgentType: vc.KataContainersAgent,
|
||||
ProxyType: vc.KataProxyType,
|
||||
ShimType: vc.KataShimType,
|
||||
Console: consolePath,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user