docker/swarmkit

View on GitHub

Showing 1,008 of 1,820 total issues

Avoid deeply nested control flow statements.
Open

                    if oldTask, exists := tasksMap[v.Task.ID]; exists {
                        // States ASSIGNED and below are set by the orchestrator/scheduler,
                        // not the agent, so tasks in these states need to be sent to the
                        // agent even if nothing else has changed.
                        if equality.TasksEqualStable(oldTask, v.Task) && v.Task.Status.State > api.TaskStateAssigned {
Severity: Major
Found in manager/dispatcher/dispatcher.go - About 45 mins to fix

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

    func validateIPAMConfiguration(ipamConf *api.IPAMConfig) error {
        if ipamConf == nil {
            return status.Errorf(codes.InvalidArgument, "ipam configuration: cannot be empty")
        }
    
    
    Severity: Major
    Found in manager/controlapi/network.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if assignments.addOrUpdateTask(readTx, v.Task) {
                                  oneModification()
                              }
      Severity: Major
      Found in manager/dispatcher/dispatcher.go - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if time.Since(debouncingStarted) > maxLatency {
                                commitDebounceTimer.Stop()
                                commitDebounceTimer = nil
                                commitDebounceTimeout = nil
                                schedule()
        Severity: Major
        Found in manager/scheduler/scheduler.go - About 45 mins to fix

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

          func (s *Server) Watch(request *api.WatchRequest, stream api.Watch_WatchServer) error {
              ctx := stream.Context()
          
              s.mu.Lock()
              pctx := s.pctx
          Severity: Major
          Found in manager/watchapi/watch.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if atomic.LoadUint32(&n.signalledLeadership) == 1 {
                                    atomic.StoreUint32(&n.signalledLeadership, 0)
                                    n.leadershipBroadcast.Publish(IsFollower)
                                }
            Severity: Major
            Found in manager/state/raft/raft.go - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                              } else if !wasLeader && rd.SoftState.RaftState == raft.StateLeader {
                                  // Node just became a leader.
                                  wasLeader = true
                              }
              Severity: Major
              Found in manager/state/raft/raft.go - About 45 mins to fix

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

                func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error {
                    f, err := os.CreateTemp(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
                    if err != nil {
                        return err
                    }
                Severity: Major
                Found in ioutils/ioutils.go - About 45 mins to fix

                  Method ResourceAllocator.DetachNetwork has 7 return statements (exceeds 4 allowed).
                  Open

                  func (ra *ResourceAllocator) DetachNetwork(ctx context.Context, request *api.DetachNetworkRequest) (*api.DetachNetworkResponse, error) {
                      if request.AttachmentID == "" {
                          return nil, status.Errorf(codes.InvalidArgument, errInvalidArgument.Error())
                      }
                  
                  
                  Severity: Major
                  Found in manager/resourceapi/allocator.go - About 45 mins to fix

                    Method Transport.Send has 7 return statements (exceeds 4 allowed).
                    Open

                    func (t *Transport) Send(m raftpb.Message) error {
                        t.mu.Lock()
                        defer t.mu.Unlock()
                        if t.stopped {
                            return errors.New("transport stopped")
                    Severity: Major
                    Found in manager/state/raft/transport/transport.go - About 45 mins to fix

                      Method Node.reportNewAddress has 7 return statements (exceeds 4 allowed).
                      Open

                      func (n *Node) reportNewAddress(ctx context.Context, id uint64) error {
                          // too early
                          if !n.IsMember() {
                              return nil
                          }
                      Severity: Major
                      Found in manager/state/raft/raft.go - About 45 mins to fix

                        Method peer.sendProcessMessage has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                        Open

                        func (p *peer) sendProcessMessage(ctx context.Context, m raftpb.Message) error {
                            // These lines used to be in the code, but they've been removed. I'm
                            // leaving them in in a comment just in case they cause some unforeseen
                            // breakage later, to show why they were removed.
                            //
                        Severity: Minor
                        Found in manager/state/raft/transport/peer.go - About 45 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

                        Avoid deeply nested control flow statements.
                        Open

                                        if err := a.commitAllocatedNetwork(ctx, batch, nc.ingressNetwork); err != nil {
                                            log.G(ctx).WithError(err).Error("failed committing allocation of ingress network during init")
                                        }
                        Severity: Major
                        Found in manager/allocator/network.go - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                  select {
                                                  case <-commitGuard:
                                                      memDBTx.Commit()
                                                  default:
                                                      // Already Abort()ed.
                          Severity: Major
                          Found in manager/state/store/memory.go - About 45 mins to fix

                            Function CheckValuesOnNodes has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring.
                            Open

                            func CheckValuesOnNodes(t *testing.T, clockSource *fakeclock.FakeClock, checkNodes map[uint64]*TestNode, ids []string, values []*api.Node) {
                                iteration := 0
                                for checkNodeID, node := range checkNodes {
                                    assert.NoError(t, testutils.PollFunc(clockSource, func() error {
                                        var err error
                            Severity: Minor
                            Found in manager/state/raft/testutils/testutils.go - About 45 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 Node.registerNode has 7 return statements (exceeds 4 allowed).
                            Open

                            func (n *Node) registerNode(node *api.RaftMember) error {
                                if n.cluster.IsIDRemoved(node.RaftID) {
                                    return nil
                                }
                            
                            
                            Severity: Major
                            Found in manager/state/raft/raft.go - About 45 mins to fix

                              Method Node.ProcessRaftMessage has 7 return statements (exceeds 4 allowed).
                              Open

                              func (n *Node) ProcessRaftMessage(ctx context.Context, msg *api.ProcessRaftMessageRequest) (*api.ProcessRaftMessageResponse, error) {
                                  if msg == nil || msg.Message == nil {
                                      n.processRaftMessageLogger(ctx, msg).Debug("received empty message")
                                      return &api.ProcessRaftMessageResponse{}, nil
                                  }
                              Severity: Major
                              Found in manager/state/raft/raft.go - About 45 mins to fix

                                Method session.sendTaskStatuses has 6 return statements (exceeds 4 allowed).
                                Open

                                func (s *session) sendTaskStatuses(ctx context.Context, updates ...*api.UpdateTaskStatusRequest_TaskStatusUpdate) ([]*api.UpdateTaskStatusRequest_TaskStatusUpdate, error) {
                                    if len(updates) < 1 {
                                        return nil, nil
                                    }
                                
                                
                                Severity: Major
                                Found in agent/session.go - About 40 mins to fix

                                  Method session.logSubscriptions has 6 return statements (exceeds 4 allowed).
                                  Open

                                  func (s *session) logSubscriptions(ctx context.Context) error {
                                      logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).logSubscriptions"})
                                      logger.Debugf("")
                                  
                                      client := api.NewLogBrokerClient(s.conn.ClientConn)
                                  Severity: Major
                                  Found in agent/session.go - About 40 mins to fix

                                    Method session.watch has 6 return statements (exceeds 4 allowed).
                                    Open

                                    func (s *session) watch(ctx context.Context) error {
                                        logger := log.G(ctx).WithFields(log.Fields{"method": "(*session).watch"})
                                        logger.Debugf("")
                                        var (
                                            resp            *api.AssignmentsMessage
                                    Severity: Major
                                    Found in agent/session.go - About 40 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language