mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-04 11:06:21 +00:00
config: Reorganize the code to fix code complexity
By breaking down updateRuntimeConfig() into smaller functions, this commit prevents the function to grow a Go complexity higher than 15. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
d6c1f531a9
commit
353564abe0
@ -547,7 +547,7 @@ func newShimConfig(s shim) (vc.ShimConfig, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
|
func updateRuntimeConfigHypervisor(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
|
||||||
for k, hypervisor := range tomlConf.Hypervisor {
|
for k, hypervisor := range tomlConf.Hypervisor {
|
||||||
var err error
|
var err error
|
||||||
var hConfig vc.HypervisorConfig
|
var hConfig vc.HypervisorConfig
|
||||||
@ -567,6 +567,10 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
|
|||||||
config.HypervisorConfig = hConfig
|
config.HypervisorConfig = hConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateRuntimeConfigProxy(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
|
||||||
for k, proxy := range tomlConf.Proxy {
|
for k, proxy := range tomlConf.Proxy {
|
||||||
switch k {
|
switch k {
|
||||||
case ccProxyTableType:
|
case ccProxyTableType:
|
||||||
@ -581,6 +585,10 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
|
||||||
for k := range tomlConf.Agent {
|
for k := range tomlConf.Agent {
|
||||||
switch k {
|
switch k {
|
||||||
case hyperstartAgentTableType:
|
case hyperstartAgentTableType:
|
||||||
@ -595,6 +603,10 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateRuntimeConfigShim(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
|
||||||
for k, shim := range tomlConf.Shim {
|
for k, shim := range tomlConf.Shim {
|
||||||
switch k {
|
switch k {
|
||||||
case ccShimTableType:
|
case ccShimTableType:
|
||||||
@ -611,6 +623,26 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
|
|||||||
config.ShimConfig = shConfig
|
config.ShimConfig = shConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
|
||||||
|
if err := updateRuntimeConfigHypervisor(configPath, tomlConf, config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := updateRuntimeConfigProxy(configPath, tomlConf, config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := updateRuntimeConfigAgent(configPath, tomlConf, config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := updateRuntimeConfigShim(configPath, tomlConf, config); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
fConfig, err := newFactoryConfig(tomlConf.Factory)
|
fConfig, err := newFactoryConfig(tomlConf.Factory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%v: %v", configPath, err)
|
return fmt.Errorf("%v: %v", configPath, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user