-
Notifications
You must be signed in to change notification settings - Fork 367
cli: add configuration option to use or not use host netns #733
Changes from all commits
f8f2962
6935279
14e5437
7a5a57d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,6 +108,7 @@ type proxy struct { | |
| type runtime struct { | ||
| Debug bool `toml:"enable_debug"` | ||
| Tracing bool `toml:"enable_tracing"` | ||
| DisableNewNetNs bool `toml:"disable_new_netns"` | ||
| InterNetworkModel string `toml:"internetworking_model"` | ||
| } | ||
|
|
||
|
|
@@ -598,9 +599,7 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat | |
| kataLog.Logger.Level = originalLoggerLevel | ||
| } | ||
|
|
||
| if tomlConf.Runtime.Tracing { | ||
| tracing = true | ||
| } | ||
| tracing = tomlConf.Runtime.Tracing | ||
|
|
||
| if tomlConf.Runtime.InterNetworkModel != "" { | ||
| err = config.InterNetworkModel.SetModel(tomlConf.Runtime.InterNetworkModel) | ||
|
|
@@ -626,6 +625,11 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat | |
| return "", config, err | ||
| } | ||
|
|
||
| config.DisableNewNetNs = tomlConf.Runtime.DisableNewNetNs | ||
| if err := checkNetNsConfig(config); err != nil { | ||
| return "", config, err | ||
| } | ||
|
|
||
| // use no proxy if HypervisorConfig.UseVSock is true | ||
| if config.HypervisorConfig.UseVSock { | ||
| kataLog.Info("VSOCK supported, configure to not use proxy") | ||
|
|
@@ -640,6 +644,20 @@ func loadConfiguration(configPath string, ignoreLogging bool) (resolvedConfigPat | |
| return resolved, config, nil | ||
| } | ||
|
|
||
| // checkNetNsConfig performs sanity checks on disable_new_netns config. | ||
| // Because it is an expert option and conflicts with some other common configs. | ||
| func checkNetNsConfig(config oci.RuntimeConfig) error { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this function :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| if config.DisableNewNetNs { | ||
| if config.NetmonConfig.Enable { | ||
| return fmt.Errorf("config disable_new_netns conflicts with enable_netmon") | ||
| } | ||
| if config.InterNetworkModel != vc.NetXConnectNoneModel { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it is not implemented, I think it should be in a new netns like other models. |
||
| return fmt.Errorf("config disable_new_netns only works with 'none' internetworking_model") | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // checkHypervisorConfig performs basic "sanity checks" on the hypervisor | ||
| // config. | ||
| func checkHypervisorConfig(config vc.HypervisorConfig) error { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -230,9 +230,23 @@ path = "@NETMONPATH@" | |
| # - macvtap | ||
| # Used when the Container network interface can be bridged using | ||
| # macvtap. | ||
| # | ||
| # - none | ||
| # Used when customize network. Only creates a tap device. No veth pair. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be useful to add a link here to the following as that shows users visually more about how this will work:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I will add a PR in documentation repo. |
||
| # | ||
| internetworking_model="@DEFNETWORKMODEL@" | ||
|
|
||
| # If enabled, the runtime will create opentracing.io traces and spans. | ||
| # (See https://www.jaegertracing.io/docs/getting-started). | ||
| # (default: disabled) | ||
| #enable_tracing = true | ||
|
|
||
| # If enabled, the runtime will not create a network namespace for shim and hypervisor processes. | ||
| # This option may have some potential impacts to your host. It should only be used when you know what you're doing. | ||
| # `disable_new_netns` conflicts with `enable_netmon` | ||
| # `disable_new_netns` conflicts with `internetworking_model=bridged` and `internetworking_model=macvtap`. It works only | ||
| # with `internetworking_model=none`. The tap device will be in the host network namespace and can connect to a bridge | ||
| # (like OVS) directly. | ||
| # If you are using docker, `disable_new_netns` only works with `docker run --net=none` | ||
| # (default: false) | ||
| #disable_new_netns = true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -336,6 +336,11 @@ func hostNetworkingRequested(configNetNs string) (bool, error) { | |
| } | ||
|
|
||
| func setupNetworkNamespace(config *vc.NetworkConfig) error { | ||
| if config.DisableNewNetNs { | ||
| kataLog.Info("DisableNewNetNs is on, shim and hypervisor are running in the host netns") | ||
| return nil | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be worth adding some log traces here to confirm that we're running without any netns! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be overkill to add this to every log call, but due to the delicate nature of namespaces + golang, how about we log the namespace details at various points in the code [*]? We already log the pid so this will give more detail than a simple "changed namspace" log call: const nsPath = "/proc/self/ns"
func getNamespaces() (string, error) {
files, err := ioutil.ReadDir(nsPath)
if err != nil {
return "", err
}
var ns []string
for _, file := range files {
filePath := path.Join(nsPath, file.Name())
linkName, err := os.Readlink(filePath)
if err != nil {
return "", err
}
ns = append(ns, linkName)
}
sort.Sort(sort.StringSlice(ns))
namespaces := strings.Join(ns, ",")
return namespaces, nil
}This will return something like: [*] - At runtime startup, whenever we change namespace, and in this function to show if we did or didn't switch ns.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's good to add some logs. But in this function we cannot get container id or sandbox id for log fields. |
||
| } | ||
|
|
||
| if config.NetNSPath == "" { | ||
| n, err := ns.NewNS() | ||
| if err != nil { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're modifying something that's not really part of this commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because its cyclomatic complexity reaches the top, I must reduce one to add an "if" for netns config.