Skip to content

Commit

Permalink
cpu: re-arrange code to reduce cyclomatic complexity
Browse files Browse the repository at this point in the history
Static checks complaining about cyclomatic complexity > 15
for CreateContainer

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Mar 6, 2019
1 parent 4f249bf commit 1f9ac24
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 1f9ac24

Please sign in to comment.