From 1f9ac240d45a15ae7f246cd09558cb69d19c0cd1 Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Tue, 5 Mar 2019 17:29:34 -0800 Subject: [PATCH] cpu: re-arrange code to reduce cyclomatic complexity Static checks complaining about cyclomatic complexity > 15 for CreateContainer Signed-off-by: Archana Shinde --- grpc.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/grpc.go b/grpc.go index 620fef0af6..b4946bd8b8 100644 --- a/grpc.go +++ b/grpc.go @@ -648,13 +648,8 @@ func (a *agentGRPC) CreateContainer(ctx context.Context, req *pb.CreateContainer return emptyResp, err } - if ociSpec.Linux.Resources.CPU != nil && ociSpec.Linux.Resources.CPU.Cpus != "" { - availableCpuset, err := getAvailableCpusetList(ociSpec.Linux.Resources.CPU.Cpus) - if err != nil { - return emptyResp, err - } - - ociSpec.Linux.Resources.CPU.Cpus = availableCpuset + if err := a.handleCPUSet(ociSpec); err != nil { + return emptyResp, err } if err := a.applyNetworkSysctls(ociSpec); err != nil { @@ -738,6 +733,18 @@ func (a *agentGRPC) applyNetworkSysctls(ociSpec *specs.Spec) error { return nil } +func (a *agentGRPC) handleCPUSet(ociSpec *specs.Spec) error { + if ociSpec.Linux.Resources.CPU != nil && ociSpec.Linux.Resources.CPU.Cpus != "" { + availableCpuset, err := getAvailableCpusetList(ociSpec.Linux.Resources.CPU.Cpus) + if err != nil { + return err + } + + ociSpec.Linux.Resources.CPU.Cpus = availableCpuset + } + return nil +} + func posixRlimitsToRlimits(posixRlimits []specs.POSIXRlimit) []configs.Rlimit { var rlimits []configs.Rlimit