docker/swarmkit

View on GitHub

Showing 1,820 of 1,820 total issues

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

    if request.Filters != nil {
        clusters = filterClusters(clusters,
            func(e *api.Cluster) bool {
                return filterContains(e.Spec.Annotations.Name, request.Filters.Names)
            },
Severity: Major
Found in manager/controlapi/cluster.go and 1 other location - About 2 hrs to fix
manager/controlapi/network.go on lines 278..293

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

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 request.Filters != nil {
        networks = filterNetworks(networks,
            func(e *api.Network) bool {
                return filterContains(e.Spec.Annotations.Name, request.Filters.Names)
            },
Severity: Major
Found in manager/controlapi/network.go and 1 other location - About 2 hrs to fix
manager/controlapi/cluster.go on lines 227..242

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

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 Meta.Unmarshal has 30 return statements (exceeds 4 allowed).
Open

func (m *Meta) Unmarshal(dAtA []byte) error {
    l := len(dAtA)
    iNdEx := 0
    for iNdEx < l {
        preIndex := iNdEx
Severity: Major
Found in api/objects.pb.go - About 2 hrs to fix

    Method Endpoint.Unmarshal has 30 return statements (exceeds 4 allowed).
    Open

    func (m *Endpoint) Unmarshal(dAtA []byte) error {
        l := len(dAtA)
        iNdEx := 0
        for iNdEx < l {
            preIndex := iNdEx
    Severity: Major
    Found in api/objects.pb.go - About 2 hrs to fix

      Method TaskReaper.Run has 91 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (tr *TaskReaper) Run(ctx context.Context) {
          watcher, watchCancel := state.Watch(tr.store.WatchQueue(), api.EventCreateTask{}, api.EventUpdateTask{}, api.EventUpdateCluster{})
      
          defer func() {
              close(tr.doneChan)
      Severity: Major
      Found in manager/orchestrator/taskreaper/task_reaper.go - About 2 hrs to fix

        Method Server.signNodeCert has 91 lines of code (exceeds 50 allowed). Consider refactoring.
        Open

        func (s *Server) signNodeCert(ctx context.Context, node *api.Node) error {
            s.signingMu.Lock()
            rootCA := s.localRootCA
            externalCA := s.externalCA
            s.signingMu.Unlock()
        Severity: Major
        Found in ca/server.go - About 2 hrs to fix

          Method Server.IssueNodeCertificate has 91 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

          func (s *Server) IssueNodeCertificate(ctx context.Context, request *api.IssueNodeCertificateRequest) (*api.IssueNodeCertificateResponse, error) {
              // First, let's see if the remote node is presenting a non-empty CSR
              if len(request.CSR) == 0 {
                  return nil, status.Errorf(codes.InvalidArgument, codes.InvalidArgument.String())
              }
          Severity: Major
          Found in ca/server.go - About 2 hrs to fix

            Method Orchestrator.Run has 90 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

            func (g *Orchestrator) Run(ctx context.Context) error {
                defer close(g.doneChan)
            
                // Watch changes to services and tasks
                queue := g.store.WatchQueue()
            Severity: Major
            Found in manager/orchestrator/global/global.go - About 2 hrs to fix

              Method Config.Unmarshal has 29 return statements (exceeds 4 allowed).
              Open

              func (m *Config) Unmarshal(dAtA []byte) error {
                  l := len(dAtA)
                  iNdEx := 0
                  for iNdEx < l {
                      preIndex := iNdEx
              Severity: Major
              Found in api/objects.pb.go - About 2 hrs to fix

                Method ConfigSpec.Unmarshal has 29 return statements (exceeds 4 allowed).
                Open

                func (m *ConfigSpec) Unmarshal(dAtA []byte) error {
                    l := len(dAtA)
                    iNdEx := 0
                    for iNdEx < l {
                        preIndex := iNdEx
                Severity: Major
                Found in api/specs.pb.go - About 2 hrs to fix

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

                  func (r *Supervisor) shouldRestart(ctx context.Context, t *api.Task, service *api.Service) bool {
                      // TODO(aluzzardi): This function should not depend on `service`.
                      // There are 3 possible restart policies.
                      switch orchestrator.RestartCondition(t) {
                      case api.RestartOnAny:
                  Severity: Minor
                  Found in manager/orchestrator/restart/restart.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 JoinResponse.Unmarshal has 29 return statements (exceeds 4 allowed).
                  Open

                  func (m *JoinResponse) Unmarshal(dAtA []byte) error {
                      l := len(dAtA)
                      iNdEx := 0
                      for iNdEx < l {
                          preIndex := iNdEx
                  Severity: Major
                  Found in api/raft.pb.go - About 2 hrs to fix

                    Function WaitForCluster has a Cognitive Complexity of 34 (exceeds 20 allowed). Consider refactoring.
                    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: Minor
                    Found in manager/state/raft/testutils/testutils.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.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

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

                        if storeObject.WatchSelectors.Custom != nil && *storeObject.WatchSelectors.Custom {
                            d.P("case *SelectBy_Custom:")
                            d.In()
                            if _, hasNoSpec := typesWithNoSpec[*m.Name]; hasNoSpec {
                                d.P(`if len(m.Annotations.Indices) != 0 {`)
                    Severity: Major
                    Found in protobuf/plugin/storeobject/storeobject.go and 1 other location - About 2 hrs to fix
                    protobuf/plugin/storeobject/storeobject.go on lines 477..497

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

                    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 storeObject.WatchSelectors.CustomPrefix != nil && *storeObject.WatchSelectors.CustomPrefix {
                            d.P("case *SelectBy_CustomPrefix:")
                            d.In()
                            if _, hasNoSpec := typesWithNoSpec[*m.Name]; hasNoSpec {
                                d.P(`if len(m.Annotations.Indices) != 0 {`)
                    Severity: Major
                    Found in protobuf/plugin/storeobject/storeobject.go and 1 other location - About 2 hrs to fix
                    protobuf/plugin/storeobject/storeobject.go on lines 456..476

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

                    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 SelectBy.CopyFrom has 89 lines of code (exceeds 50 allowed). Consider refactoring.
                    Open

                    func (m *SelectBy) CopyFrom(src interface{}) {
                    
                        o := src.(*SelectBy)
                        *m = *o
                        if o.By != nil {
                    Severity: Major
                    Found in api/watch.pb.go - About 2 hrs to fix

                      Method VolumeSpec.MarshalToSizedBuffer has 89 lines of code (exceeds 50 allowed). Consider refactoring.
                      Open

                      func (m *VolumeSpec) MarshalToSizedBuffer(dAtA []byte) (int, error) {
                          i := len(dAtA)
                          _ = i
                          var l int
                          _ = l
                      Severity: Major
                      Found in api/specs.pb.go - About 2 hrs to fix

                        Method Server.ListTasks has 89 lines of code (exceeds 50 allowed). Consider refactoring.
                        Open

                        func (s *Server) ListTasks(ctx context.Context, request *api.ListTasksRequest) (*api.ListTasksResponse, error) {
                            var (
                                tasks []*api.Task
                                err   error
                            )
                        Severity: Major
                        Found in manager/controlapi/task.go - About 2 hrs to fix

                          File updater.go has 523 lines of code (exceeds 500 allowed). Consider refactoring.
                          Open

                          package update
                          
                          import (
                              "context"
                              "errors"
                          Severity: Minor
                          Found in manager/orchestrator/update/updater.go - About 2 hrs to fix
                            Severity
                            Category
                            Status
                            Source
                            Language