Skip to content

Commit

Permalink
Add support for Remote flags in containers.conf
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed May 28, 2020
1 parent c292d84 commit 379e353
Show file tree
Hide file tree
Showing 8 changed files with 339 additions and 139 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ test: test-unit
.PHONY: test-unit
test-unit:
go test -v $(PROJECT)/pkg/...
go test --tags remote -v $(PROJECT)/pkg/...

clean: ## Clean artifacts
$(MAKE) -C docs clean
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ type EngineConfig struct {
// PullPolicy determines whether to pull image before creating or running a container
// default is "missing"
PullPolicy string `toml:"pull_policy"`

// Indicates whether the application should be running in Remote mode
Remote bool `toml:"_"`

// RemoteURI containers connection information used to connect to remote system.
RemoteURI string `toml:"remote_uri,omitempty"`

// RuntimePath is the path to OCI runtime binary for launching containers.
// The first path pointing to a valid file will be used This is used only
// when there are no OCIRuntime/OCIRuntimes defined. It is used only to be
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,7 @@ func (c *ContainersConfig) validateUlimits() error {
}
return nil
}

func isRemote() bool {
return false
}
179 changes: 179 additions & 0 deletions pkg/config/config_local_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
// +build !remote

package config

import (
"io/ioutil"
"os"
"path"

. "github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

var _ = Describe("Config Local", func() {
BeforeEach(beforeEach)

It("should fail on invalid NetworkConfigDir", func() {
// Given
tmpfile := path.Join(os.TempDir(), "wrong-file")
file, err := os.Create(tmpfile)
gomega.Expect(err).To(gomega.BeNil())
file.Close()
defer os.Remove(tmpfile)
sut.Network.NetworkConfigDir = tmpfile
sut.Network.CNIPluginDirs = []string{}

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail on invalid CNIPluginDirs", func() {
validDirPath, err := ioutil.TempDir("", "config-empty")
if err != nil {
panic(err)
}
defer os.RemoveAll(validDirPath)
// Given
sut.Network.NetworkConfigDir = validDirPath
sut.Network.CNIPluginDirs = []string{invalidPath}

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail in validating invalid PluginDir", func() {
validDirPath, err := ioutil.TempDir("", "config-empty")
if err != nil {
panic(err)
}
defer os.RemoveAll(validDirPath)
// Given
sut.Network.NetworkConfigDir = validDirPath
sut.Network.CNIPluginDirs = []string{invalidPath}

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).ToNot(gomega.BeNil())
})

It("should fail on invalid CNIPluginDirs", func() {
validDirPath, err := ioutil.TempDir("", "config-empty")
if err != nil {
panic(err)
}
defer os.RemoveAll(validDirPath)
// Given
sut.Network.NetworkConfigDir = validDirPath
sut.Network.CNIPluginDirs = []string{invalidPath}

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail during runtime", func() {
validDirPath, err := ioutil.TempDir("", "config-empty")
if err != nil {
panic(err)
}
defer os.RemoveAll(validDirPath)
// Given
sut.Network.NetworkConfigDir = validDirPath
tmpDir := path.Join(os.TempDir(), "cni-test")
sut.Network.CNIPluginDirs = []string{tmpDir}
defer os.RemoveAll(tmpDir)

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).ToNot(gomega.BeNil())
})

It("should fail on invalid device mode", func() {
// Given
sut.Containers.Devices = []string{"/dev/null:/dev/null:abc"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail on invalid first device", func() {
// Given
sut.Containers.Devices = []string{"wrong:/dev/null:rw"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail on invalid second device", func() {
// Given
sut.Containers.Devices = []string{"/dev/null:wrong:rw"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail on invalid device", func() {
// Given
sut.Containers.Devices = []string{invalidPath}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail on wrong invalid device specification", func() {
// Given
sut.Containers.Devices = []string{"::::"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("should fail on wrong DefaultUlimits", func() {
// Given
sut.Containers.DefaultUlimits = []string{invalidPath}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).NotTo(gomega.BeNil())
})

It("Expect Remote to be False", func() {
// Given
// When
config, err := NewConfig("")
// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config.Engine.Remote).To(gomega.BeFalse())
})

})
4 changes: 4 additions & 0 deletions pkg/config/config_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ func isDirectory(path string) error {
return nil
}

func isRemote() bool {
return true
}

func (c *EngineConfig) validatePaths() error {
return nil
}
Expand Down
142 changes: 142 additions & 0 deletions pkg/config/config_remote_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// +build remote

package config

import (
"io/ioutil"
"os"

. "github.com/onsi/ginkgo"
"github.com/onsi/gomega"
)

var _ = Describe("Config Remote", func() {
BeforeEach(beforeEach)

It("should succeed on invalid CNIPluginDirs", func() {
validDirPath, err := ioutil.TempDir("", "config-empty")
if err != nil {
panic(err)
}
defer os.RemoveAll(validDirPath)
// Given
sut.Network.NetworkConfigDir = validDirPath
sut.Network.CNIPluginDirs = []string{invalidPath}

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("should succeed on invalid device mode", func() {
// Given
sut.Containers.Devices = []string{"/dev/null:/dev/null:abc"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("should succeed on invalid first device", func() {
// Given
sut.Containers.Devices = []string{"wrong:/dev/null:rw"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("should succeed on invalid second device", func() {
// Given
sut.Containers.Devices = []string{"/dev/null:wrong:rw"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("should succeed on invalid device", func() {
// Given
sut.Containers.Devices = []string{invalidPath}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("should succeed on wrong invalid device specification", func() {
// Given
sut.Containers.Devices = []string{"::::"}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("Expect Remote to be true", func() {
// Given
// When
config, err := NewConfig("")
// Then
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(config.Engine.Remote).To(gomega.BeTrue())
})

It("should succeed on wrong DefaultUlimits", func() {
// Given
sut.Containers.DefaultUlimits = []string{invalidPath}

// When
err := sut.Containers.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("should succeed on invalid CNIPluginDirs", func() {
validDirPath, err := ioutil.TempDir("", "config-empty")
if err != nil {
panic(err)
}
defer os.RemoveAll(validDirPath)
// Given
sut.Network.NetworkConfigDir = validDirPath
sut.Network.CNIPluginDirs = []string{invalidPath}

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

It("should succeed in validating invalid PluginDir", func() {
validDirPath, err := ioutil.TempDir("", "config-empty")
if err != nil {
panic(err)
}
defer os.RemoveAll(validDirPath)
// Given
sut.Network.NetworkConfigDir = validDirPath
sut.Network.CNIPluginDirs = []string{invalidPath}

// When
err = sut.Network.Validate()

// Then
gomega.Expect(err).To(gomega.BeNil())
})

})
Loading

0 comments on commit 379e353

Please sign in to comment.