main: Add CNI options
We add 2 ocid options for choosing the CNI configuration and plugin binaries directories: --cni-config-dir and --cni-plugin-dir. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
50a3958e5a
commit
c525459000
6 changed files with 61 additions and 1 deletions
|
@ -17,6 +17,8 @@ const (
|
|||
seccompProfilePath = "/etc/ocid/seccomp.json"
|
||||
apparmorProfileName = "ocid-default"
|
||||
cgroupManager = "cgroupfs"
|
||||
cniConfigDir = "/etc/cni/net.d/"
|
||||
cniBinDir = "/opt/cni/bin/"
|
||||
)
|
||||
|
||||
var commentedConfigTemplate = template.Must(template.New("config").Parse(`
|
||||
|
@ -81,6 +83,17 @@ cgroup_manager = "{{ .CgroupManager }}"
|
|||
# pause is the path to the statically linked pause container binary, used
|
||||
# as the entrypoint for infra containers.
|
||||
pause = "{{ .Pause }}"
|
||||
|
||||
# The "ocid.network" table contains settings pertaining to the
|
||||
# management of CNI plugins.
|
||||
[ocid.network]
|
||||
|
||||
# network_dir is is where CNI network configuration
|
||||
# files are stored.
|
||||
network_dir = "{{ .NetworkDir }}"
|
||||
|
||||
# plugin_dir is is where CNI plugin binaries are stored.
|
||||
plugin_dir = "{{ .PluginDir }}"
|
||||
`))
|
||||
|
||||
// TODO: Currently ImageDir isn't really used, so we haven't added it to this
|
||||
|
@ -113,6 +126,10 @@ func DefaultConfig() *server.Config {
|
|||
Pause: pausePath,
|
||||
ImageDir: filepath.Join(ocidRoot, "store"),
|
||||
},
|
||||
NetworkConfig: server.NetworkConfig{
|
||||
NetworkDir: cniConfigDir,
|
||||
PluginDir: cniBinDir,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,6 +66,12 @@ func mergeConfig(config *server.Config, ctx *cli.Context) error {
|
|||
if ctx.GlobalIsSet("cgroup-manager") {
|
||||
config.CgroupManager = ctx.GlobalString("cgroup-manager")
|
||||
}
|
||||
if ctx.GlobalIsSet("cni-config-dir") {
|
||||
config.NetworkDir = ctx.GlobalString("cni-config-dir")
|
||||
}
|
||||
if ctx.GlobalIsSet("cni-plugin-dir") {
|
||||
config.PluginDir = ctx.GlobalString("cni-plugin-dir")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -157,6 +163,14 @@ func main() {
|
|||
Name: "cgroup-manager",
|
||||
Usage: "cgroup manager (cgroupfs or systemd)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "cni-config-dir",
|
||||
Usage: "CNI configuration files directory",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "cni-plugin-dir",
|
||||
Usage: "CNI plugin binaries directory",
|
||||
},
|
||||
}
|
||||
|
||||
// remove once https://github.com/urfave/cli/pull/544 lands
|
||||
|
|
|
@ -21,6 +21,8 @@ ocid - Enable OCI Kubernetes Container Runtime daemon
|
|||
[**--selinux**]
|
||||
[**--seccomp-profile**=[*value*]]
|
||||
[**--apparmor-profile**=[*value*]]
|
||||
[**---cni-config-dir**=[*value*]]
|
||||
[**---cni-plugin-dir**=[*value*]]
|
||||
[**--version**|**-v**]
|
||||
|
||||
# DESCRIPTION
|
||||
|
@ -86,6 +88,12 @@ ocid is meant to provide an integration path between OCI conformant runtimes and
|
|||
**--apparmor_profile**=""
|
||||
Name of the apparmor profile to be used as the runtime's default (default: "ocid-default")
|
||||
|
||||
**--cni-config-dir**=""
|
||||
CNI configuration files directory (defautl: "/etc/cni/net.d/")
|
||||
|
||||
**--cni-plugin-dir**=""
|
||||
CNI plugin binaries directory (defautl: "/opt/cni/bin/")
|
||||
|
||||
**--version, -v**
|
||||
Print the version
|
||||
|
||||
|
|
|
@ -69,6 +69,14 @@ The `ocid` table supports the following options:
|
|||
**pause**=""
|
||||
Path to the pause executable (default: "/usr/libexec/ocid/pause")
|
||||
|
||||
## OCID.NETWORK TABLE
|
||||
|
||||
**network_dir**=""
|
||||
Path to CNI configuration files (default: "/etc/cni/net.d/")
|
||||
|
||||
**plugin_dir**=""
|
||||
Path to CNI plugin binaries (default: "/opt/cni/bin/")
|
||||
|
||||
# SEE ALSO
|
||||
ocid(8)
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ type Config struct {
|
|||
APIConfig
|
||||
RuntimeConfig
|
||||
ImageConfig
|
||||
NetworkConfig
|
||||
}
|
||||
|
||||
// This structure is necessary to fake the TOML tables when parsing,
|
||||
|
@ -93,6 +94,15 @@ type ImageConfig struct {
|
|||
ImageDir string `toml:"image_dir"`
|
||||
}
|
||||
|
||||
// NetworkConfig represents the "ocid.network" TOML config table
|
||||
type NetworkConfig struct {
|
||||
// NetworkDir is where CNI network configuration files are stored.
|
||||
NetworkDir string `toml:"network_dir"`
|
||||
|
||||
// PluginDir is where CNI plugin binaries are stored.
|
||||
PluginDir string `toml:"plugin_dir"`
|
||||
}
|
||||
|
||||
// tomlConfig is another way of looking at a Config, which is
|
||||
// TOML-friendly (it has all of the explicit tables). It's just used for
|
||||
// conversions.
|
||||
|
@ -102,6 +112,7 @@ type tomlConfig struct {
|
|||
API struct{ APIConfig } `toml:"api"`
|
||||
Runtime struct{ RuntimeConfig } `toml:"runtime"`
|
||||
Image struct{ ImageConfig } `toml:"image"`
|
||||
Network struct{ NetworkConfig } `toml:"network"`
|
||||
} `toml:"ocid"`
|
||||
}
|
||||
|
||||
|
@ -110,6 +121,7 @@ func (t *tomlConfig) toConfig(c *Config) {
|
|||
c.APIConfig = t.Ocid.API.APIConfig
|
||||
c.RuntimeConfig = t.Ocid.Runtime.RuntimeConfig
|
||||
c.ImageConfig = t.Ocid.Image.ImageConfig
|
||||
c.NetworkConfig = t.Ocid.Network.NetworkConfig
|
||||
}
|
||||
|
||||
func (t *tomlConfig) fromConfig(c *Config) {
|
||||
|
@ -117,6 +129,7 @@ func (t *tomlConfig) fromConfig(c *Config) {
|
|||
t.Ocid.API.APIConfig = c.APIConfig
|
||||
t.Ocid.Runtime.RuntimeConfig = c.RuntimeConfig
|
||||
t.Ocid.Image.ImageConfig = c.ImageConfig
|
||||
t.Ocid.Network.NetworkConfig = c.NetworkConfig
|
||||
}
|
||||
|
||||
// FromFile populates the Config from the TOML-encoded file at the given path.
|
||||
|
|
|
@ -310,7 +310,7 @@ func New(config *Config) (*Server, error) {
|
|||
}
|
||||
sandboxes := make(map[string]*sandbox)
|
||||
containers := oci.NewMemoryStore()
|
||||
netPlugin, err := ocicni.InitCNI("")
|
||||
netPlugin, err := ocicni.InitCNI(config.NetworkDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue