docker/swarmkit

View on GitHub

Showing 1,820 of 1,820 total issues

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

func (s *Server) signNodeCert(ctx context.Context, node *api.Node) error {
    s.signingMu.Lock()
    rootCA := s.localRootCA
    externalCA := s.externalCA
    s.signingMu.Unlock()
Severity: Minor
Found in ca/server.go - About 55 mins 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.NodeCertificateStatus has 9 return statements (exceeds 4 allowed).
Open

func (s *Server) NodeCertificateStatus(ctx context.Context, request *api.NodeCertificateStatusRequest) (*api.NodeCertificateStatusResponse, error) {
    if request.NodeID == "" {
        return nil, status.Errorf(codes.InvalidArgument, codes.InvalidArgument.String())
    }

Severity: Major
Found in ca/server.go - About 55 mins to fix

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

    func makeExternalSignRequest(ctx context.Context, client *http.Client, url string, csrJSON []byte) (cert []byte, err error) {
        resp, err := ctxhttp.Post(ctx, client, url, "application/json", bytes.NewReader(csrJSON))
        if err != nil {
            return nil, recoverableErr{err: errors.Wrap(err, "unable to perform certificate signing request")}
        }
    Severity: Major
    Found in ca/external.go - About 55 mins to fix

      Method raftProxyRaftServer.StreamRaftMessage has 9 return statements (exceeds 4 allowed).
      Open

      func (p *raftProxyRaftServer) StreamRaftMessage(stream Raft_StreamRaftMessageServer) error {
          ctx := stream.Context()
          conn, err := p.connSelector.LeaderConn(ctx)
          if err != nil {
              if err == raftselector.ErrIsLeader {
      Severity: Major
      Found in api/raft.pb.go - About 55 mins to fix

        Method raftProxyRaftMembershipServer.Leave has 9 return statements (exceeds 4 allowed).
        Open

        func (p *raftProxyRaftMembershipServer) Leave(ctx context.Context, r *LeaveRequest) (*LeaveResponse, error) {
        
            conn, err := p.connSelector.LeaderConn(ctx)
            if err != nil {
                if err == raftselector.ErrIsLeader {
        Severity: Major
        Found in api/raft.pb.go - About 55 mins to fix

          Method Server.signNodeCert has 9 return statements (exceeds 4 allowed).
          Open

          func (s *Server) signNodeCert(ctx context.Context, node *api.Node) error {
              s.signingMu.Lock()
              rootCA := s.localRootCA
              externalCA := s.externalCA
              s.signingMu.Unlock()
          Severity: Major
          Found in ca/server.go - About 55 mins to fix

            Method StreamRaftMessageResponse.Unmarshal has 9 return statements (exceeds 4 allowed).
            Open

            func (m *StreamRaftMessageResponse) Unmarshal(dAtA []byte) error {
                l := len(dAtA)
                iNdEx := 0
                for iNdEx < l {
                    preIndex := iNdEx
            Severity: Major
            Found in api/raft.pb.go - About 55 mins to fix

              Method LeaveResponse.Unmarshal has 9 return statements (exceeds 4 allowed).
              Open

              func (m *LeaveResponse) Unmarshal(dAtA []byte) error {
                  l := len(dAtA)
                  iNdEx := 0
                  for iNdEx < l {
                      preIndex := iNdEx
              Severity: Major
              Found in api/raft.pb.go - About 55 mins to fix

                Method raftProxyRaftServer.ProcessRaftMessage has 9 return statements (exceeds 4 allowed).
                Open

                func (p *raftProxyRaftServer) ProcessRaftMessage(ctx context.Context, r *ProcessRaftMessageRequest) (*ProcessRaftMessageResponse, error) {
                
                    conn, err := p.connSelector.LeaderConn(ctx)
                    if err != nil {
                        if err == raftselector.ErrIsLeader {
                Severity: Major
                Found in api/raft.pb.go - About 55 mins to fix

                  Method Server.ListVolumes has 9 return statements (exceeds 4 allowed).
                  Open

                  func (s *Server) ListVolumes(ctx context.Context, request *api.ListVolumesRequest) (*api.ListVolumesResponse, error) {
                      var (
                          volumes []*api.Volume
                          err     error
                      )
                  Severity: Major
                  Found in manager/controlapi/volume.go - About 55 mins to fix

                    Method Server.CreateVolume has 9 return statements (exceeds 4 allowed).
                    Open

                    func (s *Server) CreateVolume(ctx context.Context, request *api.CreateVolumeRequest) (*api.CreateVolumeResponse, error) {
                        if request.Spec == nil {
                            return nil, status.Errorf(codes.InvalidArgument, "spec must not be nil")
                        }
                    
                    
                    Severity: Major
                    Found in manager/controlapi/volume.go - About 55 mins 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 PluginFilter.Check has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func (f *PluginFilter) Check(n *NodeInfo) bool {
                            if n.Description == nil || n.Description.Engine == nil {
                                // If the node is not running Engine, plugins are not
                                // supported.
                                return true
                        Severity: Minor
                        Found in manager/scheduler/filter.go - About 55 mins 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

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

                        func WatchFrom(store *MemoryStore, version *api.Version, specifiers ...api.Event) (chan events.Event, func(), error) {
                            if version == nil {
                                ch, cancel := state.Watch(store.WatchQueue(), specifiers...)
                                return ch, cancel, nil
                            }
                        Severity: Major
                        Found in manager/state/store/memory.go - About 55 mins to fix

                          Method Allocator.doNetworkInit has 9 return statements (exceeds 4 allowed).
                          Open

                          func (a *Allocator) doNetworkInit(ctx context.Context) (err error) {
                              nc := &networkContext{
                                  nwkAllocator:        a.nwkAllocator,
                                  portAllocator:       newPortAllocator(),
                                  pendingTasks:        make(map[string]*api.Task),
                          Severity: Major
                          Found in manager/allocator/network.go - About 55 mins to fix

                            Method Allocator.doTaskAlloc has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func (a *Allocator) doTaskAlloc(ctx context.Context, ev events.Event) {
                                var (
                                    isDelete bool
                                    t        *api.Task
                                )
                            Severity: Minor
                            Found in manager/allocator/network.go - About 55 mins 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 Collector.Run has 9 return statements (exceeds 4 allowed).
                            Open

                            func (c *Collector) Run(ctx context.Context) error {
                                defer close(c.doneChan)
                            
                                watcher, cancel, err := store.ViewAndWatch(c.store, func(readTx store.ReadTx) error {
                                    nodes, err := store.FindNodes(readTx, store.All)
                            Severity: Major
                            Found in manager/metrics/collector.go - About 55 mins to fix

                              Method subscription.match has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                              Open

                              func (s *subscription) match() {
                                  s.mu.Lock()
                                  defer s.mu.Unlock()
                              
                                  add := func(t *api.Task) {
                              Severity: Minor
                              Found in manager/logbroker/subscription.go - About 55 mins 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

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

                                      case "service":
                                          if selector.id != "" {
                                              object := store.GetService(tx, selector.id)
                                              if object != nil {
                                                  objects = append(objects, object)
                              Severity: Major
                              Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                              swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                              swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                              swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                              swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                              swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                              swarmd/cmd/swarm-rafttool/dump.go on lines 394..409
                              swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                              swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

                              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 123.

                              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 9 locations. Consider refactoring.
                              Open

                                      case "config":
                                          if selector.id != "" {
                                              object := store.GetConfig(tx, selector.id)
                                              if object != nil {
                                                  objects = append(objects, object)
                              Severity: Major
                              Found in swarmd/cmd/swarm-rafttool/dump.go and 8 other locations - About 55 mins to fix
                              swarmd/cmd/swarm-rafttool/dump.go on lines 298..313
                              swarmd/cmd/swarm-rafttool/dump.go on lines 314..329
                              swarmd/cmd/swarm-rafttool/dump.go on lines 330..345
                              swarmd/cmd/swarm-rafttool/dump.go on lines 346..361
                              swarmd/cmd/swarm-rafttool/dump.go on lines 362..377
                              swarmd/cmd/swarm-rafttool/dump.go on lines 378..393
                              swarmd/cmd/swarm-rafttool/dump.go on lines 410..425
                              swarmd/cmd/swarm-rafttool/dump.go on lines 426..441

                              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 123.

                              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

                              Severity
                              Category
                              Status
                              Source
                              Language