Add support for Remote flags in containers.conf
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
f4e4a8617d
commit
a3a0a08b50
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -75,3 +75,7 @@ func (c *ContainersConfig) validateUlimits() error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func isRemote() bool {
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
})
|
||||
|
||||
})
|
||||
|
|
@ -8,6 +8,10 @@ func isDirectory(path string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func isRemote() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *EngineConfig) validatePaths() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
})
|
||||
|
||||
})
|
||||
|
|
@ -1,9 +1,7 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
|
|
@ -43,72 +41,6 @@ var _ = Describe("Config", func() {
|
|||
gomega.Expect(err).To(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("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 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 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 wrong max log size", func() {
|
||||
// Given
|
||||
sut.Containers.LogSizeMax = 1
|
||||
|
|
@ -175,77 +107,6 @@ var _ = Describe("Config", func() {
|
|||
// Then
|
||||
gomega.Expect(err).To(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 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())
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
Describe("readConfigFromFile", func() {
|
||||
|
|
@ -522,4 +383,5 @@ var _ = Describe("Config", func() {
|
|||
gomega.Expect(err).ToNot(gomega.BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
|||
|
|
@ -239,6 +239,7 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
|
|||
c.CgroupManager = defaultCgroupManager()
|
||||
c.StopTimeout = uint(10)
|
||||
|
||||
c.Remote = isRemote()
|
||||
c.OCIRuntimes = map[string][]string{
|
||||
"runc": {
|
||||
"/usr/bin/runc",
|
||||
|
|
|
|||
Loading…
Reference in New Issue