docker/swarmkit

View on GitHub
manager/controlapi/service.go

Summary

Maintainability
F
6 days
Test Coverage

File service.go has 847 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package controlapi

import (
    "context"
    "errors"
Severity: Major
Found in manager/controlapi/service.go - About 1 day to fix

    Method Server.ListServiceStatuses has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *Server) ListServiceStatuses(ctx context.Context, req *api.ListServiceStatusesRequest) (*api.ListServiceStatusesResponse, error) {
        resp := &api.ListServiceStatusesResponse{}
        if req == nil {
            return resp, nil
        }
    Severity: Minor
    Found in manager/controlapi/service.go - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method Server.checkPortConflicts has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *Server) checkPortConflicts(spec *api.ServiceSpec, serviceID string) error {
        if spec.Endpoint == nil {
            return nil
        }
    
    
    Severity: Minor
    Found in manager/controlapi/service.go - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method Server.UpdateService has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
    Open

    func (s *Server) UpdateService(ctx context.Context, request *api.UpdateServiceRequest) (*api.UpdateServiceResponse, error) {
        if request.ServiceID == "" || request.ServiceVersion == nil {
            return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
        }
        if err := validateServiceSpec(request.Spec); err != nil {
    Severity: Minor
    Found in manager/controlapi/service.go - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method Server.UpdateService has 85 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (s *Server) UpdateService(ctx context.Context, request *api.UpdateServiceRequest) (*api.UpdateServiceResponse, error) {
        if request.ServiceID == "" || request.ServiceVersion == nil {
            return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
        }
        if err := validateServiceSpec(request.Spec); err != nil {
    Severity: Major
    Found in manager/controlapi/service.go - About 2 hrs to fix

      Method Server.checkPortConflicts has 78 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (s *Server) checkPortConflicts(spec *api.ServiceSpec, serviceID string) error {
          if spec.Endpoint == nil {
              return nil
          }
      
      
      Severity: Major
      Found in manager/controlapi/service.go - About 2 hrs to fix

        Method Server.UpdateService has 16 return statements (exceeds 4 allowed).
        Open

        func (s *Server) UpdateService(ctx context.Context, request *api.UpdateServiceRequest) (*api.UpdateServiceResponse, error) {
            if request.ServiceID == "" || request.ServiceVersion == nil {
                return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
            }
            if err := validateServiceSpec(request.Spec); err != nil {
        Severity: Major
        Found in manager/controlapi/service.go - About 1 hr to fix

          Function validateHealthCheck has a Cognitive Complexity of 26 (exceeds 20 allowed). Consider refactoring.
          Open

          func validateHealthCheck(hc *api.HealthConfig) error {
              if hc == nil {
                  return nil
              }
          
          
          Severity: Minor
          Found in manager/controlapi/service.go - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method Server.ListServices has 55 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (s *Server) ListServices(ctx context.Context, request *api.ListServicesRequest) (*api.ListServicesResponse, error) {
              var (
                  services []*api.Service
                  err      error
              )
          Severity: Minor
          Found in manager/controlapi/service.go - About 1 hr to fix

            Method Server.checkPortConflicts has 12 return statements (exceeds 4 allowed).
            Open

            func (s *Server) checkPortConflicts(spec *api.ServiceSpec, serviceID string) error {
                if spec.Endpoint == nil {
                    return nil
                }
            
            
            Severity: Major
            Found in manager/controlapi/service.go - About 1 hr to fix

              Function validateHealthCheck has 11 return statements (exceeds 4 allowed).
              Open

              func validateHealthCheck(hc *api.HealthConfig) error {
                  if hc == nil {
                      return nil
                  }
              
              
              Severity: Major
              Found in manager/controlapi/service.go - About 1 hr to fix

                Function validateConfigRefsSpec has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
                Open

                func validateConfigRefsSpec(spec api.TaskSpec) error {
                    container := spec.GetContainer()
                    if container == nil {
                        return nil
                    }
                Severity: Minor
                Found in manager/controlapi/service.go - About 1 hr to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Method Server.ListServiceStatuses has 51 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (s *Server) ListServiceStatuses(ctx context.Context, req *api.ListServiceStatusesRequest) (*api.ListServiceStatusesResponse, error) {
                    resp := &api.ListServiceStatusesResponse{}
                    if req == nil {
                        return resp, nil
                    }
                Severity: Minor
                Found in manager/controlapi/service.go - About 1 hr to fix

                  Function validateTaskSpec has 9 return statements (exceeds 4 allowed).
                  Open

                  func validateTaskSpec(taskSpec api.TaskSpec) error {
                      if err := validateResourceRequirements(taskSpec.Resources); err != nil {
                          return err
                      }
                  
                  
                  Severity: Major
                  Found in manager/controlapi/service.go - About 55 mins to fix

                    Method Server.ListServices has 8 return statements (exceeds 4 allowed).
                    Open

                    func (s *Server) ListServices(ctx context.Context, request *api.ListServicesRequest) (*api.ListServicesResponse, error) {
                        var (
                            services []*api.Service
                            err      error
                        )
                    Severity: Major
                    Found in manager/controlapi/service.go - About 50 mins to fix

                      Function validateConfigRefsSpec has 7 return statements (exceeds 4 allowed).
                      Open

                      func validateConfigRefsSpec(spec api.TaskSpec) error {
                          container := spec.GetContainer()
                          if container == nil {
                              return nil
                          }
                      Severity: Major
                      Found in manager/controlapi/service.go - About 45 mins to fix

                        Function validateServiceSpec has 7 return statements (exceeds 4 allowed).
                        Open

                        func validateServiceSpec(spec *api.ServiceSpec) error {
                            if spec == nil {
                                return status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
                            }
                            if err := validateAnnotations(spec.Annotations); err != nil {
                        Severity: Major
                        Found in manager/controlapi/service.go - About 45 mins to fix

                          Method Server.CreateService has 7 return statements (exceeds 4 allowed).
                          Open

                          func (s *Server) CreateService(ctx context.Context, request *api.CreateServiceRequest) (*api.CreateServiceResponse, error) {
                              if err := validateServiceSpec(request.Spec); err != nil {
                                  return nil, err
                              }
                          
                          
                          Severity: Major
                          Found in manager/controlapi/service.go - About 45 mins to fix

                            Function validateSecretRefsSpec has 6 return statements (exceeds 4 allowed).
                            Open

                            func validateSecretRefsSpec(spec api.TaskSpec) error {
                                container := spec.GetContainer()
                                if container == nil {
                                    return nil
                                }
                            Severity: Major
                            Found in manager/controlapi/service.go - About 40 mins to fix

                              Function validateRestartPolicy has 6 return statements (exceeds 4 allowed).
                              Open

                              func validateRestartPolicy(rp *api.RestartPolicy) error {
                                  if rp == nil {
                                      return nil
                                  }
                              
                              
                              Severity: Major
                              Found in manager/controlapi/service.go - About 40 mins to fix

                                Function validateUpdate has 6 return statements (exceeds 4 allowed).
                                Open

                                func validateUpdate(uc *api.UpdateConfig) error {
                                    if uc == nil {
                                        return nil
                                    }
                                
                                
                                Severity: Major
                                Found in manager/controlapi/service.go - About 40 mins to fix

                                  Function validateGenericRuntimeSpec has 6 return statements (exceeds 4 allowed).
                                  Open

                                  func validateGenericRuntimeSpec(taskSpec api.TaskSpec) error {
                                      generic := taskSpec.GetGeneric()
                                  
                                      if len(generic.Kind) < 3 {
                                          return status.Errorf(codes.InvalidArgument, "Generic runtime: Invalid name %q", generic.Kind)
                                  Severity: Major
                                  Found in manager/controlapi/service.go - About 40 mins to fix

                                    Function validateResources has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func validateResources(r *api.Resources) error {
                                        if r == nil {
                                            return nil
                                        }
                                    
                                    
                                    Severity: Major
                                    Found in manager/controlapi/service.go - About 35 mins to fix

                                      Method Server.RemoveService has 5 return statements (exceeds 4 allowed).
                                      Open

                                      func (s *Server) RemoveService(ctx context.Context, request *api.RemoveServiceRequest) (*api.RemoveServiceResponse, error) {
                                          if request.ServiceID == "" {
                                              return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
                                          }
                                      
                                      
                                      Severity: Major
                                      Found in manager/controlapi/service.go - About 35 mins to fix

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                        func (s *Server) checkConfigExistence(tx store.Tx, spec *api.ServiceSpec) error {
                                            container := spec.Task.GetContainer()
                                            if container == nil {
                                                return nil
                                            }
                                        Severity: Major
                                        Found in manager/controlapi/service.go and 1 other location - About 2 hrs to fix
                                        manager/controlapi/service.go on lines 665..691

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 238.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                        func (s *Server) checkSecretExistence(tx store.Tx, spec *api.ServiceSpec) error {
                                            container := spec.Task.GetContainer()
                                            if container == nil {
                                                return nil
                                            }
                                        Severity: Major
                                        Found in manager/controlapi/service.go and 1 other location - About 2 hrs to fix
                                        manager/controlapi/service.go on lines 694..720

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 238.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                        func (s *Server) RemoveService(ctx context.Context, request *api.RemoveServiceRequest) (*api.RemoveServiceResponse, error) {
                                            if request.ServiceID == "" {
                                                return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
                                            }
                                        
                                        
                                        Severity: Major
                                        Found in manager/controlapi/service.go and 1 other location - About 2 hrs to fix
                                        manager/controlapi/task.go on lines 38..53

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 218.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 6 locations. Consider refactoring.
                                        Open

                                        func filterServices(candidates []*api.Service, filters ...func(*api.Service) bool) []*api.Service {
                                            result := []*api.Service{}
                                        
                                            for _, c := range candidates {
                                                match := true
                                        Severity: Major
                                        Found in manager/controlapi/service.go and 5 other locations - About 1 hr to fix
                                        manager/controlapi/cluster.go on lines 186..203
                                        manager/controlapi/network.go on lines 236..253
                                        manager/controlapi/node.go on lines 59..76
                                        manager/controlapi/task.go on lines 55..72
                                        manager/controlapi/volume.go on lines 204..220

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 140.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                                if configRef.GetFile() != nil {
                                                    fileName := configRef.GetFile().Name
                                                    // Validate the file name
                                                    if fileName == "" {
                                                        return status.Errorf(codes.InvalidArgument, "malformed file config reference, invalid target file name provided")
                                        Severity: Minor
                                        Found in manager/controlapi/service.go and 1 other location - About 40 mins to fix
                                        manager/controlapi/service.go on lines 380..391

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 110.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        Similar blocks of code found in 2 locations. Consider refactoring.
                                        Open

                                                if secretRef.GetFile() != nil {
                                                    fileName := secretRef.GetFile().Name
                                                    if fileName == "" {
                                                        return status.Errorf(codes.InvalidArgument, "malformed file secret reference, invalid target file name provided")
                                                    }
                                        Severity: Minor
                                        Found in manager/controlapi/service.go and 1 other location - About 40 mins to fix
                                        manager/controlapi/service.go on lines 435..448

                                        Duplicated Code

                                        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                        Tuning

                                        This issue has a mass of 110.

                                        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                        Refactorings

                                        Further Reading

                                        There are no issues that match your filters.

                                        Category
                                        Status