Ejemplo n.º 1
0
func (p *provider) ProvideContainer(spec linux_backend.LinuxContainerSpec) linux_backend.Container {
	cgroupReader := &cgroups_manager.LinuxCgroupReader{
		Path: p.sysconfig.CgroupNodeFilePath,
	}

	cgroupsManager := cgroups_manager.New(p.sysconfig.CgroupPath, spec.ID, cgroupReader)

	oomWatcher := linux_container.NewOomNotifier(
		p.runner, spec.ContainerPath, cgroupsManager,
	)

	return linux_container.NewLinuxContainer(
		spec,
		p.portPool,
		p.runner,
		cgroupsManager,
		p.quotaManager,
		bandwidth_manager.New(spec.ContainerPath, spec.ID, p.runner),
		process_tracker.New(spec.ContainerPath, p.runner),
		p.ProvideFilter(spec.ID),
		p.ipTablesMgr,
		devices.Link{Name: p.sysconfig.NetworkInterfacePrefix + spec.ID + "-0"},
		oomWatcher,
		p.log.Session("container", lager.Data{"handle": spec.Handle}),
	)
}
var _ = Describe("Container cgroups", func() {
	var (
		cgroupsPath    string
		cgroupsManager *cgroups_manager.ContainerCgroupsManager
		cgroupReader   *fake_cgroup_reader.FakeCgroupReader
	)

	BeforeEach(func() {
		cgroupReader = new(fake_cgroup_reader.FakeCgroupReader)
		tmpdir, err := ioutil.TempDir(os.TempDir(), "some-cgroups")
		Expect(err).ToNot(HaveOccurred())

		cgroupsPath = tmpdir

		cgroupsManager = cgroups_manager.New(cgroupsPath, "some-container-id", cgroupReader)
	})

	Describe("setup cgroups", func() {
		It("creates a cgroups directory for each subsystem", func() {
			err := cgroupsManager.Setup("memory", "cpu")
			Expect(err).ToNot(HaveOccurred())

			Expect(path.Join(cgroupsPath, "memory", "instance-some-container-id")).To(BeADirectory())
			Expect(path.Join(cgroupsPath, "cpu", "instance-some-container-id")).To(BeADirectory())
		})

		Context("when the subsystems contain cpuset", func() {
			It("initializes the cpuset.cpus and cpuset.mems based on the system cgroup", func() {
				Expect(os.MkdirAll(path.Join(cgroupsPath, "cpuset"), 0755)).To(Succeed())