Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gometalinter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Vendor": true,
"Exclude": [
".*\\.pb\\.go"
],
"Enable": [
"vet",
"misspell",
"gofmt",
"goimports",
"golint",
"gosimple",
"ineffassign",
"deadcode",
"unconvert"
],
"Deadline": "2m"
}
2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package agent

import (
"bytes"
"context"
"math/rand"
"reflect"
"sync"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/log"
"github.com/pkg/errors"
"golang.org/x/net/context"
)

const (
Expand Down
5 changes: 3 additions & 2 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"context"
"crypto/tls"
"errors"
"fmt"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/docker/swarmkit/xnet"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)

var localDispatcher = false
Expand Down Expand Up @@ -90,7 +90,8 @@ func TestAgentStartStop(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, agent)

ctx, _ := context.WithTimeout(tc.Context, 5000*time.Millisecond)
ctx, cancel := context.WithTimeout(tc.Context, 5000*time.Millisecond)
defer cancel()

assert.Equal(t, errAgentNotStarted, agent.Stop(ctx))
assert.NoError(t, agent.Start(ctx))
Expand Down
7 changes: 1 addition & 6 deletions agent/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,5 @@ var (
errAgentStarted = errors.New("agent: already started")
errAgentNotStarted = errors.New("agent: not started")

errTaskNoController = errors.New("agent: no task controller")
errTaskNotAssigned = errors.New("agent: task not assigned")
errTaskStatusUpdateNoChange = errors.New("agent: no change in task status")
errTaskUnknown = errors.New("agent: task unknown")

errTaskInvalid = errors.New("task: invalid")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these were unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, as listed in the changelog message from the commit:

agent/errors.go:7:1 errTaskNoController is unused (deadcode)
agent/errors.go:7:1 errTaskStatusUpdateNoChange is unused (deadcode)
agent/errors.go:7:1 errTaskNotAssigned is unused (deadcode)
agent/errors.go:7:1 errTaskInvalid is unused (deadcode)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that these are private to the package so if it compiles those can safely be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, had missed that.

errTaskUnknown = errors.New("agent: task unknown")
)
2 changes: 1 addition & 1 deletion agent/exec/controller.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exec

import (
"context"
"fmt"
"time"

Expand All @@ -10,7 +11,6 @@ import (
"github.com/docker/swarmkit/protobuf/ptypes"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
)

// Controller controls execution of a task.
Expand Down
5 changes: 3 additions & 2 deletions agent/exec/controller_stub.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package exec

import (
"github.com/docker/swarmkit/api"
"golang.org/x/net/context"
"context"
"runtime"
"strings"

"github.com/docker/swarmkit/api"
)

// StubController implements the Controller interface,
Expand Down
2 changes: 1 addition & 1 deletion agent/exec/controller_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package exec

import (
"context"
"errors"
"fmt"
"runtime"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/docker/swarmkit/log"
gogotypes "github.com/gogo/protobuf/types"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)

func TestResolve(t *testing.T) {
Expand Down
10 changes: 4 additions & 6 deletions agent/exec/dockerapi/adapter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dockerapi

import (
"context"
"encoding/json"
"fmt"
"io"
Expand All @@ -16,7 +17,6 @@ import (
gogotypes "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
"golang.org/x/time/rate"
)

Expand Down Expand Up @@ -144,15 +144,13 @@ func (c *containerAdapter) removeNetworks(ctx context.Context) error {
}

func (c *containerAdapter) create(ctx context.Context) error {
if _, err := c.client.ContainerCreate(ctx,
_, err := c.client.ContainerCreate(ctx,
c.container.config(),
c.container.hostConfig(),
c.container.networkingConfig(),
c.container.name()); err != nil {
return err
}
c.container.name())

return nil
return err
}

func (c *containerAdapter) start(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion agent/exec/dockerapi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dockerapi
import (
"bufio"
"bytes"
"context"
"encoding/binary"
"fmt"
"io"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/docker/swarmkit/log"
gogotypes "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
"golang.org/x/net/context"
"golang.org/x/time/rate"
)

Expand Down
2 changes: 1 addition & 1 deletion agent/exec/dockerapi/controller_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dockerapi

import (
"context"
"flag"
"testing"

Expand All @@ -9,7 +10,6 @@ import (
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/api/genericresource"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion agent/exec/dockerapi/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dockerapi

import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/docker/swarmkit/log"
gogotypes "github.com/gogo/protobuf/types"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)

var tenSecond = 10 * time.Second
Expand Down
11 changes: 6 additions & 5 deletions agent/exec/dockerapi/docker_client_stub.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package dockerapi

import (
"context"
"io"
"runtime"
"strings"
"time"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/events"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/client"
"golang.org/x/net/context"
"io"
"runtime"
"strings"
"time"
)

// StubAPIClient implements the client.APIClient interface, but allows
Expand Down
4 changes: 2 additions & 2 deletions agent/exec/dockerapi/executor.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package dockerapi

import (
"context"
"sort"
"strings"
"sync"

"github.com/docker/docker/api/types/filters"
engineapi "github.com/docker/docker/client"
"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/agent/secrets"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/log"
"golang.org/x/net/context"
"sync"
)

type executor struct {
Expand Down
3 changes: 2 additions & 1 deletion agent/exec/executor.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package exec

import (
"context"

"github.com/docker/swarmkit/api"
"golang.org/x/net/context"
)

// Executor provides controllers for tasks.
Expand Down
2 changes: 1 addition & 1 deletion agent/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package agent

import "golang.org/x/net/context"
import "context"

// runctx blocks until the function exits, closed is closed, or the context is
// cancelled. Call as part of go statement.
Expand Down
2 changes: 1 addition & 1 deletion agent/reporter.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package agent

import (
"context"
"reflect"
"sync"

"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/log"
"golang.org/x/net/context"
)

// StatusReporter receives updates to task status. Method may be called
Expand Down
2 changes: 1 addition & 1 deletion agent/reporter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"context"
"errors"
"fmt"
"math/rand"
Expand All @@ -9,7 +10,6 @@ import (

"github.com/docker/swarmkit/api"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)

type uniqueStatus struct {
Expand Down
3 changes: 2 additions & 1 deletion agent/resource.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package agent

import (
"context"

"github.com/docker/swarmkit/api"
"golang.org/x/net/context"
)

type resourceAllocator struct {
Expand Down
7 changes: 3 additions & 4 deletions agent/session.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package agent

import (
"context"
"errors"
"sync"
"time"
Expand All @@ -9,15 +10,13 @@ import (
"github.com/docker/swarmkit/connectionbroker"
"github.com/docker/swarmkit/log"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

var (
dispatcherRPCTimeout = 5 * time.Second
errSessionDisconnect = errors.New("agent: session disconnect") // instructed to disconnect
errSessionClosed = errors.New("agent: session closed")
)

Expand Down Expand Up @@ -137,7 +136,7 @@ func (s *session) start(ctx context.Context, description *api.NodeDescription) e
// `ctx` is done and hence fail to propagate the timeout error to the agent.
// If the error is not propogated to the agent, the agent will not close
// the session or rebuild a new session.
sessionCtx, cancelSession := context.WithCancel(ctx)
sessionCtx, cancelSession := context.WithCancel(ctx) // nolint: vet

// Need to run Session in a goroutine since there's no way to set a
// timeout for an individual Recv call in a stream.
Expand All @@ -160,7 +159,7 @@ func (s *session) start(ctx context.Context, description *api.NodeDescription) e
select {
case err := <-errChan:
if err != nil {
return err
return err // nolint: vet
}
case <-time.After(dispatcherRPCTimeout):
cancelSession()
Expand Down
2 changes: 1 addition & 1 deletion agent/task.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package agent

import (
"context"
"sync"
"time"

"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/api"
"github.com/docker/swarmkit/api/equality"
"github.com/docker/swarmkit/log"
"golang.org/x/net/context"
)

// taskManager manages all aspects of task execution and reporting for an agent
Expand Down
2 changes: 1 addition & 1 deletion agent/task_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package agent

import (
"context"
"testing"
"time"

"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/api"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)

func init() {
Expand Down
Loading