Пример #1
0
// Makes a common cgroup and ensures that it gets destroyed on test exit.
func makeCgroup(t *testing.T) *cgroups.Cgroup {
	name := fmt.Sprintf("unittesting-%s", uuid.Variant4().String())
	cgroup, err := cgroups.New(name)
	TestExpectSuccess(t, err)
	AddTestFinalizer(func() {
		TestExpectSuccess(t, cgroup.Destroy())
	})
	return cgroup
}
Пример #2
0
// NewManager creates a new Manager with the provided options. It will ensure
// the manager is setup and ready to create containers with the provided
// configuration.
func NewManager(opts *Options) (*Manager, error) {
	// validate cgroups is properly setup on the host
	if err := cgroups.CheckCgroups(); err != nil {
		return nil, fmt.Errorf("failed to check cgroups: %v", err)
	}

	// create the parent cgroup for all child containers to be in
	cg, err := cgroups.New(opts.ParentCgroupName)
	if err != nil {
		return nil, err
	}

	m := &Manager{
		Log:                logray.New(),
		containers:         make(map[string]*Container),
		containerDirectory: opts.ContainerDirectory,
		volumeDirectory:    opts.VolumeDirectory,
		cgroup:             cg,
		requiredNamespaces: opts.RequiredNamespaces,
	}
	return m, nil
}