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

Commit

Permalink
config: Reorganize the code to fix code complexity
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sebastien Boeuf committed Dec 20, 2018
1 parent d6c1f53 commit 353564a
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pkg/katautils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func newShimConfig(s shim) (vc.ShimConfig, error) {
}, 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 {
var err error
var hConfig vc.HypervisorConfig
Expand All @@ -567,6 +567,10 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
config.HypervisorConfig = hConfig
}

return nil
}

func updateRuntimeConfigProxy(configPath string, tomlConf tomlConfig, config *oci.RuntimeConfig) error {
for k, proxy := range tomlConf.Proxy {
switch k {
case ccProxyTableType:
Expand All @@ -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 {
switch k {
case hyperstartAgentTableType:
Expand All @@ -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 {
switch k {
case ccShimTableType:
Expand All @@ -611,6 +623,26 @@ func updateRuntimeConfig(configPath string, tomlConf tomlConfig, config *oci.Run
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)
if err != nil {
return fmt.Errorf("%v: %v", configPath, err)
Expand Down

0 comments on commit 353564a

Please # to comment.