dotcloud/docker

View on GitHub
libnetwork/cnmallocator/networkallocator.go

Summary

Maintainability
F
3 days
Test Coverage

File networkallocator.go has 684 lines of code (exceeds 500 allowed). Consider refactoring.
Open

package cnmallocator

import (
    "context"
    "fmt"
Severity: Minor
Found in libnetwork/cnmallocator/networkallocator.go - About 6 hrs to fix

    Method cnmNetworkAllocator.IsServiceAllocated has a Cognitive Complexity of 42 (exceeds 20 allowed). Consider refactoring.
    Open

    func (na *cnmNetworkAllocator) IsServiceAllocated(s *api.Service, flags ...func(*networkallocator.ServiceAllocationOpts)) bool {
        specNetworks := serviceNetworks(s)
    
        // If endpoint mode is VIP and allocator does not have the
        // service in VIP allocated set then it needs to be allocated.
    Severity: Minor
    Found in libnetwork/cnmallocator/networkallocator.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 cnmNetworkAllocator.AllocateService has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring.
    Open

    func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
        defer func() {
            if err != nil {
                na.DeallocateService(s)
            }
    Severity: Minor
    Found in libnetwork/cnmallocator/networkallocator.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

    cnmNetworkAllocator has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type cnmNetworkAllocator struct {
        // The plugin getter instance used to get network and IPAM driver plugins.
        pg plugingetter.PluginGetter
    
        // The driver registry for all internal and external IPAM drivers.
    Severity: Minor
    Found in libnetwork/cnmallocator/networkallocator.go - About 2 hrs to fix

      Method cnmNetworkAllocator.allocatePools has 66 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string, error) {
          ipam, dName, dOptions, err := na.resolveIPAM(n)
          if err != nil {
              return nil, err
          }
      Severity: Minor
      Found in libnetwork/cnmallocator/networkallocator.go - About 1 hr to fix

        Method cnmNetworkAllocator.AllocateService has 64 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
            defer func() {
                if err != nil {
                    na.DeallocateService(s)
                }
        Severity: Minor
        Found in libnetwork/cnmallocator/networkallocator.go - About 1 hr to fix

          Method cnmNetworkAllocator.allocatePools has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
          Open

          func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string, error) {
              ipam, dName, dOptions, err := na.resolveIPAM(n)
              if err != nil {
                  return nil, err
              }
          Severity: Minor
          Found in libnetwork/cnmallocator/networkallocator.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 cnmNetworkAllocator.allocateNetworkIPs has a Cognitive Complexity of 25 (exceeds 20 allowed). Consider refactoring.
          Open

          func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment) error {
              var ip *net.IPNet
              var opts map[string]string
          
              ipam, _, _, err := na.resolveIPAM(nAttach.Network)
          Severity: Minor
          Found in libnetwork/cnmallocator/networkallocator.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 cnmNetworkAllocator.allocateVIP has 8 return statements (exceeds 4 allowed).
          Open

          func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
              var opts map[string]string
              localNet := na.getNetwork(vip.NetworkID)
              if localNet == nil {
                  return errors.New("networkallocator: could not find local network state")
          Severity: Major
          Found in libnetwork/cnmallocator/networkallocator.go - About 50 mins to fix

            Method cnmNetworkAllocator.IsAttachmentAllocated has 8 return statements (exceeds 4 allowed).
            Open

            func (na *cnmNetworkAllocator) IsAttachmentAllocated(node *api.Node, networkAttachment *api.NetworkAttachment) bool {
                if node == nil {
                    return false
                }
            
            
            Severity: Major
            Found in libnetwork/cnmallocator/networkallocator.go - About 50 mins to fix

              Method cnmNetworkAllocator.IsServiceAllocated has 7 return statements (exceeds 4 allowed).
              Open

              func (na *cnmNetworkAllocator) IsServiceAllocated(s *api.Service, flags ...func(*networkallocator.ServiceAllocationOpts)) bool {
                  specNetworks := serviceNetworks(s)
              
                  // If endpoint mode is VIP and allocator does not have the
                  // service in VIP allocated set then it needs to be allocated.
              Severity: Major
              Found in libnetwork/cnmallocator/networkallocator.go - About 45 mins to fix

                Method cnmNetworkAllocator.deallocateVIP has 6 return statements (exceeds 4 allowed).
                Open

                func (na *cnmNetworkAllocator) deallocateVIP(vip *api.Endpoint_VirtualIP) error {
                    localNet := na.getNetwork(vip.NetworkID)
                    if localNet == nil {
                        return errors.New("networkallocator: could not find local network state")
                    }
                Severity: Major
                Found in libnetwork/cnmallocator/networkallocator.go - About 40 mins to fix

                  Method cnmNetworkAllocator.allocatePools has 6 return statements (exceeds 4 allowed).
                  Open

                  func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string, error) {
                      ipam, dName, dOptions, err := na.resolveIPAM(n)
                      if err != nil {
                          return nil, err
                      }
                  Severity: Major
                  Found in libnetwork/cnmallocator/networkallocator.go - About 40 mins to fix

                    Method cnmNetworkAllocator.IsTaskAllocated has 6 return statements (exceeds 4 allowed).
                    Open

                    func (na *cnmNetworkAllocator) IsTaskAllocated(t *api.Task) bool {
                        // If the task is not found in the allocated set, then it is
                        // not allocated.
                        if _, ok := na.tasks[t.ID]; !ok {
                            return false
                    Severity: Major
                    Found in libnetwork/cnmallocator/networkallocator.go - About 40 mins to fix

                      Method cnmNetworkAllocator.allocateNetworkIPs has 6 return statements (exceeds 4 allowed).
                      Open

                      func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment) error {
                          var ip *net.IPNet
                          var opts map[string]string
                      
                          ipam, _, _, err := na.resolveIPAM(nAttach.Network)
                      Severity: Major
                      Found in libnetwork/cnmallocator/networkallocator.go - About 40 mins to fix

                        Method Provider.NewAllocator has 5 return statements (exceeds 4 allowed).
                        Open

                        func (p *Provider) NewAllocator(netConfig *networkallocator.Config) (networkallocator.NetworkAllocator, error) {
                            na := &cnmNetworkAllocator{
                                networks: make(map[string]*network),
                                services: make(map[string]struct{}),
                                tasks:    make(map[string]struct{}),
                        Severity: Major
                        Found in libnetwork/cnmallocator/networkallocator.go - About 35 mins to fix

                          Method cnmNetworkAllocator.Allocate has 5 return statements (exceeds 4 allowed).
                          Open

                          func (na *cnmNetworkAllocator) Allocate(n *api.Network) error {
                              if _, ok := na.networks[n.ID]; ok {
                                  return fmt.Errorf("network %s already allocated", n.ID)
                              }
                          
                          
                          Severity: Major
                          Found in libnetwork/cnmallocator/networkallocator.go - About 35 mins to fix

                            Method cnmNetworkAllocator.AllocateService has 5 return statements (exceeds 4 allowed).
                            Open

                            func (na *cnmNetworkAllocator) AllocateService(s *api.Service) (err error) {
                                defer func() {
                                    if err != nil {
                                        na.DeallocateService(s)
                                    }
                            Severity: Major
                            Found in libnetwork/cnmallocator/networkallocator.go - About 35 mins to fix

                              There are no issues that match your filters.

                              Category
                              Status