docker/swarmkit

View on GitHub
manager/allocator/network.go

Summary

Maintainability
F
1 wk
Test Coverage

File network.go has 1128 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package allocator

import (
    "context"
    "fmt"
Severity: Major
Found in manager/allocator/network.go - About 2 days to fix

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

    func (a *Allocator) doNetworkAlloc(ctx context.Context, ev events.Event) {
        nc := a.netCtx
    
        switch v := ev.(type) {
        case api.EventCreateNetwork:
    Severity: Minor
    Found in manager/allocator/network.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 Allocator.allocateTask has a Cognitive Complexity of 40 (exceeds 20 allowed). Consider refactoring.
    Open

    func (a *Allocator) allocateTask(ctx context.Context, t *api.Task) (err error) {
        taskUpdated := false
        nc := a.netCtx
    
        logger := log.G(ctx).WithField("method", "(*Allocator).allocateTask")
    Severity: Minor
    Found in manager/allocator/network.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 Allocator.doNetworkAlloc has 111 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (a *Allocator) doNetworkAlloc(ctx context.Context, ev events.Event) {
        nc := a.netCtx
    
        switch v := ev.(type) {
        case api.EventCreateNetwork:
    Severity: Major
    Found in manager/allocator/network.go - About 3 hrs to fix

      Allocator has 26 methods (exceeds 20 allowed). Consider refactoring.
      Open

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

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

        func (a *Allocator) allocateService(ctx context.Context, s *api.Service, existingAddressesOnly bool) error {
            nc := a.netCtx
        
            if s.Spec.Endpoint != nil {
                // service has user-defined endpoint
        Severity: Minor
        Found in manager/allocator/network.go - About 2 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 Allocator.allocateTasks has a Cognitive Complexity of 32 (exceeds 20 allowed). Consider refactoring.
        Open

        func (a *Allocator) allocateTasks(ctx context.Context, existingAddressesOnly bool) error {
            var (
                nc             = a.netCtx
                tasks          []*api.Task
                allocatedTasks []*api.Task
        Severity: Minor
        Found in manager/allocator/network.go - About 2 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 Allocator.allocateNode has a Cognitive Complexity of 30 (exceeds 20 allowed). Consider refactoring.
        Open

        func (a *Allocator) allocateNode(ctx context.Context, node *api.Node, existingAddressesOnly bool, networks []*api.Network) bool {
            var allocated bool
        
            nc := a.netCtx
        
        
        Severity: Minor
        Found in manager/allocator/network.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 Allocator.allocateTasks has 71 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (a *Allocator) allocateTasks(ctx context.Context, existingAddressesOnly bool) error {
            var (
                nc             = a.netCtx
                tasks          []*api.Task
                allocatedTasks []*api.Task
        Severity: Minor
        Found in manager/allocator/network.go - About 1 hr to fix

          Method Allocator.doTaskAlloc has 63 lines of code (exceeds 50 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 1 hr to fix

            Method Allocator.doNetworkInit has 57 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

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

              Method Allocator.allocateTask has 56 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (a *Allocator) allocateTask(ctx context.Context, t *api.Task) (err error) {
                  taskUpdated := false
                  nc := a.netCtx
              
                  logger := log.G(ctx).WithField("method", "(*Allocator).allocateTask")
              Severity: Minor
              Found in manager/allocator/network.go - About 1 hr to fix

                Method Allocator.allocateNode has 54 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

                func (a *Allocator) allocateNode(ctx context.Context, node *api.Node, existingAddressesOnly bool, networks []*api.Network) bool {
                    var allocated bool
                
                    nc := a.netCtx
                
                
                Severity: Minor
                Found in manager/allocator/network.go - About 1 hr 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 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.allocateTask has 8 return statements (exceeds 4 allowed).
                    Open

                    func (a *Allocator) allocateTask(ctx context.Context, t *api.Task) (err error) {
                        taskUpdated := false
                        nc := a.netCtx
                    
                        logger := log.G(ctx).WithField("method", "(*Allocator).allocateTask")
                    Severity: Major
                    Found in manager/allocator/network.go - About 50 mins to fix

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

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

                              switch v := ev.(type) {
                              case api.EventCreateNode:
                                  a.store.View(func(tx store.ReadTx) {
                                      node = store.GetNode(tx, v.Node.ID)
                                  })
                          Severity: Major
                          Found in manager/allocator/network.go and 1 other location - About 1 hr to fix
                          manager/allocator/network.go on lines 882..894

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

                          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

                              switch v := ev.(type) {
                              case api.EventCreateTask:
                                  a.store.View(func(tx store.ReadTx) {
                                      t = store.GetTask(tx, v.Task.ID)
                                  })
                          Severity: Major
                          Found in manager/allocator/network.go and 1 other location - About 1 hr to fix
                          manager/allocator/network.go on lines 307..319

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

                          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 err := a.store.Batch(func(batch *store.Batch) error {
                                  for _, node := range allocatedNodes {
                                      if err := a.commitAllocatedNode(ctx, batch, node); err != nil {
                                          log.G(ctx).WithError(err).Errorf("Failed to commit allocation of network resources for node %s", node.ID)
                                      }
                          Severity: Major
                          Found in manager/allocator/network.go and 1 other location - About 1 hr to fix
                          manager/allocator/network.go on lines 631..640

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

                          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 err := a.store.Batch(func(batch *store.Batch) error {
                                  for _, n := range allocatedNetworks {
                                      if err := a.commitAllocatedNetwork(ctx, batch, n); err != nil {
                                          log.G(ctx).WithError(err).Errorf("failed committing allocation of network %s during init", n.ID)
                                      }
                          Severity: Major
                          Found in manager/allocator/network.go and 1 other location - About 1 hr to fix
                          manager/allocator/network.go on lines 474..483

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

                          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

                              err := a.store.Batch(func(batch *store.Batch) error {
                                  for _, n := range allocatedNetworks {
                                      if err := a.commitAllocatedNetwork(ctx, batch, n); err != nil {
                                          log.G(ctx).WithError(err).Debugf("Failed to commit allocation of unallocated network %s", n.ID)
                                          continue
                          Severity: Major
                          Found in manager/allocator/network.go and 1 other location - About 1 hr to fix
                          manager/allocator/network.go on lines 1454..1463

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

                          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

                              err := a.store.Batch(func(batch *store.Batch) error {
                                  for _, s := range allocatedServices {
                                      if err := a.commitAllocatedService(ctx, batch, s); err != nil {
                                          log.G(ctx).WithError(err).Debugf("Failed to commit allocation of unallocated service %s", s.ID)
                                          continue
                          Severity: Major
                          Found in manager/allocator/network.go and 1 other location - About 1 hr to fix
                          manager/allocator/network.go on lines 1415..1424

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

                          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 err := batch.Update(func(tx store.Tx) error {
                                  err := store.UpdateNode(tx, node)
                          
                                  if err == store.ErrSequenceConflict {
                                      storeNode := store.GetNode(tx, node.ID)
                          Severity: Minor
                          Found in manager/allocator/network.go and 1 other location - About 55 mins to fix
                          manager/allocator/network.go on lines 1248..1264

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

                          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 err := batch.Update(func(tx store.Tx) error {
                                  err := store.UpdateService(tx, s)
                          
                                  if err == store.ErrSequenceConflict {
                                      storeService := store.GetService(tx, s.ID)
                          Severity: Minor
                          Found in manager/allocator/network.go and 1 other location - About 55 mins to fix
                          manager/allocator/network.go on lines 1106..1122

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

                          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