mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 11:06:21 +00:00
config: Check factory config
If VM factory templating is enabled (`enable_template=true`), error if the configured image is not an `initrd=` one. Also add a note to the config file explaining that a normal image cannot be used - only initrd images are supported. Fixes #948. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
This commit is contained in:
parent
fe784c1e36
commit
0bf29c8207
@ -193,6 +193,8 @@ enable_iothreads = @DEFENABLEIOTHREADS@
|
||||
#
|
||||
# When disabled, new VMs are created from scratch.
|
||||
#
|
||||
# Note: Requires "initrd=" to be set ("image=" is not supported).
|
||||
#
|
||||
# Default false
|
||||
#enable_template = true
|
||||
|
||||
|
@ -677,6 +677,10 @@ func checkConfig(config oci.RuntimeConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := checkFactoryConfig(config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -710,6 +714,15 @@ func checkNetNsConfig(config oci.RuntimeConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkFactoryConfig ensures the VM factory configuration is valid.
|
||||
func checkFactoryConfig(config oci.RuntimeConfig) error {
|
||||
if config.FactoryConfig.Template && config.HypervisorConfig.InitrdPath == "" {
|
||||
return errors.New("Factory option enable_template requires an initrd image")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkHypervisorConfig performs basic "sanity checks" on the hypervisor
|
||||
// config.
|
||||
func checkHypervisorConfig(config vc.HypervisorConfig) error {
|
||||
|
@ -1497,3 +1497,44 @@ func TestCheckNetNsConfig(t *testing.T) {
|
||||
err = checkNetNsConfig(config)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
func TestCheckFactoryConfig(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
type testData struct {
|
||||
factoryEnabled bool
|
||||
imagePath string
|
||||
initrdPath string
|
||||
expectError bool
|
||||
}
|
||||
|
||||
data := []testData{
|
||||
{false, "", "", false},
|
||||
{false, "image", "", false},
|
||||
{false, "", "initrd", false},
|
||||
|
||||
{true, "", "initrd", false},
|
||||
{true, "image", "", true},
|
||||
}
|
||||
|
||||
for i, d := range data {
|
||||
config := oci.RuntimeConfig{
|
||||
HypervisorConfig: vc.HypervisorConfig{
|
||||
ImagePath: d.imagePath,
|
||||
InitrdPath: d.initrdPath,
|
||||
},
|
||||
|
||||
FactoryConfig: oci.FactoryConfig{
|
||||
Template: d.factoryEnabled,
|
||||
},
|
||||
}
|
||||
|
||||
err := checkFactoryConfig(config)
|
||||
|
||||
if d.expectError {
|
||||
assert.Error(err, "test %d (%+v)", i, d)
|
||||
} else {
|
||||
assert.NoError(err, "test %d (%+v)", i, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user