Ejemplo n.º 1
0
func wireContainerizer(log lager.Logger, depotPath, iodaemonPath, nstarPath, tarPath, defaultRootFSPath string) *rundmc.Containerizer {
	depot := depot.New(depotPath)

	startChecker := rundmc.StartChecker{Expect: "Pid 1 Running", Timeout: 3 * time.Second}
	stateChecker := rundmc.StateChecker{StateFileDir: OciStateDir}

	commandRunner := linux_command_runner.New()

	runcrunner := runrunc.New(
		process_tracker.New(path.Join(os.TempDir(), fmt.Sprintf("garden-%s", *tag), "processes"), iodaemonPath, commandRunner),
		commandRunner,
		wireUidGenerator(),
		goci.RuncBinary("runc"),
		&goci.BndlLoader{},
		runrunc.LookupFunc(runrunc.LookupUser),
	)

	baseBundle := goci.Bundle().
		WithNamespaces(PrivilegedContainerNamespaces...).
		WithResources(&specs.Resources{}).
		WithMounts(
			goci.Mount{Name: "proc", Type: "proc", Source: "proc", Destination: "/proc"},
			goci.Mount{Name: "tmp", Type: "tmpfs", Source: "tmpfs", Destination: "/tmp"},
		).WithRootFS(defaultRootFSPath).
		WithProcess(goci.Process("/bin/sh", "-c", `echo "Pid 1 Running"; read x`)).
		WithDevices(specs.Device{Path: "/dev/null", Type: 'c', Major: 1, Minor: 3, UID: 0, GID: 0, Permissions: "rwm", FileMode: 0666})

	nstar := rundmc.NewNstarRunner(nstarPath, tarPath, linux_command_runner.New())
	return rundmc.New(depot, &rundmc.BundleTemplate{Bndl: baseBundle}, runcrunner, startChecker, stateChecker, nstar)
}
Ejemplo n.º 2
0
Archivo: main.go Proyecto: glyn/pango
func wireContainerizer(depotPath, iodaemonPath, defaultRootFSPath string) *rundmc.Containerizer {
	depot := depot.New(depotPath)

	startCheck := rundmc.StartChecker{Expect: "Pid 1 Running", Timeout: 3 * time.Second}

	runcrunner := runrunc.New(
		process_tracker.New(path.Join(os.TempDir(), fmt.Sprintf("garden-%s", *tag), "processes"), iodaemonPath, linux_command_runner.New()),
		linux_command_runner.New(),
		wireUidGenerator(),
		goci.RuncBinary("runc"),
	)

	baseBundle := goci.Bundle().
		WithNamespaces(PrivilegedContainerNamespaces...).
		WithResources(&specs.Resources{}).
		WithMounts(goci.Mount{Name: "proc", Type: "proc", Source: "proc", Destination: "/proc"}).
		WithRootFS(defaultRootFSPath).
		WithProcess(goci.Process("/bin/sh", "-c", `echo "Pid 1 Running"; read x`))

	return rundmc.New(depot, &rundmc.BundleTemplate{baseBundle}, runcrunner, startCheck)
}
Ejemplo n.º 3
0
package rundmc_test

import (
	"github.com/cloudfoundry-incubator/goci"
	"github.com/cloudfoundry-incubator/goci/specs"
	"github.com/cloudfoundry-incubator/guardian/gardener"
	"github.com/cloudfoundry-incubator/guardian/rundmc"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Bundle", func() {
	Context("when there is a network path", func() {
		It("adds the network path to the network namespace of the bundle", func() {
			base := goci.Bundle().WithNamespaces(specs.Namespace{Type: "network"})
			modifiedBundle := rundmc.BundleTemplate{base}.Bundle(gardener.DesiredContainerSpec{
				NetworkPath: "/path/to/network",
			})

			Expect(modifiedBundle.RuntimeSpec.Linux.Namespaces).Should(ConsistOf(
				specs.Namespace{Type: specs.NetworkNamespace, Path: "/path/to/network"},
			))
		})

		It("does not modify the other fields", func() {
			base := goci.Bundle().WithProcess(goci.Process("potato"))
			modifiedBundle := rundmc.BundleTemplate{base}.Bundle(gardener.DesiredContainerSpec{})
			Expect(modifiedBundle.Spec.Process.Args).Should(ConsistOf("potato"))
		})
	})
})
Ejemplo n.º 4
0
package goci_test

import (
	"github.com/cloudfoundry-incubator/goci"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Bundle", func() {
	var (
		initialBundle goci.Bndle
	)

	BeforeEach(func() {
		initialBundle = goci.Bundle()
	})

	Describe("WithProcess", func() {
		It("adds the process to the bundle", func() {
			bundle := goci.Bundle().WithProcess(goci.Process("echo", "foo"))
			Expect(bundle.Spec.Process).To(Equal(goci.SpecProcess{Args: []string{"echo", "foo"}}))
		})
	})

	Describe("WithMounts", func() {
		var bundle goci.Bndle

		BeforeEach(func() {
			bundle = goci.Bundle().WithMounts(
				goci.Mount{
					Name:        "apple",
Ejemplo n.º 5
0
		fakeNstarRunner = new(fakes.FakeNstarRunner)
		fakeStater = new(fakes.FakeContainerStater)
		logger = lagertest.NewTestLogger("test")

		containerizer = rundmc.New(fakeDepot, fakeBundler, fakeContainerRunner, fakeStartChecker, fakeStater, fakeNstarRunner)

		fakeDepot.LookupStub = func(_ lager.Logger, handle string) (string, error) {
			return "/path/to/" + handle, nil
		}
	})

	Describe("Create", func() {
		It("should ask the depot to create a container", func() {
			var returnedBundle *goci.Bndl
			fakeBundler.BundleStub = func(spec gardener.DesiredContainerSpec) *goci.Bndl {
				returnedBundle = goci.Bundle().WithRootFS(spec.NetworkPath)
				return returnedBundle
			}

			containerizer.Create(logger, gardener.DesiredContainerSpec{
				Handle: "exuberant!",
			})

			Expect(fakeDepot.CreateCallCount()).To(Equal(1))

			_, handle, bundle := fakeDepot.CreateArgsForCall(0)
			Expect(handle).To(Equal("exuberant!"))
			Expect(bundle).To(Equal(returnedBundle))
		})

		Context("when creating the depot directory fails", func() {