Allow moving netns directory into StateDir

Signed-off-by: Lorenz Brun <lorenz@nexantic.com>
This commit is contained in:
Lorenz Brun
2021-01-27 13:05:30 +01:00
committed by Lorenz Brun
parent e288feacf3
commit 36d0bc1f2b
6 changed files with 22 additions and 10 deletions

View File

@@ -253,6 +253,10 @@ type PluginConfig struct {
// isolation, security and early detection of issues in the mount configuration when using
// ReadOnlyRootFilesystem since containers won't silently mount a temporary volume.
IgnoreImageDefinedVolumes bool `toml:"ignore_image_defined_volumes" json:"ignoreImageDefinedVolumes"`
// NetNSMountsUnderStateDir places all mounts for network namespaces under StateDir/netns instead
// of being placed under the hardcoded directory /var/run/netns. Changing this setting requires
// that all containers are deleted.
NetNSMountsUnderStateDir bool `toml:"netns_mounts_under_state_dir" json:"netnsMountsUnderStateDir"`
}
// X509KeyPairStreaming contains the x509 configuration for streaming

View File

@@ -19,6 +19,7 @@ package server
import (
"encoding/json"
"math"
"path/filepath"
goruntime "runtime"
"strings"
@@ -120,7 +121,11 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
// handle. NetNSPath in sandbox metadata and NetNS is non empty only for non host network
// namespaces. If the pod is in host network namespace then both are empty and should not
// be used.
sandbox.NetNS, err = netns.NewNetNS()
var netnsMountDir string = "/var/run/netns"
if c.config.NetNSMountsUnderStateDir {
netnsMountDir = filepath.Join(c.config.StateDir, "netns")
}
sandbox.NetNS, err = netns.NewNetNS(netnsMountDir)
if err != nil {
return nil, errors.Wrapf(err, "failed to create network namespace for sandbox %q", id)
}