Пример #1
0
func (l Hostname) Apply(bndl goci.Bndl, spec gardener.DesiredContainerSpec) goci.Bndl {
	hostname := spec.Hostname
	if len(hostname) > 49 {
		hostname = hostname[len(hostname)-49:]
	}

	return bndl.WithHostname(hostname)
}
Пример #2
0
func (b BindMounts) Apply(bndl goci.Bndl, spec gardener.DesiredContainerSpec) goci.Bndl {
	var mounts []specs.Mount
	for _, m := range spec.BindMounts {
		modeOpt := "ro"
		if m.Mode == garden.BindMountModeRW {
			modeOpt = "rw"
		}

		mounts = append(mounts, specs.Mount{
			Destination: m.DstPath,
			Source:      m.SrcPath,
			Type:        "bind",
			Options:     []string{"bind", modeOpt},
		})
	}

	return bndl.WithMounts(mounts...)
}
Пример #3
0
func (r RootFS) Apply(bndl goci.Bndl, spec gardener.DesiredContainerSpec) goci.Bndl {
	var uid, gid int
	if !spec.Privileged {
		uid = r.ContainerRootUID
		gid = r.ContainerRootGID
	}

	r.MkdirChown.MkdirAs(
		spec.RootFSPath, uid, gid, 0755, true,
		".pivot_root",
		"dev", "proc", "sys",
	)

	r.MkdirChown.MkdirAs(
		spec.RootFSPath, uid, gid, 0777, false,
		"tmp",
	)

	return bndl.WithRootFS(spec.RootFSPath)
}
Пример #4
0
func (l Limits) Apply(bndl goci.Bndl, spec gardener.DesiredContainerSpec) goci.Bndl {
	limit := uint64(spec.Limits.Memory.LimitInBytes)
	bndl = bndl.WithMemoryLimit(specs.LinuxMemory{Limit: &limit, Swap: &limit})
	shares := uint64(spec.Limits.CPU.LimitInShares)
	bndl = bndl.WithCPUShares(specs.LinuxCPU{Shares: &shares})
	pids := int64(spec.Limits.Pid.Max)
	return bndl.WithPidLimit(specs.LinuxPids{Limit: pids})
}
Пример #5
0
package goci_test

import (
	"code.cloudfoundry.org/guardian/rundmc/goci"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/opencontainers/runtime-spec/specs-go"
)

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

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

	It("specifies the correct version", func() {
		Expect(initialBundle.Spec.Version).To(Equal("0.2.0"))
	})

	Describe("WithHostname", func() {
		It("sets the Hostname in the bundle", func() {
			returnedBundle := initialBundle.WithHostname("hostname")
			Expect(returnedBundle.Hostname()).To(Equal("hostname"))
		})
	})

	Describe("WithCapabilities", func() {
		It("adds capabilities to the bundle", func() {
			returnedBundle := initialBundle.WithCapabilities("growtulips", "waterspuds")
Пример #6
0
package bundlerules_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/opencontainers/runtime-spec/specs-go"

	"code.cloudfoundry.org/garden"
	"code.cloudfoundry.org/guardian/gardener"
	"code.cloudfoundry.org/guardian/rundmc/bundlerules"
	"code.cloudfoundry.org/guardian/rundmc/goci"
)

var _ = Describe("BindMountsRule", func() {
	var newBndl goci.Bndl

	BeforeEach(func() {
		newBndl = bundlerules.BindMounts{}.Apply(goci.Bundle(), gardener.DesiredContainerSpec{
			BindMounts: []garden.BindMount{
				{
					SrcPath: "/path/to/ro/src",
					DstPath: "/path/to/ro/dest",
					Mode:    garden.BindMountModeRO,
				},
				{
					SrcPath: "/path/to/rw/src",
					DstPath: "/path/to/rw/dest",
					Mode:    garden.BindMountModeRW,
				},
			},
		})
Пример #7
0
	"encoding/json"
	"io"
	"io/ioutil"
	"os"
	"path"

	"code.cloudfoundry.org/guardian/rundmc/goci"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/opencontainers/runtime-spec/specs-go"
)

var _ = Describe("Bundle Serialization", func() {

	var (
		tmp   string
		bndle goci.Bndl
	)

	BeforeEach(func() {
		var err error
		tmp, err = ioutil.TempDir("", "gocitest")
		Expect(err).NotTo(HaveOccurred())

		bndle = goci.Bndl{
			Spec: specs.Spec{
				Version: "abcd",
			},
		}

		Expect(bndle.Save(tmp)).To(Succeed())
	})
Пример #8
0
func (r Env) Apply(bndl goci.Bndl, spec gardener.DesiredContainerSpec) goci.Bndl {
	process := bndl.Process()
	process.Env = spec.Env
	return bndl.WithProcess(process)
}