Add default-config command.
Signed-off-by: Lantao Liu <lantaol@google.com>
This commit is contained in:
parent
7977970e04
commit
eb4d5f3fc7
@ -52,6 +52,16 @@ func init() {
|
|||||||
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
cmd.PersistentFlags().AddGoFlagSet(flag.CommandLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func defaultConfigCommand() *cobra.Command {
|
||||||
|
return &cobra.Command{
|
||||||
|
Use: "default-config",
|
||||||
|
Short: "Print default toml config of cri-containerd and quit.",
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
options.PrintDefaultTomlConfig()
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
if reexec.Init() {
|
if reexec.Init() {
|
||||||
return
|
return
|
||||||
@ -59,6 +69,7 @@ func main() {
|
|||||||
o := options.NewCRIContainerdOptions()
|
o := options.NewCRIContainerdOptions()
|
||||||
|
|
||||||
o.AddFlags(cmd.Flags())
|
o.AddFlags(cmd.Flags())
|
||||||
|
cmd.AddCommand(defaultConfigCommand())
|
||||||
|
|
||||||
cmd.Run = func(cmd *cobra.Command, args []string) {
|
cmd.Run = func(cmd *cobra.Command, args []string) {
|
||||||
if err := o.InitFlags(cmd.Flags()); err != nil {
|
if err := o.InitFlags(cmd.Flags()); err != nil {
|
||||||
@ -71,11 +82,6 @@ func main() {
|
|||||||
version.PrintVersion()
|
version.PrintVersion()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if o.PrintDefaultConfig {
|
|
||||||
o.PrintDefaultTomlConfig()
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
validateConfig(o)
|
validateConfig(o)
|
||||||
|
|
||||||
glog.V(2).Infof("Run cri-containerd grpc server on socket %q", o.SocketPath)
|
glog.V(2).Infof("Run cri-containerd grpc server on socket %q", o.SocketPath)
|
||||||
|
@ -97,8 +97,6 @@ type CRIContainerdOptions struct {
|
|||||||
ConfigFilePath string `toml:"-"`
|
ConfigFilePath string `toml:"-"`
|
||||||
// PrintVersion indicates to print version information of cri-containerd.
|
// PrintVersion indicates to print version information of cri-containerd.
|
||||||
PrintVersion bool
|
PrintVersion bool
|
||||||
// PrintDefaultConfig indicates to print default toml config of cri-containerd.
|
|
||||||
PrintDefaultConfig bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCRIContainerdOptions returns a reference to CRIContainerdOptions
|
// NewCRIContainerdOptions returns a reference to CRIContainerdOptions
|
||||||
@ -108,48 +106,47 @@ func NewCRIContainerdOptions() *CRIContainerdOptions {
|
|||||||
|
|
||||||
// AddFlags adds cri-containerd command line options to pflag.
|
// AddFlags adds cri-containerd command line options to pflag.
|
||||||
func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
|
func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
|
||||||
|
defaults := defaultConfig()
|
||||||
fs.StringVar(&c.ConfigFilePath, configFilePathArgName,
|
fs.StringVar(&c.ConfigFilePath, configFilePathArgName,
|
||||||
defaultConfigFilePath, "Path to the config file.")
|
defaultConfigFilePath, "Path to the config file.")
|
||||||
fs.StringVar(&c.SocketPath, "socket-path",
|
fs.StringVar(&c.SocketPath, "socket-path",
|
||||||
"/var/run/cri-containerd.sock", "Path to the socket which cri-containerd serves on.")
|
defaults.SocketPath, "Path to the socket which cri-containerd serves on.")
|
||||||
fs.StringVar(&c.RootDir, "root-dir",
|
fs.StringVar(&c.RootDir, "root-dir",
|
||||||
"/var/lib/cri-containerd", "Root directory path for cri-containerd managed files (metadata checkpoint etc).")
|
defaults.RootDir, "Root directory path for cri-containerd managed files (metadata checkpoint etc).")
|
||||||
fs.StringVar(&c.ContainerdConfig.RootDir, "containerd-root-dir",
|
fs.StringVar(&c.ContainerdConfig.RootDir, "containerd-root-dir",
|
||||||
"/var/lib/containerd", "Root directory path where containerd stores persistent data.")
|
defaults.ContainerdConfig.RootDir, "Root directory path where containerd stores persistent data.")
|
||||||
fs.StringVar(&c.ContainerdConfig.Endpoint, "containerd-endpoint",
|
fs.StringVar(&c.ContainerdConfig.Endpoint, "containerd-endpoint",
|
||||||
"/run/containerd/containerd.sock", "Path to the containerd endpoint.")
|
defaults.ContainerdConfig.Endpoint, "Path to the containerd endpoint.")
|
||||||
fs.StringVar(&c.ContainerdConfig.Snapshotter, "containerd-snapshotter",
|
fs.StringVar(&c.ContainerdConfig.Snapshotter, "containerd-snapshotter",
|
||||||
containerd.DefaultSnapshotter, "The snapshotter used by containerd.")
|
defaults.ContainerdConfig.Snapshotter, "The snapshotter used by containerd.")
|
||||||
fs.StringVar(&c.ContainerdConfig.Runtime, "containerd-runtime",
|
fs.StringVar(&c.ContainerdConfig.Runtime, "containerd-runtime",
|
||||||
"io.containerd.runtime.v1.linux", "The runtime used by containerd.")
|
defaults.ContainerdConfig.Runtime, "The runtime used by containerd.")
|
||||||
fs.StringVar(&c.ContainerdConfig.RuntimeEngine, "containerd-runtime-engine",
|
fs.StringVar(&c.ContainerdConfig.RuntimeEngine, "containerd-runtime-engine",
|
||||||
"", "Runtime engine used by containerd. Defaults to containerd's default if not specified.")
|
defaults.ContainerdConfig.RuntimeEngine, "Runtime engine used by containerd. Defaults to containerd's default if not specified.")
|
||||||
fs.StringVar(&c.ContainerdConfig.RuntimeRoot, "containerd-runtime-root",
|
fs.StringVar(&c.ContainerdConfig.RuntimeRoot, "containerd-runtime-root",
|
||||||
"", "The directory used by containerd for runtime state. Defaults to containerd's default if not specified.")
|
defaults.ContainerdConfig.RuntimeRoot, "The directory used by containerd for runtime state. Defaults to containerd's default if not specified.")
|
||||||
fs.BoolVar(&c.PrintVersion, "version",
|
fs.BoolVar(&c.PrintVersion, "version",
|
||||||
false, "Print cri-containerd version information and quit.")
|
false, "Print cri-containerd version information and quit.")
|
||||||
fs.StringVar(&c.NetworkPluginBinDir, "network-bin-dir",
|
fs.StringVar(&c.NetworkPluginBinDir, "network-bin-dir",
|
||||||
"/opt/cni/bin", "The directory for putting network binaries.")
|
defaults.NetworkPluginBinDir, "The directory for putting network binaries.")
|
||||||
fs.StringVar(&c.NetworkPluginConfDir, "network-conf-dir",
|
fs.StringVar(&c.NetworkPluginConfDir, "network-conf-dir",
|
||||||
"/etc/cni/net.d", "The directory for putting network plugin configuration files.")
|
defaults.NetworkPluginConfDir, "The directory for putting network plugin configuration files.")
|
||||||
fs.StringVar(&c.StreamServerAddress, "stream-addr",
|
fs.StringVar(&c.StreamServerAddress, "stream-addr",
|
||||||
"", "The ip address streaming server is listening on. The default host interface is used if not specified.")
|
defaults.StreamServerAddress, "The ip address streaming server is listening on. The default host interface is used if not specified.")
|
||||||
fs.StringVar(&c.StreamServerPort, "stream-port",
|
fs.StringVar(&c.StreamServerPort, "stream-port",
|
||||||
"10010", "The port streaming server is listening on.")
|
defaults.StreamServerPort, "The port streaming server is listening on.")
|
||||||
fs.StringVar(&c.CgroupPath, "cgroup-path",
|
fs.StringVar(&c.CgroupPath, "cgroup-path",
|
||||||
"", "The cgroup that cri-containerd is part of. Cri-containerd is not placed in a cgroup if none is specified.")
|
defaults.CgroupPath, "The cgroup that cri-containerd is part of. Cri-containerd is not placed in a cgroup if none is specified.")
|
||||||
fs.BoolVar(&c.EnableSelinux, "enable-selinux",
|
fs.BoolVar(&c.EnableSelinux, "enable-selinux",
|
||||||
false, "Enable selinux support. By default not enabled.")
|
defaults.EnableSelinux, "Enable selinux support. By default not enabled.")
|
||||||
fs.StringVar(&c.SandboxImage, "sandbox-image",
|
fs.StringVar(&c.SandboxImage, "sandbox-image",
|
||||||
"gcr.io/google_containers/pause:3.0", "The image used by sandbox container.")
|
defaults.SandboxImage, "The image used by sandbox container.")
|
||||||
fs.IntVar(&c.StatsCollectPeriod, "stats-collect-period",
|
fs.IntVar(&c.StatsCollectPeriod, "stats-collect-period",
|
||||||
10, "The period (in seconds) of snapshots stats collection.")
|
defaults.StatsCollectPeriod, "The period (in seconds) of snapshots stats collection.")
|
||||||
fs.BoolVar(&c.SystemdCgroup, "systemd-cgroup",
|
fs.BoolVar(&c.SystemdCgroup, "systemd-cgroup",
|
||||||
false, "Enables systemd cgroup support. By default not enabled.")
|
defaults.SystemdCgroup, "Enables systemd cgroup support. By default not enabled.")
|
||||||
fs.BoolVar(&c.PrintDefaultConfig, "default-config",
|
|
||||||
false, "Print default toml config of cri-containerd and quit.")
|
|
||||||
fs.IntVar(&c.OOMScore, "oom-score",
|
fs.IntVar(&c.OOMScore, "oom-score",
|
||||||
-999, "Adjust the cri-containerd's oom score.")
|
defaults.OOMScore, "Adjust the cri-containerd's oom score.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitFlags load configurations from config file, and then overwrite with flags.
|
// InitFlags load configurations from config file, and then overwrite with flags.
|
||||||
@ -178,13 +175,37 @@ func (c *CRIContainerdOptions) InitFlags(fs *pflag.FlagSet) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PrintDefaultTomlConfig print default toml config of cri-containerd.
|
// PrintDefaultTomlConfig print default toml config of cri-containerd.
|
||||||
func (c *CRIContainerdOptions) PrintDefaultTomlConfig() {
|
func PrintDefaultTomlConfig() {
|
||||||
fs := pflag.NewFlagSet("default-config", pflag.ExitOnError)
|
if err := toml.NewEncoder(os.Stdout).Encode(defaultConfig()); err != nil {
|
||||||
|
|
||||||
c.AddFlags(fs)
|
|
||||||
|
|
||||||
if err := toml.NewEncoder(os.Stdout).Encode(c.Config); err != nil {
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// defaultConfig returns default configurations of cri-containerd.
|
||||||
|
func defaultConfig() Config {
|
||||||
|
return Config{
|
||||||
|
ContainerdConfig: ContainerdConfig{
|
||||||
|
RootDir: "/var/lib/containerd",
|
||||||
|
Snapshotter: containerd.DefaultSnapshotter,
|
||||||
|
Endpoint: "/run/containerd/containerd.sock",
|
||||||
|
Runtime: "io.containerd.runtime.v1.linux",
|
||||||
|
RuntimeEngine: "",
|
||||||
|
RuntimeRoot: "",
|
||||||
|
},
|
||||||
|
CniConfig: CniConfig{
|
||||||
|
NetworkPluginBinDir: "/opt/cni/bin",
|
||||||
|
NetworkPluginConfDir: "/etc/cni/net.d",
|
||||||
|
},
|
||||||
|
SocketPath: "/var/run/cri-containerd.sock",
|
||||||
|
RootDir: "/var/lib/cri-containerd",
|
||||||
|
StreamServerAddress: "",
|
||||||
|
StreamServerPort: "10010",
|
||||||
|
CgroupPath: "",
|
||||||
|
EnableSelinux: false,
|
||||||
|
SandboxImage: "gcr.io/google_containers/pause:3.0",
|
||||||
|
StatsCollectPeriod: 10,
|
||||||
|
SystemdCgroup: false,
|
||||||
|
OOMScore: -999,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user