dotcloud/docker

View on GitHub

Showing 1,904 of 1,904 total issues

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

    if len(m.Networks) > 0 {
        for iNdEx := len(m.Networks) - 1; iNdEx >= 0; iNdEx-- {
            i -= len(m.Networks[iNdEx])
            copy(dAtA[i:], m.Networks[iNdEx])
            i = encodeVarintNetworkdb(dAtA, i, uint64(len(m.Networks[iNdEx])))
Severity: Major
Found in libnetwork/networkdb/networkdb.pb.go and 4 other locations - About 55 mins to fix
api/types/swarm/runtime/plugin.pb.go on lines 211..219
api/types/swarm/runtime/plugin.pb.go on lines 281..289
libnetwork/agent.pb.go on lines 370..378
libnetwork/agent.pb.go on lines 379..387

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

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 5 locations. Consider refactoring.
Open

    if len(m.Env) > 0 {
        for iNdEx := len(m.Env) - 1; iNdEx >= 0; iNdEx-- {
            i -= len(m.Env[iNdEx])
            copy(dAtA[i:], m.Env[iNdEx])
            i = encodeVarintPlugin(dAtA, i, uint64(len(m.Env[iNdEx])))
Severity: Major
Found in api/types/swarm/runtime/plugin.pb.go and 4 other locations - About 55 mins to fix
api/types/swarm/runtime/plugin.pb.go on lines 281..289
libnetwork/agent.pb.go on lines 370..378
libnetwork/agent.pb.go on lines 379..387
libnetwork/networkdb/networkdb.pb.go on lines 1275..1283

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

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

Method Manager.Privileges has 9 return statements (exceeds 4 allowed).
Open

func (pm *Manager) Privileges(ctx context.Context, ref reference.Named, metaHeader http.Header, authConfig *registry.AuthConfig) (types.PluginPrivileges, error) {
    var (
        config     types.PluginConfig
        configSeen bool
    )
Severity: Major
Found in plugin/backend_linux.go - About 55 mins to fix

    Function SwitchRoot has 9 return statements (exceeds 4 allowed).
    Open

    func SwitchRoot(path string) error {
        if mounted, _ := mountinfo.Mounted(path); !mounted {
            if err := mount.Mount(path, path, "bind", "rbind,rw"); err != nil {
                return realChroot(path)
            }
    Severity: Major
    Found in internal/mounttree/switchroot_linux.go - About 55 mins to fix

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

      func (pm *Manager) List(pluginFilters filters.Args) ([]types.Plugin, error) {
          if err := pluginFilters.Validate(acceptedPluginFilterTags); err != nil {
              return nil, err
          }
      
      
      Severity: Minor
      Found in plugin/backend_linux.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

      Function fetchTable has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func fetchTable(ip string, port int, network, tableName string, clusterPeers, networkPeers map[string]string, remediate bool) {
          log.G(context.TODO()).Infof("Fetch %s table and check owners", tableName)
          resp, err := http.Get(fmt.Sprintf(dumpTable, ip, port, network, tableName))
          if err != nil {
              log.G(context.TODO()).WithError(err).Fatalf("Failed fetching endpoint table")
      Severity: Minor
      Found in libnetwork/cmd/diagnostic/main.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

      Function checkTable has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func checkTable(ctx context.Context, ips []string, port, networkName, tableName string, expectedEntries int, fn func(string, string, string, string, chan resultTuple)) (opTime time.Duration) {
          startTime := time.Now().UnixNano()
          var successTime int64
      
          // Loop for 2 minutes to guarantee that the result is stable
      Severity: Minor
      Found in libnetwork/cmd/networkdb-test/dbclient/ndbClient.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 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 Controller.NewSandbox has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func (c *Controller) NewSandbox(ctx context.Context, containerID string, options ...SandboxOption) (_ *Sandbox, retErr error) {
          if containerID == "" {
              return nil, types.InvalidParameterErrorf("invalid container ID")
          }
      
      
      Severity: Minor
      Found in libnetwork/controller.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

      Function StartProxy has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
      Open

      func StartProxy(pb types.PortBinding,
          proxyPath string,
          listenSock *os.File,
      ) (stop func() error, retErr error) {
          if proxyPath == "" {
      Severity: Minor
      Found in libnetwork/portmapper/proxy_linux.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 driver.Join has 9 return statements (exceeds 4 allowed).
      Open

      func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, options map[string]interface{}) (retErr error) {
          join := &api.JoinRequest{
              NetworkID:  nid,
              EndpointID: eid,
              SandboxKey: sboxKey,
      Severity: Major
      Found in libnetwork/drivers/remote/driver.go - About 55 mins to fix

        Method driver.CreateNetwork has 9 return statements (exceeds 4 allowed).
        Open

        func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error {
            kv, err := kernel.GetKernelVersion()
            if err != nil {
                return fmt.Errorf("failed to check kernel version for ipvlan driver support: %v", err)
            }
        Severity: Major
        Found in libnetwork/drivers/ipvlan/ipvlan_network.go - About 55 mins to fix

          Method bridgeNetwork.setupIPTables has 9 return statements (exceeds 4 allowed).
          Open

          func (n *bridgeNetwork) setupIPTables(ipVersion iptables.IPVersion, maskedAddr *net.IPNet, config *networkConfiguration, i *bridgeInterface) error {
              var err error
          
              d := n.driver
              d.Lock()
          Severity: Major
          Found in libnetwork/drivers/bridge/setup_ip_tables_linux.go - About 55 mins to fix

            Function newProxy has 9 return statements (exceeds 4 allowed).
            Open

            func newProxy(config ProxyConfig) (p Proxy, err error) {
                ipv := ipv4
                if config.HostIP.To4() == nil {
                    ipv = ipv6
                }
            Severity: Major
            Found in cmd/docker-proxy/main_linux.go - About 55 mins to fix

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

              func (s *distributionRouter) fetchManifest(ctx context.Context, distrepo distribution.Repository, namedRef reference.Named) (registry.DistributionInspect, error) {
                  var distributionInspect registry.DistributionInspect
                  if canonicalRef, ok := namedRef.(reference.Canonical); !ok {
                      namedRef = reference.TagNameOnly(namedRef)
              
              
              Severity: Minor
              Found in api/server/router/distribution/distribution_routes.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 State.String has 9 return statements (exceeds 4 allowed).
              Open

              func (s *State) String() string {
                  if s.Running {
                      if s.Paused {
                          return fmt.Sprintf("Up %s (Paused)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
                      }
              Severity: Major
              Found in container/state.go - About 55 mins to fix

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

                func (ir *imageRouter) getImagesJSON(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
                    if err := httputils.ParseForm(r); err != nil {
                        return err
                    }
                
                
                Severity: Minor
                Found in api/server/router/image/image_routes.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 Daemon.cleanupMountsFromReaderByID has a Cognitive Complexity of 24 (exceeds 20 allowed). Consider refactoring.
                Open

                func (daemon *Daemon) cleanupMountsFromReaderByID(reader io.Reader, id string, unmount func(target string) error) error {
                    if daemon.root == "" {
                        return nil
                    }
                    var errs []string
                Severity: Minor
                Found in daemon/daemon_linux.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 ImageService.PrepareSnapshot has 9 return statements (exceeds 4 allowed).
                Open

                func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error) error {
                    var parentSnapshot string
                    if parentImage != "" {
                        img, err := i.resolveImage(ctx, parentImage)
                        if err != nil {
                Severity: Major
                Found in daemon/containerd/image_snapshot.go - About 55 mins to fix

                  Method container.NewTask has 9 return statements (exceeds 4 allowed).
                  Open

                  func (c *container) NewTask(ctx context.Context, checkpointDir string, withStdin bool, attachStdio libcontainerdtypes.StdioCallback) (libcontainerdtypes.Task, error) {
                      var (
                          checkpoint     *types.Descriptor
                          t              containerd.Task
                          rio            cio.IO
                  Severity: Major
                  Found in libcontainerd/remote/client.go - About 55 mins to fix
                    Severity
                    Category
                    Status
                    Source
                    Language