mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-05 15:34:21 +01:00
virtcontainers: Rename the Network structure fields and methods
We are converting the Network structure into an interface, so that different host OSes can have different networking implementations for Kata. One step into that direction is to rename all the Network structure fields and methods to something that is less Linux networking namespace specific. This will make the Network interface naming consistent. Signed-off-by: Samuel Ortiz <s.ortiz@apple.com>
This commit is contained in:
committed by
Samuel Ortiz
parent
b858d0dedf
commit
5e119e90e8
@@ -148,15 +148,15 @@ func CreateSandbox(ctx context.Context, vci vc.VC, ociSpec specs.Spec, runtimeCo
|
||||
defer func() {
|
||||
// cleanup netns if kata creates it
|
||||
ns := sandboxConfig.NetworkConfig
|
||||
if err != nil && ns.NetNsCreated {
|
||||
if ex := cleanupNetNS(ns.NetNSPath); ex != nil {
|
||||
kataUtilsLogger.WithField("path", ns.NetNSPath).WithError(ex).Warn("failed to cleanup netns")
|
||||
if err != nil && ns.NetworkCreated {
|
||||
if ex := cleanupNetNS(ns.NetworkID); ex != nil {
|
||||
kataUtilsLogger.WithField("id", ns.NetworkID).WithError(ex).Warn("failed to cleanup network")
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
// Run pre-start OCI hooks.
|
||||
err = EnterNetNS(sandboxConfig.NetworkConfig.NetNSPath, func() error {
|
||||
err = EnterNetNS(sandboxConfig.NetworkConfig.NetworkID, func() error {
|
||||
return PreStartHooks(ctx, ociSpec, containerID, bundlePath)
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -26,8 +26,8 @@ const procMountInfoFile = "/proc/self/mountinfo"
|
||||
// EnterNetNS is free from any call to a go routine, and it calls
|
||||
// into runtime.LockOSThread(), meaning it won't be executed in a
|
||||
// different thread than the one expected by the caller.
|
||||
func EnterNetNS(netNSPath string, cb func() error) error {
|
||||
if netNSPath == "" {
|
||||
func EnterNetNS(networkID string, cb func() error) error {
|
||||
if networkID == "" {
|
||||
return cb()
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func EnterNetNS(netNSPath string, cb func() error) error {
|
||||
}
|
||||
defer currentNS.Close()
|
||||
|
||||
targetNS, err := ns.GetNS(netNSPath)
|
||||
targetNS, err := ns.GetNS(networkID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func EnterNetNS(netNSPath string, cb func() error) error {
|
||||
|
||||
// SetupNetworkNamespace create a network namespace
|
||||
func SetupNetworkNamespace(config *vc.NetworkConfig) error {
|
||||
if config.DisableNewNetNs {
|
||||
if config.DisableNewNetwork {
|
||||
kataUtilsLogger.Info("DisableNewNetNs is on, shim and hypervisor are running in the host netns")
|
||||
return nil
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func SetupNetworkNamespace(config *vc.NetworkConfig) error {
|
||||
var err error
|
||||
var n ns.NetNS
|
||||
|
||||
if config.NetNSPath == "" {
|
||||
if config.NetworkID == "" {
|
||||
if rootless.IsRootless() {
|
||||
n, err = rootless.NewNS()
|
||||
if err != nil {
|
||||
@@ -76,14 +76,14 @@ func SetupNetworkNamespace(config *vc.NetworkConfig) error {
|
||||
}
|
||||
}
|
||||
|
||||
config.NetNSPath = n.Path()
|
||||
config.NetNsCreated = true
|
||||
config.NetworkID = n.Path()
|
||||
config.NetworkCreated = true
|
||||
kataUtilsLogger.WithField("netns", n.Path()).Info("create netns")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
isHostNs, err := hostNetworkingRequested(config.NetNSPath)
|
||||
isHostNs, err := hostNetworkingRequested(config.NetworkID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -114,14 +114,14 @@ func TestSetupNetworkNamespace(t *testing.T) {
|
||||
|
||||
// Network namespace same as the host
|
||||
config := &vc.NetworkConfig{
|
||||
NetNSPath: "/proc/self/ns/net",
|
||||
NetworkID: "/proc/self/ns/net",
|
||||
}
|
||||
err := SetupNetworkNamespace(config)
|
||||
assert.Error(err)
|
||||
|
||||
// Non-existent netns path
|
||||
config = &vc.NetworkConfig{
|
||||
NetNSPath: "/proc/123456789/ns/net",
|
||||
NetworkID: "/proc/123456789/ns/net",
|
||||
}
|
||||
err = SetupNetworkNamespace(config)
|
||||
assert.Error(err)
|
||||
@@ -130,7 +130,7 @@ func TestSetupNetworkNamespace(t *testing.T) {
|
||||
n, err := testutils.NewNS()
|
||||
assert.NoError(err)
|
||||
config = &vc.NetworkConfig{
|
||||
NetNSPath: n.Path(),
|
||||
NetworkID: n.Path(),
|
||||
}
|
||||
err = SetupNetworkNamespace(config)
|
||||
assert.NoError(err)
|
||||
@@ -140,16 +140,16 @@ func TestSetupNetworkNamespace(t *testing.T) {
|
||||
config = &vc.NetworkConfig{}
|
||||
err = SetupNetworkNamespace(config)
|
||||
assert.NoError(err)
|
||||
n, err = ns.GetNS(config.NetNSPath)
|
||||
n, err = ns.GetNS(config.NetworkID)
|
||||
assert.NoError(err)
|
||||
assert.NotNil(n)
|
||||
assert.True(config.NetNsCreated)
|
||||
assert.True(config.NetworkCreated)
|
||||
n.Close()
|
||||
unix.Unmount(config.NetNSPath, unix.MNT_DETACH)
|
||||
os.RemoveAll(config.NetNSPath)
|
||||
unix.Unmount(config.NetworkID, unix.MNT_DETACH)
|
||||
os.RemoveAll(config.NetworkID)
|
||||
|
||||
// Config with DisableNewNetNs
|
||||
config = &vc.NetworkConfig{DisableNewNetNs: true}
|
||||
config = &vc.NetworkConfig{DisableNewNetwork: true}
|
||||
err = SetupNetworkNamespace(config)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
@@ -318,11 +318,11 @@ func networkConfig(ocispec specs.Spec, config RuntimeConfig) (vc.NetworkConfig,
|
||||
}
|
||||
|
||||
if n.Path != "" {
|
||||
netConf.NetNSPath = n.Path
|
||||
netConf.NetworkID = n.Path
|
||||
}
|
||||
}
|
||||
netConf.InterworkingModel = config.InterNetworkModel
|
||||
netConf.DisableNewNetNs = config.DisableNewNetNs
|
||||
netConf.DisableNewNetwork = config.DisableNewNetNs
|
||||
|
||||
return netConf, nil
|
||||
}
|
||||
@@ -798,7 +798,7 @@ func addRuntimeConfigOverrides(ocispec specs.Spec, sbConfig *vc.SandboxConfig, r
|
||||
}
|
||||
|
||||
if err := newAnnotationConfiguration(ocispec, vcAnnotations.DisableNewNetNs).setBool(func(disableNewNetNs bool) {
|
||||
sbConfig.NetworkConfig.DisableNewNetNs = disableNewNetNs
|
||||
sbConfig.NetworkConfig.DisableNewNetwork = disableNewNetNs
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -822,7 +822,7 @@ func TestAddRuntimeAnnotations(t *testing.T) {
|
||||
addAnnotations(ocispec, &config, runtimeConfig)
|
||||
assert.Equal(config.DisableGuestSeccomp, true)
|
||||
assert.Equal(config.SandboxCgroupOnly, true)
|
||||
assert.Equal(config.NetworkConfig.DisableNewNetNs, true)
|
||||
assert.Equal(config.NetworkConfig.DisableNewNetwork, true)
|
||||
assert.Equal(config.NetworkConfig.InterworkingModel, vc.NetXConnectMacVtapModel)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user