Skip to content

Commit

Permalink
sandbox: Fix gocyclo complexity
Browse files Browse the repository at this point in the history
With the networking namespace code added, we were reaching a
gocyclo complexitiy of 52. By moving the container creation and
starting code path out, we're back to reasonable levels.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Samuel Ortiz committed Dec 10, 2016
1 parent 769d693 commit aec684f
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions server/sandbox_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@ import (
pb "k8s.io/kubernetes/pkg/kubelet/api/v1alpha1/runtime"
)

func (s *Server) runContainer(container *oci.Container) error {
if err := s.runtime.CreateContainer(container); err != nil {
return err
}

if err := s.runtime.UpdateStatus(container); err != nil {
return err
}

if err := s.runtime.StartContainer(container); err != nil {
return err
}

if err := s.runtime.UpdateStatus(container); err != nil {
return err
}

return nil
}

// RunPodSandbox creates and runs a pod-level sandbox.
func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest) (resp *pb.RunPodSandboxResponse, err error) {
logrus.Debugf("RunPodSandboxRequest %+v", req)
Expand Down Expand Up @@ -307,19 +327,7 @@ func (s *Server) RunPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
return nil, fmt.Errorf("failed to create network for container %s in sandbox %s: %v", containerName, id, err)
}

if err = s.runtime.CreateContainer(container); err != nil {
return nil, err
}

if err = s.runtime.UpdateStatus(container); err != nil {
return nil, err
}

if err = s.runtime.StartContainer(container); err != nil {
return nil, err
}

if err = s.runtime.UpdateStatus(container); err != nil {
if err = s.runContainer(container); err != nil {
return nil, err
}

Expand Down

0 comments on commit aec684f

Please sign in to comment.