mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-30 17:22:33 +00:00
factory: Make VMCache and VM templating can work together
Make VMCache and VM templating can work together. Fixes: #1376 Signed-off-by: Hui Zhu <teawater@hyper.sh>
This commit is contained in:
parent
fae022dc64
commit
343a0d35fe
@ -158,20 +158,21 @@ var initFactoryCommand = cli.Command{
|
|||||||
return errors.New("invalid runtime config")
|
return errors.New("invalid runtime config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
factoryConfig := vf.Config{
|
||||||
|
Template: runtimeConfig.FactoryConfig.Template,
|
||||||
|
Cache: runtimeConfig.FactoryConfig.VMCacheNumber,
|
||||||
|
VMCache: runtimeConfig.FactoryConfig.VMCacheNumber > 0,
|
||||||
|
VMConfig: vc.VMConfig{
|
||||||
|
HypervisorType: runtimeConfig.HypervisorType,
|
||||||
|
HypervisorConfig: runtimeConfig.HypervisorConfig,
|
||||||
|
AgentType: runtimeConfig.AgentType,
|
||||||
|
AgentConfig: runtimeConfig.AgentConfig,
|
||||||
|
ProxyType: runtimeConfig.ProxyType,
|
||||||
|
ProxyConfig: runtimeConfig.ProxyConfig,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
if runtimeConfig.FactoryConfig.VMCacheNumber > 0 {
|
if runtimeConfig.FactoryConfig.VMCacheNumber > 0 {
|
||||||
factoryConfig := vf.Config{
|
|
||||||
Template: runtimeConfig.FactoryConfig.Template,
|
|
||||||
Cache: runtimeConfig.FactoryConfig.VMCacheNumber,
|
|
||||||
VMCache: true,
|
|
||||||
VMConfig: vc.VMConfig{
|
|
||||||
HypervisorType: runtimeConfig.HypervisorType,
|
|
||||||
HypervisorConfig: runtimeConfig.HypervisorConfig,
|
|
||||||
AgentType: runtimeConfig.AgentType,
|
|
||||||
AgentConfig: runtimeConfig.AgentConfig,
|
|
||||||
ProxyType: runtimeConfig.ProxyType,
|
|
||||||
ProxyConfig: runtimeConfig.ProxyConfig,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
f, err := vf.NewFactory(ctx, factoryConfig, false)
|
f, err := vf.NewFactory(ctx, factoryConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -204,16 +205,6 @@ var initFactoryCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if runtimeConfig.FactoryConfig.Template {
|
if runtimeConfig.FactoryConfig.Template {
|
||||||
factoryConfig := vf.Config{
|
|
||||||
Template: true,
|
|
||||||
VMConfig: vc.VMConfig{
|
|
||||||
HypervisorType: runtimeConfig.HypervisorType,
|
|
||||||
HypervisorConfig: runtimeConfig.HypervisorConfig,
|
|
||||||
AgentType: runtimeConfig.AgentType,
|
|
||||||
AgentConfig: runtimeConfig.AgentConfig,
|
|
||||||
ProxyType: runtimeConfig.ProxyType,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
kataLog.WithField("factory", factoryConfig).Info("create vm factory")
|
kataLog.WithField("factory", factoryConfig).Info("create vm factory")
|
||||||
_, err := vf.NewFactory(ctx, factoryConfig, false)
|
_, err := vf.NewFactory(ctx, factoryConfig, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -222,8 +213,9 @@ var initFactoryCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
fmt.Fprintln(defaultOutputFile, "vm factory initialized")
|
fmt.Fprintln(defaultOutputFile, "vm factory initialized")
|
||||||
} else {
|
} else {
|
||||||
kataLog.Error("vm factory is not enabled")
|
const errstring = "vm factory or VMCache is not enabled"
|
||||||
fmt.Fprintln(defaultOutputFile, "vm factory is not enabled")
|
kataLog.Error(errstring)
|
||||||
|
fmt.Fprintln(defaultOutputFile, errstring)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -945,10 +945,6 @@ func checkNetNsConfig(config oci.RuntimeConfig) error {
|
|||||||
|
|
||||||
// checkFactoryConfig ensures the VM factory configuration is valid.
|
// checkFactoryConfig ensures the VM factory configuration is valid.
|
||||||
func checkFactoryConfig(config oci.RuntimeConfig) error {
|
func checkFactoryConfig(config oci.RuntimeConfig) error {
|
||||||
if config.FactoryConfig.Template && config.FactoryConfig.VMCacheNumber > 0 {
|
|
||||||
return errors.New("VM factory cannot work together with VM cache")
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.FactoryConfig.Template {
|
if config.FactoryConfig.Template {
|
||||||
if config.HypervisorConfig.InitrdPath == "" {
|
if config.HypervisorConfig.InitrdPath == "" {
|
||||||
return errors.New("Factory option enable_template requires an initrd image")
|
return errors.New("Factory option enable_template requires an initrd image")
|
||||||
|
@ -122,7 +122,6 @@ func HandleFactory(ctx context.Context, vci vc.VC, runtimeConfig *oci.RuntimeCon
|
|||||||
if !runtimeConfig.FactoryConfig.Template && runtimeConfig.FactoryConfig.VMCacheNumber == 0 {
|
if !runtimeConfig.FactoryConfig.Template && runtimeConfig.FactoryConfig.VMCacheNumber == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
factoryConfig := vf.Config{
|
factoryConfig := vf.Config{
|
||||||
Template: runtimeConfig.FactoryConfig.Template,
|
Template: runtimeConfig.FactoryConfig.Template,
|
||||||
VMCache: runtimeConfig.FactoryConfig.VMCacheNumber > 0,
|
VMCache: runtimeConfig.FactoryConfig.VMCacheNumber > 0,
|
||||||
@ -142,13 +141,13 @@ func HandleFactory(ctx context.Context, vci vc.VC, runtimeConfig *oci.RuntimeCon
|
|||||||
kataUtilsLogger.WithField("factory", factoryConfig).Info("load vm factory")
|
kataUtilsLogger.WithField("factory", factoryConfig).Info("load vm factory")
|
||||||
|
|
||||||
f, err := vf.NewFactory(ctx, factoryConfig, true)
|
f, err := vf.NewFactory(ctx, factoryConfig, true)
|
||||||
if err != nil {
|
if err != nil && !factoryConfig.VMCache {
|
||||||
kataUtilsLogger.WithError(err).Warn("load vm factory failed, about to create new one")
|
kataUtilsLogger.WithError(err).Warn("load vm factory failed, about to create new one")
|
||||||
f, err = vf.NewFactory(ctx, factoryConfig, false)
|
f, err = vf.NewFactory(ctx, factoryConfig, false)
|
||||||
if err != nil {
|
}
|
||||||
kataUtilsLogger.WithError(err).Warn("create vm factory failed")
|
if err != nil {
|
||||||
return
|
kataUtilsLogger.WithError(err).Warn("create vm factory failed")
|
||||||
}
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
vci.SetFactory(ctx, f)
|
vci.SetFactory(ctx, f)
|
||||||
|
@ -61,29 +61,32 @@ func NewFactory(ctx context.Context, config Config, fetchOnly bool) (vc.Factory,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var b base.FactoryBase
|
var b base.FactoryBase
|
||||||
if config.Template {
|
if config.VMCache && config.Cache == 0 {
|
||||||
if fetchOnly {
|
// For VMCache client
|
||||||
b, err = template.Fetch(config.VMConfig)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
b, err = template.New(ctx, config.VMConfig)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if config.VMCache && config.Cache == 0 {
|
|
||||||
b, err = grpccache.New(ctx, config.VMCacheEndpoint)
|
b, err = grpccache.New(ctx, config.VMCacheEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
b = direct.New(ctx, config.VMConfig)
|
if config.Template {
|
||||||
}
|
if fetchOnly {
|
||||||
|
b, err = template.Fetch(config.VMConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
b, err = template.New(ctx, config.VMConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
b = direct.New(ctx, config.VMConfig)
|
||||||
|
}
|
||||||
|
|
||||||
if config.Cache > 0 {
|
if config.Cache > 0 {
|
||||||
b = cache.New(ctx, config.Cache, b)
|
b = cache.New(ctx, config.Cache, b)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &factory{b}, nil
|
return &factory{b}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user