Skip to content

Commit

Permalink
Move rootfs spec from garden-shed to guardian
Browse files Browse the repository at this point in the history
So that it lives next to its interface method that depends on it. An
example of the dependency inversion principle: high level interface
modules should not depend on low-level implementation modules. This also
helps us get rid of garden-shed eventually.

[#154766812]

Signed-off-by: Danail Branekov <[email protected]>
  • Loading branch information
Craig Furman authored and danail-branekov committed Feb 21, 2018
1 parent a65ff10 commit f7e17c5
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 40 deletions.
11 changes: 5 additions & 6 deletions gardener/gardenerfakes/fake_volume_creator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions gardener/noop_volumizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"

"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/lager"
)

type NoopVolumizer struct{}

var ErrGraphDisabled = errors.New("volume graph is disabled")

func (NoopVolumizer) Create(lager.Logger, string, rootfs_spec.Spec) (specs.Spec, error) {
func (NoopVolumizer) Create(lager.Logger, string, RootfsSpec) (specs.Spec, error) {
return specs.Spec{}, ErrGraphDisabled
}

Expand Down
3 changes: 1 addition & 2 deletions gardener/noop_volumizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gardener_test

import (
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/lager/lagertest"

Expand All @@ -23,7 +22,7 @@ var _ = Describe("NoopVolumizer", func() {

Describe("Create", func() {
It("returns ErrGraphDisabled", func() {
_, err := volumizer.Create(logger, "some-handle", rootfs_spec.Spec{})
_, err := volumizer.Create(logger, "some-handle", gardener.RootfsSpec{})
Expect(err).To(Equal(gardener.ErrGraphDisabled))
})
})
Expand Down
15 changes: 12 additions & 3 deletions gardener/volume_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"code.cloudfoundry.org/commandrunner"
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/lager"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
Expand Down Expand Up @@ -38,7 +37,17 @@ func NewVolumeProvider(creator VolumeCreator, manager VolumeDestroyMetricsGC, pr
}

type VolumeCreator interface {
Create(log lager.Logger, handle string, spec rootfs_spec.Spec) (specs.Spec, error)
Create(log lager.Logger, handle string, spec RootfsSpec) (specs.Spec, error)
}

// TODO GoRename RootfsSpec
type RootfsSpec struct {
RootFS *url.URL
Username string `json:"-"`
Password string `json:"-"`
Namespaced bool
QuotaSize int64
QuotaScope garden.DiskLimitScope
}

func (v *VolumeProvider) Create(log lager.Logger, spec garden.ContainerSpec) (specs.Spec, error) {
Expand All @@ -60,7 +69,7 @@ func (v *VolumeProvider) Create(log lager.Logger, spec garden.ContainerSpec) (sp
baseConfig.Process = &specs.Process{}
} else {
var err error
baseConfig, err = v.VolumeCreator.Create(log.Session("volume-creator"), spec.Handle, rootfs_spec.Spec{
baseConfig, err = v.VolumeCreator.Create(log.Session("volume-creator"), spec.Handle, RootfsSpec{
RootFS: rootFSURL,
Username: spec.Image.Username,
Password: spec.Image.Password,
Expand Down
3 changes: 1 addition & 2 deletions gardener/volume_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

"code.cloudfoundry.org/commandrunner/fake_command_runner"
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
fakes "code.cloudfoundry.org/guardian/gardener/gardenerfakes"
"code.cloudfoundry.org/lager"
Expand Down Expand Up @@ -107,7 +106,7 @@ var _ = Describe("VolumeProvider", func() {

parsedRootFS, err := url.Parse("docker:///alpine")
Expect(err).NotTo(HaveOccurred())
Expect(rootfsSpec).To(Equal(rootfs_spec.Spec{
Expect(rootfsSpec).To(Equal(gardener.RootfsSpec{
RootFS: parsedRootFS,
Username: "cakeuser",
Password: "cakepassword",
Expand Down
4 changes: 2 additions & 2 deletions imageplugin/default_command_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
specs "github.com/opencontainers/runtime-spec/specs-go"

"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/lager"
)

Expand All @@ -18,7 +18,7 @@ type DefaultCommandCreator struct {
ExtraArgs []string
}

func (cc *DefaultCommandCreator) CreateCommand(log lager.Logger, handle string, spec rootfs_spec.Spec) (*exec.Cmd, error) {
func (cc *DefaultCommandCreator) CreateCommand(log lager.Logger, handle string, spec gardener.RootfsSpec) (*exec.Cmd, error) {
args := append(cc.ExtraArgs, "create")

if spec.QuotaSize > 0 {
Expand Down
6 changes: 3 additions & 3 deletions imageplugin/default_command_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os/exec"

"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/guardian/imageplugin"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -33,13 +33,13 @@ var _ = Describe("DefaultCommandCreator", func() {
Describe("CreateCommand", func() {
var (
createCmd *exec.Cmd
spec rootfs_spec.Spec
spec gardener.RootfsSpec
)

BeforeEach(func() {
rootfsURL, err := url.Parse("/fake-registry/image")
Expect(err).NotTo(HaveOccurred())
spec = rootfs_spec.Spec{RootFS: rootfsURL}
spec = gardener.RootfsSpec{RootFS: rootfsURL}
})

JustBeforeEach(func() {
Expand Down
6 changes: 3 additions & 3 deletions imageplugin/image_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"code.cloudfoundry.org/commandrunner"
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/lager"
specs "github.com/opencontainers/runtime-spec/specs-go"
errorwrapper "github.com/pkg/errors"
Expand All @@ -22,7 +22,7 @@ const PreloadedPlusLayerScheme = "preloaded+layer"

//go:generate counterfeiter . CommandCreator
type CommandCreator interface {
CreateCommand(log lager.Logger, handle string, spec rootfs_spec.Spec) (*exec.Cmd, error)
CreateCommand(log lager.Logger, handle string, spec gardener.RootfsSpec) (*exec.Cmd, error)
DestroyCommand(log lager.Logger, handle string) *exec.Cmd
MetricsCommand(log lager.Logger, handle string) *exec.Cmd
}
Expand All @@ -40,7 +40,7 @@ type ImagePlugin struct {
DefaultRootfs string
}

func (p *ImagePlugin) Create(log lager.Logger, handle string, spec rootfs_spec.Spec) (specs.Spec, error) {
func (p *ImagePlugin) Create(log lager.Logger, handle string, spec gardener.RootfsSpec) (specs.Spec, error) {
errs := func(err error, action string) (specs.Spec, error) {
return specs.Spec{}, errorwrapper.Wrap(err, action)
}
Expand Down
6 changes: 3 additions & 3 deletions imageplugin/image_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"code.cloudfoundry.org/commandrunner/fake_command_runner"
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/guardian/imageplugin"
fakes "code.cloudfoundry.org/guardian/imageplugin/imagepluginfakes"
"code.cloudfoundry.org/lager"
Expand Down Expand Up @@ -61,7 +61,7 @@ var _ = Describe("ImagePlugin", func() {
cmd *exec.Cmd

handle string
rootfsProviderSpec rootfs_spec.Spec
rootfsProviderSpec gardener.RootfsSpec
rootfs string
namespaced bool

Expand Down Expand Up @@ -116,7 +116,7 @@ var _ = Describe("ImagePlugin", func() {

rootfsURL, err := url.Parse(rootfs)
Expect(err).NotTo(HaveOccurred())
rootfsProviderSpec = rootfs_spec.Spec{RootFS: rootfsURL, Namespaced: namespaced}
rootfsProviderSpec = gardener.RootfsSpec{RootFS: rootfsURL, Namespaced: namespaced}
baseRuntimeSpec, createErr = imagePlugin.Create(fakeLogger, handle, rootfsProviderSpec)
})

Expand Down
12 changes: 6 additions & 6 deletions imageplugin/imagepluginfakes/fake_command_creator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions imageplugin/not_implemented_command_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package imageplugin
import (
"os/exec"

"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/lager"
)

type NotImplementedCommandCreator struct {
Err error
}

func (cc *NotImplementedCommandCreator) CreateCommand(log lager.Logger, handle string, spec rootfs_spec.Spec) (*exec.Cmd, error) {
func (cc *NotImplementedCommandCreator) CreateCommand(log lager.Logger, handle string, spec gardener.RootfsSpec) (*exec.Cmd, error) {
return nil, cc.Err
}

Expand Down
4 changes: 2 additions & 2 deletions imageplugin/not_implemented_command_creator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package imageplugin_test
import (
"errors"

"code.cloudfoundry.org/garden-shed/rootfs_spec"
"code.cloudfoundry.org/guardian/gardener"
"code.cloudfoundry.org/guardian/imageplugin"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -22,7 +22,7 @@ var _ = Describe("NotImplementedCommandCreator", func() {

Describe("CreateCommand", func() {
It("returns nil and provided error", func() {
cmd, err := notImplementedCommandCreator.CreateCommand(nil, "", rootfs_spec.Spec{})
cmd, err := notImplementedCommandCreator.CreateCommand(nil, "", gardener.RootfsSpec{})
Expect(cmd).To(BeNil())
Expect(err).To(MatchError(errors.New("NOT IMPLEMENTED")))
})
Expand Down
4 changes: 0 additions & 4 deletions rundmc/execrunner/windows_execrunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import (
"code.cloudfoundry.org/commandrunner/fake_command_runner"
"code.cloudfoundry.org/garden"
"code.cloudfoundry.org/guardian/rundmc/execrunner"
"code.cloudfoundry.org/guardian/rundmc/runrunc"
"code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/lagertest"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
specs "github.com/opencontainers/runtime-spec/specs-go"
)

var _ = Describe("DirectExecRunner", func() {
Expand All @@ -30,7 +28,6 @@ var _ = Describe("DirectExecRunner", func() {
runtimePath = "container-runtime-path"
cleanupFunc func() error

spec *runrunc.PreparedSpec
process garden.Process
processIO garden.ProcessIO
runErr error
Expand Down Expand Up @@ -60,7 +57,6 @@ var _ = Describe("DirectExecRunner", func() {

Describe("Run", func() {
JustBeforeEach(func() {
spec = &runrunc.PreparedSpec{Process: specs.Process{Cwd: "idiosyncratic-string"}}
process, runErr = execRunner.Run(
logger,
processID,
Expand Down

0 comments on commit f7e17c5

Please sign in to comment.