Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
runtime: Do not error if only initrd/rootfs image installed
Browse files Browse the repository at this point in the history
If only initrd or rootfs image is installed,
allow to start Kata Containers without erroring
out.

Fixes:  #1174

Signed-off-by: Nitesh Konkar niteshkonkar@in.ibm.com
  • Loading branch information
nitkon committed Feb 4, 2019
1 parent 6f2c036 commit be0726c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
16 changes: 6 additions & 10 deletions pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func (h hypervisor) initrd() (string, error) {
p := h.Initrd

if p == "" {
return "", nil
return "", errors.New("initrd is not set")
}

return ResolvePath(p)
Expand All @@ -176,7 +176,7 @@ func (h hypervisor) image() (string, error) {
p := h.Image

if p == "" {
return "", nil
return "", errors.New("image is not set")
}

return ResolvePath(p)
Expand Down Expand Up @@ -340,20 +340,16 @@ func (h hypervisor) guestHookPath() string {
}

func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error) {
if initrd, err = h.initrd(); err != nil {
return
}
initrd, errInitrd := h.initrd()

if image, err = h.image(); err != nil {
return
}
image, errImage := h.image()

if image != "" && initrd != "" {
return "", "", errors.New("having both an image and an initrd defined in the configuration file is not supported")
}

if image == "" && initrd == "" {
return "", "", errors.New("either image or initrd must be defined in the configuration file")
if errInitrd != nil && errImage != nil {
return "", "", fmt.Errorf("Either initrd or image must be set to a valid path (initrd: %v) (image: %v)", errInitrd, errImage)
}

return
Expand Down
8 changes: 4 additions & 4 deletions pkg/katautils/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,14 +1046,14 @@ func TestHypervisorDefaultsInitrd(t *testing.T) {
defaultInitrdPath = testInitrdPath
h := hypervisor{}
p, err := h.initrd()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "", "default Image path wrong")

// test path resolution
defaultInitrdPath = testInitrdLinkPath
h = hypervisor{}
p, err = h.initrd()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "")
}

Expand Down Expand Up @@ -1083,14 +1083,14 @@ func TestHypervisorDefaultsImage(t *testing.T) {
defaultImagePath = testImagePath
h := hypervisor{}
p, err := h.image()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "", "default Image path wrong")

// test path resolution
defaultImagePath = testImageLinkPath
h = hypervisor{}
p, err = h.image()
assert.NoError(err)
assert.Error(err)
assert.Equal(p, "")
}

Expand Down

0 comments on commit be0726c

Please sign in to comment.