Merge pull request #347 from yanxuean/oomscore
Add a flag to set OOMScore
This commit is contained in:
		@@ -82,6 +82,8 @@ type Config struct {
 | 
				
			|||||||
	StatsCollectPeriod int `toml:"stats_collect_period"`
 | 
						StatsCollectPeriod int `toml:"stats_collect_period"`
 | 
				
			||||||
	// SystemdCgroup enables systemd cgroup support.
 | 
						// SystemdCgroup enables systemd cgroup support.
 | 
				
			||||||
	SystemdCgroup bool `toml:"systemd_cgroup"`
 | 
						SystemdCgroup bool `toml:"systemd_cgroup"`
 | 
				
			||||||
 | 
						// OOMScore adjust the cri-containerd's oom score
 | 
				
			||||||
 | 
						OOMScore int `toml:"oom_score"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CRIContainerdOptions contains cri-containerd command line and toml options.
 | 
					// CRIContainerdOptions contains cri-containerd command line and toml options.
 | 
				
			||||||
@@ -143,6 +145,8 @@ func (c *CRIContainerdOptions) AddFlags(fs *pflag.FlagSet) {
 | 
				
			|||||||
		false, "Enables systemd cgroup support. By default not enabled.")
 | 
							false, "Enables systemd cgroup support. By default not enabled.")
 | 
				
			||||||
	fs.BoolVar(&c.PrintDefaultConfig, "default-config",
 | 
						fs.BoolVar(&c.PrintDefaultConfig, "default-config",
 | 
				
			||||||
		false, "Print default toml config of cri-containerd and quit.")
 | 
							false, "Print default toml config of cri-containerd and quit.")
 | 
				
			||||||
 | 
						fs.IntVar(&c.OOMScore, "oom-score",
 | 
				
			||||||
 | 
							-999, "Adjust the cri-containerd's oom score.")
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// InitFlags must be called after adding all cli options flags are defined and
 | 
					// InitFlags must be called after adding all cli options flags are defined and
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,6 +29,7 @@ import (
 | 
				
			|||||||
	"github.com/containerd/containerd/content"
 | 
						"github.com/containerd/containerd/content"
 | 
				
			||||||
	"github.com/containerd/containerd/images"
 | 
						"github.com/containerd/containerd/images"
 | 
				
			||||||
	"github.com/containerd/containerd/plugin"
 | 
						"github.com/containerd/containerd/plugin"
 | 
				
			||||||
 | 
						"github.com/containerd/containerd/sys"
 | 
				
			||||||
	"github.com/cri-o/ocicni/pkg/ocicni"
 | 
						"github.com/cri-o/ocicni/pkg/ocicni"
 | 
				
			||||||
	"github.com/golang/glog"
 | 
						"github.com/golang/glog"
 | 
				
			||||||
	runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor"
 | 
						runcapparmor "github.com/opencontainers/runc/libcontainer/apparmor"
 | 
				
			||||||
@@ -121,6 +122,11 @@ func NewCRIContainerdService(config options.Config) (CRIContainerdService, error
 | 
				
			|||||||
			return nil, fmt.Errorf("failed to load cgroup for cgroup path %v: %v", config.CgroupPath, err)
 | 
								return nil, fmt.Errorf("failed to load cgroup for cgroup path %v: %v", config.CgroupPath, err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if config.OOMScore != 0 {
 | 
				
			||||||
 | 
							if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
 | 
				
			||||||
 | 
								return nil, fmt.Errorf("failed to set OOMScore to %v: %v", config.OOMScore, err)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	c := &criContainerdService{
 | 
						c := &criContainerdService{
 | 
				
			||||||
		config:              config,
 | 
							config:              config,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user