dotcloud/docker

View on GitHub
libnetwork/endpoint.go

Summary

Maintainability
F
6 days
Test Coverage

File endpoint.go has 952 lines of code (exceeds 500 allowed). Consider refactoring.
Open

// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.21

package libnetwork

Severity: Major
Found in libnetwork/endpoint.go - About 1 day to fix

    Method Endpoint.sbJoin has a Cognitive Complexity of 63 (exceeds 20 allowed). Consider refactoring.
    Open

    func (ep *Endpoint) sbJoin(ctx context.Context, sb *Sandbox, options ...EndpointOption) (retErr error) {
        ctx, span := otel.Tracer("").Start(ctx, "libnetwork.sbJoin")
        defer span.End()
    
        n, err := ep.getNetworkFromStore()
    Severity: Minor
    Found in libnetwork/endpoint.go - About 7 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

    Endpoint has 38 methods (exceeds 20 allowed). Consider refactoring.
    Open

    type Endpoint struct {
        name         string
        id           string
        network      *Network
        iface        *EndpointInterface
    Severity: Minor
    Found in libnetwork/endpoint.go - About 5 hrs to fix

      Method Endpoint.sbJoin has 132 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (ep *Endpoint) sbJoin(ctx context.Context, sb *Sandbox, options ...EndpointOption) (retErr error) {
          ctx, span := otel.Tracer("").Start(ctx, "libnetwork.sbJoin")
          defer span.End()
      
          n, err := ep.getNetworkFromStore()
      Severity: Major
      Found in libnetwork/endpoint.go - About 4 hrs to fix

        Method Endpoint.UnmarshalJSON has a Cognitive Complexity of 37 (exceeds 20 allowed). Consider refactoring.
        Open

        func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
            ep.mu.Lock()
            defer ep.mu.Unlock()
        
            var epMap map[string]interface{}
        Severity: Minor
        Found in libnetwork/endpoint.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 Endpoint.UnmarshalJSON has 101 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (ep *Endpoint) UnmarshalJSON(b []byte) (err error) {
            ep.mu.Lock()
            defer ep.mu.Unlock()
        
            var epMap map[string]interface{}
        Severity: Major
        Found in libnetwork/endpoint.go - About 3 hrs to fix

          Method Endpoint.sbLeave has a Cognitive Complexity of 36 (exceeds 20 allowed). Consider refactoring.
          Open

          func (ep *Endpoint) sbLeave(ctx context.Context, sb *Sandbox, force bool) error {
              n, err := ep.getNetworkFromStore()
              if err != nil {
                  return fmt.Errorf("failed to get network from store during leave: %v", err)
              }
          Severity: Minor
          Found in libnetwork/endpoint.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 Endpoint.sbLeave has 86 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (ep *Endpoint) sbLeave(ctx context.Context, sb *Sandbox, force bool) error {
              n, err := ep.getNetworkFromStore()
              if err != nil {
                  return fmt.Errorf("failed to get network from store during leave: %v", err)
              }
          Severity: Major
          Found in libnetwork/endpoint.go - About 2 hrs to fix

            Method Endpoint.sbJoin has 18 return statements (exceeds 4 allowed).
            Open

            func (ep *Endpoint) sbJoin(ctx context.Context, sb *Sandbox, options ...EndpointOption) (retErr error) {
                ctx, span := otel.Tracer("").Start(ctx, "libnetwork.sbJoin")
                defer span.End()
            
                n, err := ep.getNetworkFromStore()
            Severity: Major
            Found in libnetwork/endpoint.go - About 1 hr to fix

              Method Endpoint.sbLeave has 10 return statements (exceeds 4 allowed).
              Open

              func (ep *Endpoint) sbLeave(ctx context.Context, sb *Sandbox, force bool) error {
                  n, err := ep.getNetworkFromStore()
                  if err != nil {
                      return fmt.Errorf("failed to get network from store during leave: %v", err)
                  }
              Severity: Major
              Found in libnetwork/endpoint.go - About 1 hr to fix

                Method Controller.cleanupLocalEndpoints has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                Open

                func (c *Controller) cleanupLocalEndpoints() error {
                    // Get used endpoints
                    eps := make(map[string]interface{})
                    for _, sb := range c.sandboxes {
                        for _, ep := range sb.endpoints {
                Severity: Minor
                Found in libnetwork/endpoint.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 Endpoint.Delete has 6 return statements (exceeds 4 allowed).
                Open

                func (ep *Endpoint) Delete(ctx context.Context, force bool) error {
                    var err error
                    n, err := ep.getNetworkFromStore()
                    if err != nil {
                        return fmt.Errorf("failed to get network during Delete: %v", err)
                Severity: Major
                Found in libnetwork/endpoint.go - About 40 mins to fix

                  Method Endpoint.UpdateDNSNames has 5 return statements (exceeds 4 allowed).
                  Open

                  func (ep *Endpoint) UpdateDNSNames(dnsNames []string) error {
                      nw := ep.getNetwork()
                      c := nw.getController()
                      sb, ok := ep.getSandbox()
                      if !ok {
                  Severity: Major
                  Found in libnetwork/endpoint.go - About 35 mins to fix

                    Method Endpoint.assignAddressVersion has 5 return statements (exceeds 4 allowed).
                    Open

                    func (ep *Endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
                        var (
                            poolID  *string
                            address **net.IPNet
                            prefAdd net.IP
                    Severity: Major
                    Found in libnetwork/endpoint.go - About 35 mins to fix

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

                              if opt, ok := ep.generic[netlabel.PortMap]; ok {
                                  pblist := []types.PortBinding{}
                      
                                  for i := 0; i < len(opt.([]interface{})); i++ {
                                      pb := types.PortBinding{}
                      Severity: Major
                      Found in libnetwork/endpoint.go and 1 other location - About 2 hrs to fix
                      libnetwork/endpoint.go on lines 184..204

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

                      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 opt, ok := ep.generic[netlabel.ExposedPorts]; ok {
                                  tplist := []types.TransportPort{}
                      
                                  for i := 0; i < len(opt.([]interface{})); i++ {
                                      tp := types.TransportPort{}
                      Severity: Major
                      Found in libnetwork/endpoint.go and 1 other location - About 2 hrs to fix
                      libnetwork/endpoint.go on lines 162..182

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

                      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 ep.iface.addrv6 != nil {
                              if err := ipam.ReleaseAddress(ep.iface.v6PoolID, ep.iface.addrv6.IP); err != nil {
                                  log.G(context.TODO()).Warnf("Failed to release ip address %s on delete of endpoint %s (%s): %v", ep.iface.addrv6.IP, ep.Name(), ep.ID(), err)
                              }
                          }
                      Severity: Minor
                      Found in libnetwork/endpoint.go and 1 other location - About 45 mins to fix
                      libnetwork/endpoint.go on lines 1170..1174

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

                      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 ep.iface.addr != nil {
                              if err := ipam.ReleaseAddress(ep.iface.v4PoolID, ep.iface.addr.IP); err != nil {
                                  log.G(context.TODO()).Warnf("Failed to release ip address %s on delete of endpoint %s (%s): %v", ep.iface.addr.IP, ep.Name(), ep.ID(), err)
                              }
                          }
                      Severity: Minor
                      Found in libnetwork/endpoint.go and 1 other location - About 45 mins to fix
                      libnetwork/endpoint.go on lines 1176..1180

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

                      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