docker/swarmkit

View on GitHub

Showing 1,008 of 1,820 total issues

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

func (s *Scheduler) updateTask(ctx context.Context, t *api.Task) bool {
    // Ignore all tasks that have not reached PENDING
    // state.
    if t.Status.State < api.TaskStatePending {
        return false
Severity: Minor
Found in manager/scheduler/scheduler.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

Function watchNode has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

func watchNode(t *testing.T, watch chan events.Event, expectTimeout bool,
    fn func(t assert.TestingT, originalNode, updatedNode *api.Node, networks []string) bool,
    originalNode *api.Node,
    networks []string) {
Severity: Minor
Found in manager/allocator/allocator_test_suite.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

      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

        Avoid deeply nested control flow statements.
        Open

                                    if status.NodeID == nodeID {
                                        if assignments.addOrUpdateVolume(readTx, vol) {
                                            oneModification()
                                        }
                                    }
        Severity: Major
        Found in manager/dispatcher/dispatcher.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

            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

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

                      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

                      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

                        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

                          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

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

                              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

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

                                func parsePortConfig(portConfig string) (string, api.PortConfig_Protocol, uint32, uint32, error) {
                                    protocol := api.ProtocolTCP
                                    parts := strings.Split(portConfig, ":")
                                    if len(parts) < 2 {
                                        return "", protocol, 0, 0, errors.New("insufficient parameters in port configuration")
                                Severity: Major
                                Found in swarmd/cmd/swarmctl/service/flagparser/port.go - About 40 mins to fix

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

                                  func ParseAddSecret(cmd *cobra.Command, spec *api.ServiceSpec, flagName string) error {
                                      flags := cmd.Flags()
                                  
                                      if flags.Changed(flagName) {
                                          secrets, err := flags.GetStringSlice(flagName)
                                  Severity: Major
                                  Found in swarmd/cmd/swarmctl/service/flagparser/secret.go - About 40 mins to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language