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 (m *SelectBy_NamePrefix) MarshalToSizedBuffer(dAtA []byte) (int, error) {
    i := len(dAtA)
    i -= len(m.NamePrefix)
    copy(dAtA[i:], m.NamePrefix)
    i = encodeVarintWatch(dAtA, i, uint64(len(m.NamePrefix)))
Severity: Major
Found in api/watch.pb.go and 9 other locations - About 50 mins to fix
api/specs.pb.go on lines 3461..3469
api/watch.pb.go on lines 1692..1700
api/watch.pb.go on lines 1706..1714
api/watch.pb.go on lines 1720..1728
api/watch.pb.go on lines 1790..1798
api/watch.pb.go on lines 1804..1812
api/watch.pb.go on lines 1875..1883
api/watch.pb.go on lines 1889..1897
api/watch.pb.go on lines 1903..1911

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

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

func (m *ReplicatedService) MarshalToSizedBuffer(dAtA []byte) (int, error) {
    i := len(dAtA)
    _ = i
    var l int
    _ = l
Severity: Major
Found in api/specs.pb.go and 2 other locations - About 50 mins to fix
api/health.pb.go on lines 347..358
api/raft.pb.go on lines 1742..1753

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

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 updateNode has 8 return statements (exceeds 4 allowed).
Open

func updateNode(cmd *cobra.Command, args []string) error {
    if len(args) == 0 {
        return errors.New("node ID missing")
    }

Severity: Major
Found in swarmd/cmd/swarmctl/node/common.go - About 50 mins to fix

    Method controller.Prepare has 8 return statements (exceeds 4 allowed).
    Open

    func (r *controller) Prepare(ctx context.Context) error {
        if err := r.checkClosed(); err != nil {
            return err
        }
    
    
    Severity: Major
    Found in swarmd/dockerexec/controller.go - About 50 mins to fix

      Function reconcileTaskState has 8 return statements (exceeds 4 allowed).
      Open

      func reconcileTaskState(ctx context.Context, w *worker, assignments []*api.AssignmentChange, fullSnapshot bool) error {
          var (
              updatedTasks []*api.Task
              removedTasks []*api.Task
          )
      Severity: Major
      Found in agent/worker.go - About 50 mins to fix

        Method worker.Subscribe has 8 return statements (exceeds 4 allowed).
        Open

        func (w *worker) Subscribe(ctx context.Context, subscription *api.SubscriptionMessage) error {
            log.G(ctx).Debugf("Received subscription %s (selector: %v)", subscription.ID, subscription.Selector)
        
            publisher, cancel, err := w.publisherProvider.Publisher(ctx, subscription.ID)
            if err != nil {
        Severity: Major
        Found in agent/worker.go - About 50 mins to fix

          Method Resolver.get has 8 return statements (exceeds 4 allowed).
          Open

          func (r *Resolver) get(t interface{}, id string) string {
              switch t.(type) {
              case api.Node:
                  res, err := r.c.GetNode(r.ctx, &api.GetNodeRequest{NodeID: id})
                  if err != nil {
          Severity: Major
          Found in swarmd/cmd/swarmctl/common/resolver.go - About 50 mins to fix

            Function processIPAMOptions has 8 return statements (exceeds 4 allowed).
            Open

            func processIPAMOptions(cmd *cobra.Command) (*api.IPAMOptions, error) {
                flags := cmd.Flags()
            
                var ipamOpts *api.IPAMOptions
                if flags.Changed("ipam-driver") {
            Severity: Major
            Found in swarmd/cmd/swarmctl/network/create.go - About 50 mins to fix

              Function ConvertResourceWatch has 8 return statements (exceeds 4 allowed).
              Open

              func ConvertResourceWatch(action WatchActionKind, filters []*SelectBy, kind string) ([]Event, error) {
                  var (
                      m          Resource
                      checkFuncs []ResourceCheckFunc
                  )
              Severity: Major
              Found in api/objects.pb.go - About 50 mins to fix

                Function ConvertExtensionWatch has 8 return statements (exceeds 4 allowed).
                Open

                func ConvertExtensionWatch(action WatchActionKind, filters []*SelectBy) ([]Event, error) {
                    var (
                        m          Extension
                        checkFuncs []ExtensionCheckFunc
                    )
                Severity: Major
                Found in api/objects.pb.go - About 50 mins to fix

                  Function ConvertSecretWatch has 8 return statements (exceeds 4 allowed).
                  Open

                  func ConvertSecretWatch(action WatchActionKind, filters []*SelectBy) ([]Event, error) {
                      var (
                          m          Secret
                          checkFuncs []SecretCheckFunc
                      )
                  Severity: Major
                  Found in api/objects.pb.go - About 50 mins to fix

                    Function ConvertClusterWatch has 8 return statements (exceeds 4 allowed).
                    Open

                    func ConvertClusterWatch(action WatchActionKind, filters []*SelectBy) ([]Event, error) {
                        var (
                            m          Cluster
                            checkFuncs []ClusterCheckFunc
                        )
                    Severity: Major
                    Found in api/objects.pb.go - About 50 mins to fix

                      Function ConvertServiceWatch has 8 return statements (exceeds 4 allowed).
                      Open

                      func ConvertServiceWatch(action WatchActionKind, filters []*SelectBy) ([]Event, error) {
                          var (
                              m          Service
                              checkFuncs []ServiceCheckFunc
                          )
                      Severity: Major
                      Found in api/objects.pb.go - About 50 mins to fix

                        Function ConvertConfigWatch has 8 return statements (exceeds 4 allowed).
                        Open

                        func ConvertConfigWatch(action WatchActionKind, filters []*SelectBy) ([]Event, error) {
                            var (
                                m          Config
                                checkFuncs []ConfigCheckFunc
                            )
                        Severity: Major
                        Found in api/objects.pb.go - About 50 mins to fix

                          Function ConvertVolumeWatch has 8 return statements (exceeds 4 allowed).
                          Open

                          func ConvertVolumeWatch(action WatchActionKind, filters []*SelectBy) ([]Event, error) {
                              var (
                                  m          Volume
                                  checkFuncs []VolumeCheckFunc
                              )
                          Severity: Major
                          Found in api/objects.pb.go - About 50 mins to fix

                            Function ConvertNetworkWatch has 8 return statements (exceeds 4 allowed).
                            Open

                            func ConvertNetworkWatch(action WatchActionKind, filters []*SelectBy) ([]Event, error) {
                                var (
                                    m          Network
                                    checkFuncs []NetworkCheckFunc
                                )
                            Severity: Major
                            Found in api/objects.pb.go - About 50 mins to fix

                              Method raftProxyDispatcherServer.Tasks has 8 return statements (exceeds 4 allowed).
                              Open

                              func (p *raftProxyDispatcherServer) Tasks(r *TasksRequest, stream Dispatcher_TasksServer) error {
                                  ctx := stream.Context()
                                  conn, err := p.connSelector.LeaderConn(ctx)
                                  if err != nil {
                                      if err == raftselector.ErrIsLeader {
                              Severity: Major
                              Found in api/dispatcher.pb.go - About 50 mins to fix

                                Method raftProxyLogBrokerServer.ListenSubscriptions has 8 return statements (exceeds 4 allowed).
                                Open

                                func (p *raftProxyLogBrokerServer) ListenSubscriptions(r *ListenSubscriptionsRequest, stream LogBroker_ListenSubscriptionsServer) error {
                                    ctx := stream.Context()
                                    conn, err := p.connSelector.LeaderConn(ctx)
                                    if err != nil {
                                        if err == raftselector.ErrIsLeader {
                                Severity: Major
                                Found in api/logbroker.pb.go - About 50 mins to fix

                                  Method raftProxyDispatcherServer.Session has 8 return statements (exceeds 4 allowed).
                                  Open

                                  func (p *raftProxyDispatcherServer) Session(r *SessionRequest, stream Dispatcher_SessionServer) error {
                                      ctx := stream.Context()
                                      conn, err := p.connSelector.LeaderConn(ctx)
                                      if err != nil {
                                          if err == raftselector.ErrIsLeader {
                                  Severity: Major
                                  Found in api/dispatcher.pb.go - About 50 mins to fix

                                    Function sanitizeResource has 8 return statements (exceeds 4 allowed).
                                    Open

                                    func sanitizeResource(nodeRes []*api.GenericResource, res *api.GenericResource) (ok bool, nrs []*api.GenericResource) {
                                        switch na := res.Resource.(type) {
                                        case *api.GenericResource_DiscreteResourceSpec:
                                            nrs := GetResource(na.DiscreteResourceSpec.Kind, nodeRes)
                                    
                                    
                                    Severity: Major
                                    Found in api/genericresource/resource_management.go - About 50 mins to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language