docker/swarmkit

View on GitHub

Showing 1,820 of 1,820 total issues

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

func NewRaftProxyResourceAllocatorServer(local ResourceAllocatorServer, connSelector raftselector.ConnProvider, localCtxMod, remoteCtxMod func(context.Context) (context.Context, error)) ResourceAllocatorServer {
    redirectChecker := func(ctx context.Context) (context.Context, error) {
        p, ok := peer.FromContext(ctx)
        if !ok {
            return ctx, status.Errorf(codes.InvalidArgument, "remote addr is not found in context")
Severity: Major
Found in api/resource.pb.go and 9 other locations - About 5 hrs to fix
api/ca.pb.go on lines 1094..1125
api/ca.pb.go on lines 1236..1267
api/dispatcher.pb.go on lines 2449..2480
api/health.pb.go on lines 378..409
api/logbroker.pb.go on lines 1722..1753
api/logbroker.pb.go on lines 1845..1876
api/raft.pb.go on lines 2092..2123
api/raft.pb.go on lines 2291..2322
api/watch.pb.go on lines 2155..2186

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

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

func NewRaftProxyRaftMembershipServer(local RaftMembershipServer, connSelector raftselector.ConnProvider, localCtxMod, remoteCtxMod func(context.Context) (context.Context, error)) RaftMembershipServer {
    redirectChecker := func(ctx context.Context) (context.Context, error) {
        p, ok := peer.FromContext(ctx)
        if !ok {
            return ctx, status.Errorf(codes.InvalidArgument, "remote addr is not found in context")
Severity: Major
Found in api/raft.pb.go and 9 other locations - About 5 hrs to fix
api/ca.pb.go on lines 1094..1125
api/ca.pb.go on lines 1236..1267
api/dispatcher.pb.go on lines 2449..2480
api/health.pb.go on lines 378..409
api/logbroker.pb.go on lines 1722..1753
api/logbroker.pb.go on lines 1845..1876
api/raft.pb.go on lines 2092..2123
api/resource.pb.go on lines 570..601
api/watch.pb.go on lines 2155..2186

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

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 Agent.run has 168 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (a *Agent) run(ctx context.Context) {
    ctx, cancel := context.WithCancel(ctx)
    defer cancel()
    defer close(a.closed) // full shutdown.

Severity: Major
Found in agent/agent.go - About 5 hrs to fix

    Method testSuite.TestNodeAllocator has 168 lines of code (exceeds 50 allowed). Consider refactoring.
    Open

    func (suite *testSuite) TestNodeAllocator() {
        s := store.NewMemoryStore(nil)
        suite.NotNil(s)
        defer s.Close()
    
    
    Severity: Major
    Found in manager/allocator/allocator_test_suite.go - About 5 hrs to fix

      Method Secret.Unmarshal has 165 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

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

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

            for _, filter := range filters {
                switch v := filter.By.(type) {
                case *SelectBy_ID:
                    if m.ID != "" {
                        return nil, errConflictingFilters
        Severity: Major
        Found in api/objects.pb.go and 1 other location - About 5 hrs to fix
        api/objects.pb.go on lines 5045..5084

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

        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

            for _, filter := range filters {
                switch v := filter.By.(type) {
                case *SelectBy_ID:
                    if m.ID != "" {
                        return nil, errConflictingFilters
        Severity: Major
        Found in api/objects.pb.go and 1 other location - About 5 hrs to fix
        api/objects.pb.go on lines 5291..5330

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

        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

        Function parseUpdate has a Cognitive Complexity of 52 (exceeds 20 allowed). Consider refactoring.
        Open

        func parseUpdate(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
            if flags.Changed("update-parallelism") {
                parallelism, err := flags.GetUint64("update-parallelism")
                if err != nil {
                    return err
        Severity: Minor
        Found in swarmd/cmd/swarmctl/service/flagparser/update.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 ClusterSpec.Unmarshal has 65 return statements (exceeds 4 allowed).
        Open

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

          Method WatchSelectors.MarshalToSizedBuffer has a Cognitive Complexity of 52 (exceeds 20 allowed). Consider refactoring.
          Open

          func (m *WatchSelectors) MarshalToSizedBuffer(dAtA []byte) (int, error) {
              i := len(dAtA)
              _ = i
              var l int
              _ = l
          Severity: Minor
          Found in protobuf/plugin/plugin.pb.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 AssignmentsMessage.Unmarshal has 164 lines of code (exceeds 50 allowed). Consider refactoring.
          Open

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

            Method RaftMember.Unmarshal has 163 lines of code (exceeds 50 allowed). Consider refactoring.
            Open

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

              Function dumpSnapshot has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
              Open

              func dumpSnapshot(swarmdir, unlockKey string, redact bool) error {
                  _, snapshot, err := loadData(swarmdir, unlockKey)
                  if err != nil {
                      return err
                  }
              Severity: Minor
              Found in swarmd/cmd/swarm-rafttool/dump.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 Server.ListServiceStatuses has a Cognitive Complexity of 51 (exceeds 20 allowed). Consider refactoring.
              Open

              func (s *Server) ListServiceStatuses(ctx context.Context, req *api.ListServiceStatusesRequest) (*api.ListServiceStatusesResponse, error) {
                  resp := &api.ListServiceStatusesResponse{}
                  if req == nil {
                      return resp, nil
                  }
              Severity: Minor
              Found in manager/controlapi/service.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 readTx.findIterators has 159 lines of code (exceeds 50 allowed). Consider refactoring.
              Open

              func (tx readTx) findIterators(table string, by By, checkType func(By) error) ([]memdb.ResultIterator, error) {
                  switch by.(type) {
                  case byAll, orCombinator: // generic types
                  default: // all other types
                      if err := checkType(by); err != nil {
              Severity: Major
              Found in manager/state/store/memory.go - About 5 hrs to fix

                Method ClusterSnapshot.Unmarshal has 157 lines of code (exceeds 50 allowed). Consider refactoring.
                Open

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

                  Method TaskReaper.Run has a Cognitive Complexity of 50 (exceeds 20 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: Minor
                  Found in manager/orchestrator/taskreaper/task_reaper.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.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 VolumeSpec.Unmarshal has 60 return statements (exceeds 4 allowed).
                  Open

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

                    Function parseResource has a Cognitive Complexity of 49 (exceeds 20 allowed). Consider refactoring.
                    Open

                    func parseResource(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
                        if flags.Changed("memory-reservation") {
                            if spec.Task.Resources == nil {
                                spec.Task.Resources = &api.ResourceRequirements{}
                            }
                    Severity: Minor
                    Found in swarmd/cmd/swarmctl/service/flagparser/resource.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

                    Severity
                    Category
                    Status
                    Source
                    Language