Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type Iface interface {
}

// GetStore returns the container storage for a given configuration
func (c *Config) GetStore() (storage.Store, error) {
func (c *RootConfig) GetStore() (storage.Store, error) {
return storage.GetStore(storage.StoreOptions{
RunRoot: c.RunRoot,
GraphRoot: c.Root,
Expand Down Expand Up @@ -695,6 +695,18 @@ func (c *RootConfig) Validate(onExecution bool) error {
if err := os.MkdirAll(c.LogDir, 0o700); err != nil {
return errors.Wrap(err, "invalid log_dir")
}
store, err := c.GetStore()
if err != nil {
return errors.Wrapf(err, "failed to get store to set defaults")
}
// This step merges the /etc/container/storage.conf with the
// storage configuration in crio.conf
// If we don't do this step, we risk returning the incorrect info
// on Inspect (/info) requests
c.RunRoot = store.RunRoot()
c.Root = store.GraphRoot()
c.Storage = store.GraphDriverName()
c.StorageOptions = store.GraphOptions()
}

return nil
Expand Down
39 changes: 39 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path"
"path/filepath"

"github.com/containers/storage"
"github.com/cri-o/cri-o/pkg/config"

. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -704,6 +705,44 @@ var _ = t.Describe("Config", func() {
// Then
Expect(err).NotTo(BeNil())
})

It("should get default storage options when options are empty", func() {
// Given
defaultStore, err := storage.GetStore(storage.StoreOptions{})
Expect(err).To(BeNil())

sut.RootConfig.RunRoot = ""
sut.RootConfig.Root = ""
sut.RootConfig.Storage = ""
sut.RootConfig.StorageOptions = make([]string, 0)

// When
err = sut.Validate(true)

// Then
Expect(err).To(BeNil())
Expect(sut.RootConfig.RunRoot).To(Equal(defaultStore.RunRoot()))
Expect(sut.RootConfig.Root).To(Equal(defaultStore.GraphRoot()))
Expect(sut.RootConfig.Storage).To(Equal(defaultStore.GraphDriverName()))
Expect(sut.RootConfig.StorageOptions).To(Equal(defaultStore.GraphOptions()))
})

It("should override default storage options", func() {
// Given
defaultStore, err := storage.GetStore(storage.StoreOptions{})
Expect(err).To(BeNil())

sut.RootConfig.RunRoot = "/tmp"
sut.RootConfig.Root = "/tmp"

// When
err = sut.Validate(true)

// Then
Expect(err).To(BeNil())
Expect(sut.RootConfig.RunRoot).NotTo(Equal(defaultStore.RunRoot()))
Expect(sut.RootConfig.Root).NotTo(Equal(defaultStore.GraphRoot()))
})
})

t.Describe("ToFile", func() {
Expand Down