runtime: Do not error if only initrd/rootfs image installed

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
This commit is contained in:
Nitesh Konkar 2019-02-04 18:01:00 +05:30
parent 6f2c036601
commit be0726ce50
2 changed files with 10 additions and 14 deletions

View File

@ -166,7 +166,7 @@ func (h hypervisor) initrd() (string, error) {
p := h.Initrd p := h.Initrd
if p == "" { if p == "" {
return "", nil return "", errors.New("initrd is not set")
} }
return ResolvePath(p) return ResolvePath(p)
@ -176,7 +176,7 @@ func (h hypervisor) image() (string, error) {
p := h.Image p := h.Image
if p == "" { if p == "" {
return "", nil return "", errors.New("image is not set")
} }
return ResolvePath(p) return ResolvePath(p)
@ -340,20 +340,16 @@ func (h hypervisor) guestHookPath() string {
} }
func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error) { func (h hypervisor) getInitrdAndImage() (initrd string, image string, err error) {
if initrd, err = h.initrd(); err != nil { initrd, errInitrd := h.initrd()
return
}
if image, err = h.image(); err != nil { image, errImage := h.image()
return
}
if image != "" && initrd != "" { if image != "" && initrd != "" {
return "", "", errors.New("having both an image and an initrd defined in the configuration file is not supported") return "", "", errors.New("having both an image and an initrd defined in the configuration file is not supported")
} }
if image == "" && initrd == "" { if errInitrd != nil && errImage != nil {
return "", "", errors.New("either image or initrd must be defined in the configuration file") return "", "", fmt.Errorf("Either initrd or image must be set to a valid path (initrd: %v) (image: %v)", errInitrd, errImage)
} }
return return

View File

@ -1046,14 +1046,14 @@ func TestHypervisorDefaultsInitrd(t *testing.T) {
defaultInitrdPath = testInitrdPath defaultInitrdPath = testInitrdPath
h := hypervisor{} h := hypervisor{}
p, err := h.initrd() p, err := h.initrd()
assert.NoError(err) assert.Error(err)
assert.Equal(p, "", "default Image path wrong") assert.Equal(p, "", "default Image path wrong")
// test path resolution // test path resolution
defaultInitrdPath = testInitrdLinkPath defaultInitrdPath = testInitrdLinkPath
h = hypervisor{} h = hypervisor{}
p, err = h.initrd() p, err = h.initrd()
assert.NoError(err) assert.Error(err)
assert.Equal(p, "") assert.Equal(p, "")
} }
@ -1083,14 +1083,14 @@ func TestHypervisorDefaultsImage(t *testing.T) {
defaultImagePath = testImagePath defaultImagePath = testImagePath
h := hypervisor{} h := hypervisor{}
p, err := h.image() p, err := h.image()
assert.NoError(err) assert.Error(err)
assert.Equal(p, "", "default Image path wrong") assert.Equal(p, "", "default Image path wrong")
// test path resolution // test path resolution
defaultImagePath = testImageLinkPath defaultImagePath = testImageLinkPath
h = hypervisor{} h = hypervisor{}
p, err = h.image() p, err = h.image()
assert.NoError(err) assert.Error(err)
assert.Equal(p, "") assert.Equal(p, "")
} }