Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bump_v18.09] Fix nil pointer dereference in node allocation, linter fixes #2769

Merged
merged 7 commits into from
Oct 22, 2018
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
13 changes: 6 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
ARCH: amd64
GOVERSION: 1.10.3
# Needed to install protoc
PROTOC: https://github.com/google/protobuf/releases/download/v3.5.0/protoc-3.5.0-linux-x86_64.zip
PROTOC_VERSION: 3.6.1

# Note(cyli): We create a tmpfs mount to be used for temporary files created by tests
# to mitigate the excessive I/O latencies that sometimes cause the tests to fail.
Expand Down Expand Up @@ -61,12 +61,11 @@ jobs:
- run:
name: Install protoc
command: |
curl -fsSL -o "$HOME/$(basename $PROTOC)" "$PROTOC"
unzip -o "$HOME/$(basename $PROTOC)" -d "$HOME"
sudo cp -R "$HOME/include/google" /usr/local/include
sudo chmod 777 -R /usr/local/include/google
sudo cp -R "$HOME/bin/protoc" /usr/local/bin
sudo chmod 777 /usr/local/bin/protoc
curl --silent --show-error --location --output protoc.zip \
https://github.com/google/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip \
&& sudo unzip -d /usr/local protoc.zip include/\* bin\/* \
&& sudo chmod -R a+r /usr/local/include/google/protobuf/
rm -f protoc.zip

- run:
name: Install test/lint dependencies
Expand Down
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"
}
18 changes: 7 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ FROM golang:1.10.3-stretch

RUN apt-get update && apt-get install -y make git unzip

# should stay consistent with the version we use in Circle builds
ARG PROTOC_VERSION=3.5.0
# make a directory to do these operations in
RUN export PROTOC_TMP_DIR=protoc && mkdir -p $PROTOC_TMP_DIR && cd $PROTOC_TMP_DIR \
# download the pre-built protoc binary
&& curl --silent --show-error --location --output protoc.zip \
https://github.com/google/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip \
# move the binary to /bin. move the well-known types ot /usr/local/include
&& unzip protoc.zip && mv bin/protoc /bin/protoc && mv include/* /usr/local/include \
# remove all of the installation files
&& cd .. && rm -rf $PROTOC_TMP_DIR
# should stay consistent with the version in .circleci/config.yml
ARG PROTOC_VERSION=3.6.1
# download and install protoc binary and .proto files
RUN curl --silent --show-error --location --output protoc.zip \
https://github.com/google/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-x86_64.zip \
&& unzip -d /usr/local protoc.zip include/\* bin/\* \
&& rm -f protoc.zip

WORKDIR /go/src/github.com/docker/swarmkit/

Expand Down
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
Loading