pkg/config: turn devices into attributedstring.Slice
The tests are messy and should be turned into table-driven tests but I do not have time at the moment. Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
This commit is contained in:
parent
29b42f3f4f
commit
b8c3014c2a
|
|
@ -69,7 +69,7 @@ type Config struct {
|
|||
// containers global options for containers tools
|
||||
type ContainersConfig struct {
|
||||
// Devices to add to all containers
|
||||
Devices []string `toml:"devices,omitempty"`
|
||||
Devices attributedstring.Slice `toml:"devices,omitempty"`
|
||||
|
||||
// Volumes to add to all containers
|
||||
Volumes attributedstring.Slice `toml:"volumes,omitempty"`
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ func (c *EngineConfig) validatePaths() error {
|
|||
}
|
||||
|
||||
func (c *ContainersConfig) validateDevices() error {
|
||||
for _, d := range c.Devices {
|
||||
for _, d := range c.Devices.Values {
|
||||
if parser.IsQualifiedName(d) {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ var _ = Describe("Config Local", func() {
|
|||
gomega.Expect(defConf).NotTo(gomega.BeNil())
|
||||
|
||||
// Given
|
||||
defConf.Containers.Devices = []string{"/dev/null:/dev/null:abc"}
|
||||
defConf.Containers.Devices = attributedstring.Slice{Values: []string{"/dev/null:/dev/null:abc"}}
|
||||
|
||||
// When
|
||||
err = defConf.Containers.Validate()
|
||||
|
|
@ -170,7 +170,7 @@ var _ = Describe("Config Local", func() {
|
|||
gomega.Expect(defConf).NotTo(gomega.BeNil())
|
||||
|
||||
// Given
|
||||
defConf.Containers.Devices = []string{"wrong:/dev/null:rw"}
|
||||
defConf.Containers.Devices = attributedstring.Slice{Values: []string{"wrong:/dev/null:rw"}}
|
||||
|
||||
// When
|
||||
err = defConf.Containers.Validate()
|
||||
|
|
@ -185,7 +185,7 @@ var _ = Describe("Config Local", func() {
|
|||
gomega.Expect(defConf).NotTo(gomega.BeNil())
|
||||
|
||||
// Given
|
||||
defConf.Containers.Devices = []string{"/dev/null:wrong:rw"}
|
||||
defConf.Containers.Devices = attributedstring.Slice{Values: []string{"/dev/null:wrong:rw"}}
|
||||
|
||||
// When
|
||||
err = defConf.Containers.Validate()
|
||||
|
|
@ -200,7 +200,7 @@ var _ = Describe("Config Local", func() {
|
|||
gomega.Expect(defConf).NotTo(gomega.BeNil())
|
||||
|
||||
// Given
|
||||
defConf.Containers.Devices = []string{invalidPath}
|
||||
defConf.Containers.Devices = attributedstring.Slice{Values: []string{invalidPath}}
|
||||
|
||||
// When
|
||||
err = defConf.Containers.Validate()
|
||||
|
|
@ -215,7 +215,7 @@ var _ = Describe("Config Local", func() {
|
|||
gomega.Expect(defConf).NotTo(gomega.BeNil())
|
||||
|
||||
// Given
|
||||
defConf.Containers.Devices = []string{"::::"}
|
||||
defConf.Containers.Devices = attributedstring.Slice{Values: []string{"::::"}}
|
||||
|
||||
// When
|
||||
err = defConf.Containers.Validate()
|
||||
|
|
@ -353,12 +353,12 @@ var _ = Describe("Config Local", func() {
|
|||
|
||||
config, err := ReadCustomConfig()
|
||||
gomega.Expect(err).To(gomega.BeNil())
|
||||
config.Containers.Devices = []string{
|
||||
config.Containers.Devices = attributedstring.Slice{Values: []string{
|
||||
"/dev/null:/dev/null:rw",
|
||||
"/dev/sdc/",
|
||||
"/dev/sdc:/dev/xvdc",
|
||||
"/dev/sdc:rm",
|
||||
}
|
||||
}}
|
||||
boolTrue := true
|
||||
config.Containers.Env = attributedstring.Slice{Values: []string{"A", "B", "C"}}
|
||||
config.Containers.Env.Attributes.Append = &boolTrue
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/internal/attributedstring"
|
||||
"github.com/containers/common/pkg/apparmor"
|
||||
"github.com/containers/common/pkg/capabilities"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
|
|
@ -59,12 +60,12 @@ var _ = Describe("Config", func() {
|
|||
gomega.Expect(defConf).NotTo(gomega.BeNil())
|
||||
|
||||
// Given
|
||||
defConf.Containers.Devices = []string{
|
||||
defConf.Containers.Devices = attributedstring.Slice{Values: []string{
|
||||
"/dev/null:/dev/null:rw",
|
||||
"/dev/sdc/",
|
||||
"/dev/sdc:/dev/xvdc",
|
||||
"/dev/sdc:rm",
|
||||
}
|
||||
}}
|
||||
|
||||
// When
|
||||
err = defConf.Containers.Validate()
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ func defaultConfig() (*Config, error) {
|
|||
DefaultCapabilities: DefaultCapabilities,
|
||||
DefaultSysctls: []string{},
|
||||
DefaultUlimits: getDefaultProcessLimits(),
|
||||
Devices: []string{},
|
||||
Devices: attributedstring.Slice{},
|
||||
EnableKeyring: true,
|
||||
EnableLabeling: selinuxEnabled(),
|
||||
Env: attributedstring.Slice{
|
||||
|
|
@ -520,7 +520,7 @@ func (c *Config) Mounts() []string {
|
|||
|
||||
// Devices returns the default additional devices for containers.
|
||||
func (c *Config) Devices() []string {
|
||||
return c.Containers.Devices
|
||||
return c.Containers.Devices.Get()
|
||||
}
|
||||
|
||||
// DNSServers returns the default DNS servers to add to resolv.conf in containers.
|
||||
|
|
|
|||
Loading…
Reference in New Issue