From 372670b5074b077927314cdf46af30f8752e7db0 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 21 Aug 2017 17:06:56 -0400 Subject: [PATCH 1/2] Add goimports to linters. Signed-off-by: Daniel Nephin --- client/image_search_test.go | 5 ++--- cmd/dockerd/config_solaris.go | 2 -- daemon/config/config_solaris.go | 4 ---- daemon/graphdriver/driver_freebsd.go | 6 +++++- hack/dockerfile/install-binaries.sh | 1 + hack/validate/gometalinter.json | 1 + libcontainerd/client_solaris.go | 5 ++++- pkg/fileutils/fileutils_test.go | 2 +- pkg/mount/mounter_solaris.go | 3 ++- pkg/streamformatter/streamwriter_test.go | 2 +- registry/resumable/resumablerequestreader_test.go | 5 +++-- 11 files changed, 20 insertions(+), 16 deletions(-) diff --git a/client/image_search_test.go b/client/image_search_test.go index b17bbd8343..191e7f403a 100644 --- a/client/image_search_test.go +++ b/client/image_search_test.go @@ -2,18 +2,17 @@ package client import ( "bytes" + "encoding/json" "fmt" "io/ioutil" "net/http" "strings" "testing" - "golang.org/x/net/context" - - "encoding/json" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/registry" + "golang.org/x/net/context" ) func TestImageSearchAnyError(t *testing.T) { diff --git a/cmd/dockerd/config_solaris.go b/cmd/dockerd/config_solaris.go index 582211c6c8..ed67064906 100644 --- a/cmd/dockerd/config_solaris.go +++ b/cmd/dockerd/config_solaris.go @@ -2,8 +2,6 @@ package main import ( "github.com/docker/docker/daemon/config" - runconfigopts "github.com/docker/docker/runconfig/opts" - units "github.com/docker/go-units" "github.com/spf13/pflag" ) diff --git a/daemon/config/config_solaris.go b/daemon/config/config_solaris.go index 4741befac9..6b1e061b58 100644 --- a/daemon/config/config_solaris.go +++ b/daemon/config/config_solaris.go @@ -1,9 +1,5 @@ package config -import ( - "github.com/spf13/pflag" -) - // Config defines the configuration of a docker daemon. // These are the configuration settings that you pass // to the docker daemon when you launch it with say: `docker -d -e lxc` diff --git a/daemon/graphdriver/driver_freebsd.go b/daemon/graphdriver/driver_freebsd.go index fb13ac3d5e..53394b738d 100644 --- a/daemon/graphdriver/driver_freebsd.go +++ b/daemon/graphdriver/driver_freebsd.go @@ -1,6 +1,10 @@ package graphdriver -import "golang.org/x/sys/unix" +import ( + "syscall" + + "golang.org/x/sys/unix" +) var ( // Slice of drivers that should be used in an order diff --git a/hack/dockerfile/install-binaries.sh b/hack/dockerfile/install-binaries.sh index f7032e68f4..abd436f411 100755 --- a/hack/dockerfile/install-binaries.sh +++ b/hack/dockerfile/install-binaries.sh @@ -64,6 +64,7 @@ install_gometalinter() { export GOBIN=/usr/local/bin export GOPATH="$PWD/_linters/" go install github.com/golang/lint/golint + go install golang.org/x/tools/cmd/goimports ) } diff --git a/hack/validate/gometalinter.json b/hack/validate/gometalinter.json index 4b6049065f..6df7e6dc20 100644 --- a/hack/validate/gometalinter.json +++ b/hack/validate/gometalinter.json @@ -11,6 +11,7 @@ "Enable": [ "gofmt", + "goimports", "golint", "vet" ], diff --git a/libcontainerd/client_solaris.go b/libcontainerd/client_solaris.go index cb939975f8..c54cea3bfa 100644 --- a/libcontainerd/client_solaris.go +++ b/libcontainerd/client_solaris.go @@ -1,6 +1,9 @@ package libcontainerd -import "golang.org/x/net/context" +import ( + containerd "github.com/containerd/containerd/api/grpc/types" + "golang.org/x/net/context" +) type client struct { clientCommon diff --git a/pkg/fileutils/fileutils_test.go b/pkg/fileutils/fileutils_test.go index 3d61d55c3a..2df5bdd913 100644 --- a/pkg/fileutils/fileutils_test.go +++ b/pkg/fileutils/fileutils_test.go @@ -1,6 +1,7 @@ package fileutils import ( + "fmt" "io/ioutil" "os" "path" @@ -9,7 +10,6 @@ import ( "strings" "testing" - "fmt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/pkg/mount/mounter_solaris.go b/pkg/mount/mounter_solaris.go index c684aa81fc..48b86771e7 100644 --- a/pkg/mount/mounter_solaris.go +++ b/pkg/mount/mounter_solaris.go @@ -3,8 +3,9 @@ package mount import ( - "golang.org/x/sys/unix" "unsafe" + + "golang.org/x/sys/unix" ) // #include diff --git a/pkg/streamformatter/streamwriter_test.go b/pkg/streamformatter/streamwriter_test.go index 4935cc595c..a3c026a5c0 100644 --- a/pkg/streamformatter/streamwriter_test.go +++ b/pkg/streamformatter/streamwriter_test.go @@ -1,9 +1,9 @@ package streamformatter import ( + "bytes" "testing" - "bytes" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/registry/resumable/resumablerequestreader_test.go b/registry/resumable/resumablerequestreader_test.go index a632bc673a..9b3a6dc0cc 100644 --- a/registry/resumable/resumablerequestreader_test.go +++ b/registry/resumable/resumablerequestreader_test.go @@ -2,8 +2,6 @@ package resumable import ( "fmt" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "io" "io/ioutil" "net/http" @@ -11,6 +9,9 @@ import ( "strings" "testing" "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestResumableRequestHeaderSimpleErrors(t *testing.T) { From 62c1f0ef41e6cd88a8846da1c11976a320ca8b41 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Mon, 21 Aug 2017 17:51:45 -0400 Subject: [PATCH 2/2] Add deadcode linter Signed-off-by: Daniel Nephin --- api/server/httputils/errors.go | 8 -------- api/types/filters/parse.go | 8 -------- client/client_mock_test.go | 8 ++++++++ client/transport.go | 8 -------- cmd/dockerd/daemon_solaris.go | 13 ------------ cmd/dockerd/daemon_windows.go | 6 ------ daemon/daemon_solaris.go | 9 ++++----- daemon/daemon_windows.go | 20 ------------------- daemon/graphdriver/plugin.go | 10 ---------- daemon/health.go | 3 +-- daemon/metrics.go | 3 +-- hack/dockerfile/install-binaries.sh | 7 +------ hack/validate/gometalinter.json | 1 + pkg/devicemapper/devmapper.go | 1 + pkg/plugins/pluginrpc-gen/fixtures/foo.go | 6 ------ plugin/backend_linux.go | 18 +---------------- volume/drivers/extpoint.go | 1 + ...ate_test_unix.go => validate_unix_test.go} | 0 ...st_windows.go => validate_windows_test.go} | 0 volume/volume_unix.go | 4 ---- volume/volume_windows.go | 7 ------- 21 files changed, 19 insertions(+), 122 deletions(-) rename volume/{validate_test_unix.go => validate_unix_test.go} (100%) rename volume/{validate_test_windows.go => validate_windows_test.go} (100%) diff --git a/api/server/httputils/errors.go b/api/server/httputils/errors.go index 10628f6b33..05a842c3af 100644 --- a/api/server/httputils/errors.go +++ b/api/server/httputils/errors.go @@ -13,14 +13,6 @@ import ( "google.golang.org/grpc/codes" ) -// httpStatusError is an interface -// that errors with custom status codes -// implement to tell the api layer -// which response status to set. -type httpStatusError interface { - HTTPErrorStatusCode() int -} - type causer interface { Cause() error } diff --git a/api/types/filters/parse.go b/api/types/filters/parse.go index 411eafd6de..363d4540bb 100644 --- a/api/types/filters/parse.go +++ b/api/types/filters/parse.go @@ -276,14 +276,6 @@ func (filters Args) Validate(accepted map[string]bool) error { return nil } -type invalidFilterError string - -func (e invalidFilterError) Error() string { - return "Invalid filter: '" + string(e) + "'" -} - -func (invalidFilterError) InvalidParameter() {} - // WalkValues iterates over the list of filtered values for a field. // It stops the iteration if it finds an error and it returns that error. func (filters Args) WalkValues(field string, op func(value string) error) error { diff --git a/client/client_mock_test.go b/client/client_mock_test.go index 0ab935d536..e75c3ecbfc 100644 --- a/client/client_mock_test.go +++ b/client/client_mock_test.go @@ -9,6 +9,14 @@ import ( "github.com/docker/docker/api/types" ) +// transportFunc allows us to inject a mock transport for testing. We define it +// here so we can detect the tlsconfig and return nil for only this type. +type transportFunc func(*http.Request) (*http.Response, error) + +func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { + return tf(req) +} + func newMockClient(doer func(*http.Request) (*http.Response, error)) *http.Client { return &http.Client{ Transport: transportFunc(doer), diff --git a/client/transport.go b/client/transport.go index 401ab15d30..73f6ef7b4d 100644 --- a/client/transport.go +++ b/client/transport.go @@ -5,14 +5,6 @@ import ( "net/http" ) -// transportFunc allows us to inject a mock transport for testing. We define it -// here so we can detect the tlsconfig and return nil for only this type. -type transportFunc func(*http.Request) (*http.Response, error) - -func (tf transportFunc) RoundTrip(req *http.Request) (*http.Response, error) { - return tf(req) -} - // resolveTLSConfig attempts to resolve the TLS configuration from the // RoundTripper. func resolveTLSConfig(transport http.RoundTripper) *tls.Config { diff --git a/cmd/dockerd/daemon_solaris.go b/cmd/dockerd/daemon_solaris.go index dab4d4aaad..9ee18dad7d 100644 --- a/cmd/dockerd/daemon_solaris.go +++ b/cmd/dockerd/daemon_solaris.go @@ -5,27 +5,14 @@ package main import ( "fmt" "net" - "os" "path/filepath" "github.com/docker/docker/libcontainerd" - "github.com/docker/docker/pkg/system" "golang.org/x/sys/unix" ) const defaultDaemonConfigFile = "" -// currentUserIsOwner checks whether the current user is the owner of the given -// file. -func currentUserIsOwner(f string) bool { - if fileInfo, err := system.Stat(f); err == nil && fileInfo != nil { - if int(fileInfo.UID()) == os.Getuid() { - return true - } - } - return false -} - // setDefaultUmask sets the umask to 0022 to avoid problems // caused by custom umask func setDefaultUmask() error { diff --git a/cmd/dockerd/daemon_windows.go b/cmd/dockerd/daemon_windows.go index 7dd0920ce7..7407af45a2 100644 --- a/cmd/dockerd/daemon_windows.go +++ b/cmd/dockerd/daemon_windows.go @@ -14,12 +14,6 @@ import ( var defaultDaemonConfigFile = "" -// currentUserIsOwner checks whether the current user is the owner of the given -// file. -func currentUserIsOwner(f string) bool { - return false -} - // setDefaultUmask doesn't do anything on windows func setDefaultUmask() error { return nil diff --git a/daemon/daemon_solaris.go b/daemon/daemon_solaris.go index 905ed5843a..f523b1ee5a 100644 --- a/daemon/daemon_solaris.go +++ b/daemon/daemon_solaris.go @@ -22,7 +22,7 @@ import ( "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/netutils" lntypes "github.com/docker/libnetwork/types" - "github.com/opencontainers/runtime-spec/specs-go" + specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/selinux/go-selinux/label" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -32,10 +32,9 @@ import ( import "C" const ( - defaultVirtualSwitch = "Virtual Switch" - platformSupported = true - solarisMinCPUShares = 1 - solarisMaxCPUShares = 65535 + platformSupported = true + solarisMinCPUShares = 1 + solarisMaxCPUShares = 65535 ) func getMemoryResources(config containertypes.Resources) specs.CappedMemory { diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index c8ae577eac..f78f60a0af 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -5,7 +5,6 @@ import ( "os" "path/filepath" "strings" - "syscall" "github.com/Microsoft/hcsshim" "github.com/docker/docker/api/types" @@ -38,9 +37,6 @@ const ( windowsMaxCPUShares = 10000 windowsMinCPUPercent = 1 windowsMaxCPUPercent = 100 - windowsMinCPUCount = 1 - - errInvalidState = syscall.Errno(0x139F) ) // Windows has no concept of an execution state directory. So use config.Root here. @@ -60,22 +56,6 @@ func parseSecurityOpt(container *container.Container, config *containertypes.Hos return nil } -func getBlkioReadIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - -func getBlkioWriteIOpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - -func getBlkioReadBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - -func getBlkioWriteBpsDevices(config *containertypes.HostConfig) ([]blkiodev.ThrottleDevice, error) { - return nil, nil -} - func (daemon *Daemon) getLayerInit() func(string) error { return nil } diff --git a/daemon/graphdriver/plugin.go b/daemon/graphdriver/plugin.go index f6852f0752..5d433e5196 100644 --- a/daemon/graphdriver/plugin.go +++ b/daemon/graphdriver/plugin.go @@ -2,22 +2,12 @@ package graphdriver import ( "fmt" - "io" "path/filepath" "github.com/docker/docker/pkg/plugingetter" "github.com/docker/docker/plugin/v2" ) -type pluginClient interface { - // Call calls the specified method with the specified arguments for the plugin. - Call(string, interface{}, interface{}) error - // Stream calls the specified method with the specified arguments for the plugin and returns the response IO stream - Stream(string, interface{}) (io.ReadCloser, error) - // SendFile calls the specified method, and passes through the IO stream - SendFile(string, io.Reader, interface{}) error -} - func lookupPlugin(name string, pg plugingetter.PluginGetter, config Options) (Driver, error) { if !config.ExperimentalEnabled { return nil, fmt.Errorf("graphdriver plugins are only supported with experimental mode") diff --git a/daemon/health.go b/daemon/health.go index e10fe87104..7d8c84a397 100644 --- a/daemon/health.go +++ b/daemon/health.go @@ -45,8 +45,7 @@ const ( const ( // Exit status codes that can be returned by the probe command. - exitStatusHealthy = 0 // Container is healthy - exitStatusUnhealthy = 1 // Container is unhealthy + exitStatusHealthy = 0 // Container is healthy ) // probe implementations know how to run a particular type of probe. diff --git a/daemon/metrics.go b/daemon/metrics.go index 0d9f37e8db..8cd363fb11 100644 --- a/daemon/metrics.go +++ b/daemon/metrics.go @@ -6,7 +6,7 @@ import ( "github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/plugingetter" - "github.com/docker/go-metrics" + metrics "github.com/docker/go-metrics" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" @@ -16,7 +16,6 @@ const metricsPluginType = "MetricsCollector" var ( containerActions metrics.LabeledTimer - containerStates metrics.LabeledGauge imageActions metrics.LabeledTimer networkActions metrics.LabeledTimer engineInfo metrics.LabeledGauge diff --git a/hack/dockerfile/install-binaries.sh b/hack/dockerfile/install-binaries.sh index abd436f411..0dc8f38f27 100755 --- a/hack/dockerfile/install-binaries.sh +++ b/hack/dockerfile/install-binaries.sh @@ -60,12 +60,7 @@ install_gometalinter() { cd "$GOPATH/src/github.com/alecthomas/gometalinter" git checkout -q "$GOMETALINTER_COMMIT" go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter - ( - export GOBIN=/usr/local/bin - export GOPATH="$PWD/_linters/" - go install github.com/golang/lint/golint - go install golang.org/x/tools/cmd/goimports - ) + GOBIN=/usr/local/bin gometalinter --install } for prog in "$@" diff --git a/hack/validate/gometalinter.json b/hack/validate/gometalinter.json index 6df7e6dc20..e4614b5e8e 100644 --- a/hack/validate/gometalinter.json +++ b/hack/validate/gometalinter.json @@ -10,6 +10,7 @@ ], "Enable": [ + "deadcode", "gofmt", "goimports", "golint", diff --git a/pkg/devicemapper/devmapper.go b/pkg/devicemapper/devmapper.go index 2254a6b530..6a0ac24647 100644 --- a/pkg/devicemapper/devmapper.go +++ b/pkg/devicemapper/devmapper.go @@ -14,6 +14,7 @@ import ( ) // Same as DM_DEVICE_* enum values from libdevmapper.h +// nolint: deadcode const ( deviceCreate TaskType = iota deviceReload diff --git a/pkg/plugins/pluginrpc-gen/fixtures/foo.go b/pkg/plugins/pluginrpc-gen/fixtures/foo.go index 5695dcc2d4..4dd1d6dd24 100644 --- a/pkg/plugins/pluginrpc-gen/fixtures/foo.go +++ b/pkg/plugins/pluginrpc-gen/fixtures/foo.go @@ -1,17 +1,11 @@ package foo import ( - "fmt" - aliasedio "io" "github.com/docker/docker/pkg/plugins/pluginrpc-gen/fixtures/otherfixture" ) -var ( - errFakeImport = fmt.Errorf("just to import fmt for imports tests") -) - type wobble struct { Some string Val string diff --git a/plugin/backend_linux.go b/plugin/backend_linux.go index e70dcdbb06..8a31e97e51 100644 --- a/plugin/backend_linux.go +++ b/plugin/backend_linux.go @@ -32,7 +32,7 @@ import ( "github.com/docker/docker/pkg/system" "github.com/docker/docker/plugin/v2" refstore "github.com/docker/docker/reference" - "github.com/opencontainers/go-digest" + digest "github.com/opencontainers/go-digest" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/net/context" @@ -652,22 +652,6 @@ func (pm *Manager) Remove(name string, config *types.PluginRmConfig) error { return nil } -func getMounts(root string) ([]string, error) { - infos, err := mount.GetMounts() - if err != nil { - return nil, errors.Wrap(err, "failed to read mount table") - } - - var mounts []string - for _, m := range infos { - if strings.HasPrefix(m.Mountpoint, root) { - mounts = append(mounts, m.Mountpoint) - } - } - - return mounts, nil -} - // Set sets plugin args func (pm *Manager) Set(name string, args []string) error { p, err := pm.config.Store.GetV2Plugin(name) diff --git a/volume/drivers/extpoint.go b/volume/drivers/extpoint.go index 9c65d899ea..ee42f2f5ed 100644 --- a/volume/drivers/extpoint.go +++ b/volume/drivers/extpoint.go @@ -32,6 +32,7 @@ func NewVolumeDriver(name string, baseHostPath string, c client) volume.Driver { // volumeDriver defines the available functions that volume plugins must implement. // This interface is only defined to generate the proxy objects. // It's not intended to be public or reused. +// nolint: deadcode type volumeDriver interface { // Create a volume with the given name Create(name string, opts map[string]string) (err error) diff --git a/volume/validate_test_unix.go b/volume/validate_unix_test.go similarity index 100% rename from volume/validate_test_unix.go rename to volume/validate_unix_test.go diff --git a/volume/validate_test_windows.go b/volume/validate_windows_test.go similarity index 100% rename from volume/validate_test_windows.go rename to volume/validate_windows_test.go diff --git a/volume/volume_unix.go b/volume/volume_unix.go index 5dde82147f..31555a691a 100644 --- a/volume/volume_unix.go +++ b/volume/volume_unix.go @@ -119,10 +119,6 @@ func validateNotRoot(p string) error { return nil } -func validateCopyMode(mode bool) error { - return nil -} - func convertSlash(p string) string { return p } diff --git a/volume/volume_windows.go b/volume/volume_windows.go index d792b385f8..5bee223702 100644 --- a/volume/volume_windows.go +++ b/volume/volume_windows.go @@ -183,13 +183,6 @@ func validateNotRoot(p string) error { return nil } -func validateCopyMode(mode bool) error { - if mode { - return fmt.Errorf("Windows does not support copying image path content") - } - return nil -} - func convertSlash(p string) string { return filepath.FromSlash(p) }