From 353564abe006961b108f4e1313939bc06de77626 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 17 Dec 2018 13:23:25 -0800 Subject: [PATCH] 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 --- pkg/katautils/config.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/pkg/katautils/config.go b/pkg/katautils/config.go index b0f61c86fa..88ca34fefd 100644 --- a/pkg/katautils/config.go +++ b/pkg/katautils/config.go @@ -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 @@ -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: @@ -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: @@ -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: @@ -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)