Skip to content

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 <[email protected]>
  • Loading branch information
Sebastien Boeuf authored and mcastelino committed Dec 20, 2018
1 parent 6f78c2a commit 356ccb1
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 356ccb1

Please sign in to comment.