docker/swarmkit

View on GitHub

Showing 1,008 of 1,820 total issues

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

func (s *Scheduler) scheduleNTasksOnNodes(ctx context.Context, n int, taskGroup map[string]*api.Task, nodes []NodeInfo, schedulingDecisions map[string]schedulingDecision, nodeLess func(a *NodeInfo, b *NodeInfo) bool) int {
    tasksScheduled := 0
    failedConstraints := make(map[int]bool) // key is index in nodes slice
    nodeIter := 0
    nodeCount := len(nodes)
Severity: Minor
Found in manager/scheduler/scheduler.go - About 35 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 Updater.rollbackUpdate has 5 return statements (exceeds 4 allowed).
Open

func (u *Updater) rollbackUpdate(ctx context.Context, serviceID, message string) {
    log.G(ctx).Debugf("starting rollback of service %s", serviceID)

    err := u.store.Update(func(tx store.Tx) error {
        service := store.GetService(tx, serviceID)
Severity: Major
Found in manager/orchestrator/update/updater.go - About 35 mins to fix

    Method Dispatcher.register has 5 return statements (exceeds 4 allowed).
    Open

    func (d *Dispatcher) register(ctx context.Context, nodeID string, description *api.NodeDescription) (string, error) {
        logLocal := log.G(ctx).WithField("method", "(*Dispatcher).register")
        // prevent register until we're ready to accept it
        dctx, err := d.isRunningLocked()
        if err != nil {
    Severity: Major
    Found in manager/dispatcher/dispatcher.go - About 35 mins to fix

      Method RaftDEKManager.GetKeys has 5 return statements (exceeds 4 allowed).
      Open

      func (r *RaftDEKManager) GetKeys() raft.EncryptionKeys {
          var newKeys, originalKeys raft.EncryptionKeys
          err := r.kw.ViewAndUpdateHeaders(func(h ca.PEMKeyHeaders) (ca.PEMKeyHeaders, error) {
              data, ok := h.(RaftDEKData)
              if !ok {
      Severity: Major
      Found in manager/deks.go - About 35 mins to fix

        Method Allocator.reallocateNode has 5 return statements (exceeds 4 allowed).
        Open

        func (a *Allocator) reallocateNode(ctx context.Context, nodeID string) error {
            var (
                node *api.Node
            )
            a.store.View(func(tx store.ReadTx) {
        Severity: Major
        Found in manager/allocator/network.go - About 35 mins to fix

          Method Cluster.UpdateMember has 5 return statements (exceeds 4 allowed).
          Open

          func (c *Cluster) UpdateMember(id uint64, m *api.RaftMember) error {
              c.mu.Lock()
              defer c.mu.Unlock()
          
              if c.removed[id] {
          Severity: Major
          Found in manager/state/raft/membership/cluster.go - About 35 mins to fix

            Method testSuite.TestServiceUpdatePort has 5 return statements (exceeds 4 allowed).
            Open

            func (suite *testSuite) TestServiceUpdatePort() {
                s := store.NewMemoryStore(nil)
                suite.NotNil(s)
                defer s.Close()
            
            
            Severity: Major
            Found in manager/allocator/allocator_test_suite.go - About 35 mins to fix

              Method Transport.AddPeer has 5 return statements (exceeds 4 allowed).
              Open

              func (t *Transport) AddPeer(id uint64, addr string) 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 35 mins to fix

                Method testSuite.TestAllocateServiceConflictingUserDefinedPorts has 5 return statements (exceeds 4 allowed).
                Open

                func (suite *testSuite) TestAllocateServiceConflictingUserDefinedPorts() {
                    s := store.NewMemoryStore(nil)
                    suite.NotNil(s)
                    defer s.Close()
                
                
                Severity: Major
                Found in manager/allocator/allocator_test_suite.go - About 35 mins to fix

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

                  func Parse(env []string) ([]Constraint, error) {
                      exprs := []Constraint{}
                      for _, e := range env {
                          found := false
                          // each expr is in the form of "key op value"
                  Severity: Major
                  Found in manager/constraint/constraint.go - About 35 mins to fix

                    Method Node.TransferLeadership has 5 return statements (exceeds 4 allowed).
                    Open

                    func (n *Node) TransferLeadership(ctx context.Context) error {
                        ctx, cancelTransfer := context.WithTimeout(ctx, n.reqTimeout())
                        defer cancelTransfer()
                    
                        n.stopMu.RLock()
                    Severity: Major
                    Found in manager/state/raft/raft.go - About 35 mins to fix

                      Function CheckValuesOnNodes has 5 return statements (exceeds 4 allowed).
                      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: Major
                      Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

                        Method Batch.Update has 5 return statements (exceeds 4 allowed).
                        Open

                        func (batch *Batch) Update(cb func(Tx) error) error {
                            if batch.err != nil {
                                return batch.err
                            }
                        
                        
                        Severity: Major
                        Found in manager/state/store/memory.go - About 35 mins to fix

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

                          func WaitForCluster(t *testing.T, clockSource *fakeclock.FakeClock, nodes map[uint64]*TestNode) {
                              err := testutils.PollFunc(clockSource, func() error {
                                  var prev *etcdraft.Status
                                  var leadNode *TestNode
                              nodeLoop:
                          Severity: Major
                          Found in manager/state/raft/testutils/testutils.go - About 35 mins to fix

                            Method portSpace.allocate has 5 return statements (exceeds 4 allowed).
                            Open

                            func (ps *portSpace) allocate(p *api.PortConfig) (err error) {
                                if p.PublishedPort != 0 {
                                    // If it falls in the dynamic port range check out
                                    // from dynamic port space first.
                                    if p.PublishedPort >= dynamicPortStart && p.PublishedPort <= dynamicPortEnd {
                            Severity: Major
                            Found in manager/allocator/portallocator.go - About 35 mins to fix

                              Method Node.saveToStorage has 5 return statements (exceeds 4 allowed).
                              Open

                              func (n *Node) saveToStorage(
                                  ctx context.Context,
                                  raftConfig *api.RaftConfig,
                                  hardState raftpb.HardState,
                                  entries []raftpb.Entry,
                              Severity: Major
                              Found in manager/state/raft/raft.go - About 35 mins to fix

                                Method SecretDriver.Get has 5 return statements (exceeds 4 allowed).
                                Open

                                func (d *SecretDriver) Get(spec *api.SecretSpec, task *api.Task) ([]byte, bool, error) {
                                    if spec == nil {
                                        return nil, false, fmt.Errorf("secret spec is nil")
                                    }
                                    if task == nil {
                                Severity: Major
                                Found in manager/drivers/secrets.go - About 35 mins to fix

                                  Method Manager.IsStateDirty has 5 return statements (exceeds 4 allowed).
                                  Open

                                  func (m *Manager) IsStateDirty() (bool, error) {
                                      var (
                                          storeSnapshot *api.StoreSnapshot
                                          err           error
                                      )
                                  Severity: Major
                                  Found in manager/dirty.go - About 35 mins to fix

                                    Method Node.StreamRaftMessage has 5 return statements (exceeds 4 allowed).
                                    Open

                                    func (n *Node) StreamRaftMessage(stream api.Raft_StreamRaftMessageServer) error {
                                        // recvdMsg is the current messasge received from the stream.
                                        // assembledMessage is where the data from recvdMsg is appended to.
                                        var recvdMsg, assembledMessage *api.StreamRaftMessageRequest
                                        var err error
                                    Severity: Major
                                    Found in manager/state/raft/raft.go - About 35 mins to fix

                                      Method controller.Logs has a Cognitive Complexity of 21 (exceeds 20 allowed). Consider refactoring.
                                      Open

                                      func (r *controller) Logs(ctx context.Context, publisher exec.LogPublisher, options api.LogSubscriptionOptions) error {
                                          if err := r.checkClosed(); err != nil {
                                              return err
                                          }
                                      
                                      
                                      Severity: Minor
                                      Found in swarmd/dockerexec/controller.go - About 25 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

                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language