Skip to content

Commit

Permalink
Merge pull request moby#2750 from kolyshkin/context
Browse files Browse the repository at this point in the history
Use gometalinter; switch from x/net/context -> context

Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
  • Loading branch information
dperny authored and olljanat committed Oct 10, 2018
2 parents 01966d4 + 0e8bb70 commit dce6ce4
Show file tree
Hide file tree
Showing 147 changed files with 313 additions and 427 deletions.
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")
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

0 comments on commit dce6ce4

Please sign in to comment.