From 270e8cf64dee586240968900fb1cf8e36ed641a5 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 2 Nov 2015 08:02:25 -0800 Subject: [PATCH 1/3] Fix golint warnings Signed-off-by: Alexander Morozov --- graph/history.go | 9 ++++----- pkg/devicemapper/devmapper_wrapper_deferred_remove.go | 2 +- pkg/mflag/flag.go | 2 +- pkg/stringid/stringid.go | 2 +- pkg/tarsum/tarsum.go | 2 +- pkg/tlsconfig/config.go | 5 +++-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/graph/history.go b/graph/history.go index e0f3627a35..1b5de32f06 100644 --- a/graph/history.go +++ b/graph/history.go @@ -44,10 +44,9 @@ func (graph *Graph) depth(img *image.Image) (int, error) { return count, nil } -// Set the max depth to the aufs default that most -// kernels are compiled with +// Set the max depth to the aufs default that most kernels are compiled with. // For more information see: http://sourceforge.net/p/aufs/aufs3-standalone/ci/aufs3.12/tree/config.mk -const MaxImageDepth = 127 +const maxImageDepth = 127 // CheckDepth returns an error if the depth of an image, as returned // by ImageDepth, is too large to support creating a container from it @@ -59,8 +58,8 @@ func (graph *Graph) CheckDepth(img *image.Image) error { if err != nil { return err } - if depth+2 >= MaxImageDepth { - return fmt.Errorf("Cannot create container with more than %d parents", MaxImageDepth) + if depth+2 >= maxImageDepth { + return fmt.Errorf("Cannot create container with more than %d parents", maxImageDepth) } return nil } diff --git a/pkg/devicemapper/devmapper_wrapper_deferred_remove.go b/pkg/devicemapper/devmapper_wrapper_deferred_remove.go index 40ab199e4b..dc361eab76 100644 --- a/pkg/devicemapper/devmapper_wrapper_deferred_remove.go +++ b/pkg/devicemapper/devmapper_wrapper_deferred_remove.go @@ -8,7 +8,7 @@ package devicemapper */ import "C" -// LibraryDeferredRemovalsupport is supported when statically linked. +// LibraryDeferredRemovalSupport is supported when statically linked. const LibraryDeferredRemovalSupport = true func dmTaskDeferredRemoveFct(task *cdmTask) int { diff --git a/pkg/mflag/flag.go b/pkg/mflag/flag.go index afab4c9c60..6a113b9f62 100644 --- a/pkg/mflag/flag.go +++ b/pkg/mflag/flag.go @@ -589,7 +589,7 @@ var Usage = func() { PrintDefaults() } -// Usage prints to standard error a usage message documenting the standard command layout +// ShortUsage prints to standard error a usage message documenting the standard command layout // The function is a variable that may be changed to point to a custom function. var ShortUsage = func() { fmt.Fprintf(CommandLine.output, "Usage of %s:\n", os.Args[0]) diff --git a/pkg/stringid/stringid.go b/pkg/stringid/stringid.go index ab1f9d4749..266a74ba6d 100644 --- a/pkg/stringid/stringid.go +++ b/pkg/stringid/stringid.go @@ -34,7 +34,7 @@ func TruncateID(id string) string { func generateID(crypto bool) string { b := make([]byte, 32) - var r io.Reader = random.Reader + r := random.Reader if crypto { r = rand.Reader } diff --git a/pkg/tarsum/tarsum.go b/pkg/tarsum/tarsum.go index d2df58c7f3..0f5783be1b 100644 --- a/pkg/tarsum/tarsum.go +++ b/pkg/tarsum/tarsum.go @@ -146,7 +146,7 @@ var ( } ) -// TarSum default is "sha256" +// DefaultTHash is default TarSum hashing algoritm - "sha256". var DefaultTHash = NewTHash("sha256", sha256.New) type simpleTHash struct { diff --git a/pkg/tlsconfig/config.go b/pkg/tlsconfig/config.go index 9f7f336947..e3dfad1f0e 100644 --- a/pkg/tlsconfig/config.go +++ b/pkg/tlsconfig/config.go @@ -47,8 +47,9 @@ var clientCipherSuites = []uint16{ tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, } -// For use by code which already has a crypto/tls options struct but wants to -// use a commonly accepted set of TLS cipher suites, with known weak algorithms removed +// DefaultServerAcceptedCiphers should be uses by code which already has a crypto/tls +// options struct but wants to use a commonly accepted set of TLS cipher suites, with +// known weak algorithms removed. var DefaultServerAcceptedCiphers = append(clientCipherSuites, acceptedCBCCiphers...) // ServerDefault is a secure-enough TLS configuration for the server TLS configuration. From 7aa28b6bdd86b0ad8ca119fb8fc2f864f219a0dd Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 2 Nov 2015 08:28:34 -0800 Subject: [PATCH 2/3] Fix go vet warnings Signed-off-by: Alexander Morozov --- api/server/router/local/image.go | 9 +++++++-- daemon/create.go | 10 +++++----- daemon/inspect.go | 24 +++++++++++++++++------- daemon/inspect_unix.go | 26 ++++++++++++++++---------- graph/pull_v1.go | 2 +- pkg/archive/changes.go | 23 +++++++++++++---------- registry/registry.go | 12 ++++++------ 7 files changed, 65 insertions(+), 41 deletions(-) diff --git a/api/server/router/local/image.go b/api/server/router/local/image.go index 0bf58f310e..0826ee1e2f 100644 --- a/api/server/router/local/image.go +++ b/api/server/router/local/image.go @@ -386,9 +386,14 @@ func (s *router) postBuild(ctx context.Context, w http.ResponseWriter, r *http.R UIDMaps: uidMaps, GIDMaps: gidMaps, } - docker := daemonbuilder.Docker{s.daemon, output, authConfigs, defaultArchiver} + docker := &daemonbuilder.Docker{ + Daemon: s.daemon, + OutOld: output, + AuthConfigs: authConfigs, + Archiver: defaultArchiver, + } - b, err := dockerfile.NewBuilder(buildConfig, docker, builder.DockerIgnoreContext{context}, nil) + b, err := dockerfile.NewBuilder(buildConfig, docker, builder.DockerIgnoreContext{ModifiableContext: context}, nil) if err != nil { return errf(err) } diff --git a/daemon/create.go b/daemon/create.go index 61c60cfc93..d9aa3b29a9 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -31,7 +31,7 @@ func (daemon *Daemon) ContainerCreate(params *ContainerCreateConfig) (types.Cont warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config) if err != nil { - return types.ContainerCreateResponse{"", warnings}, err + return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err } daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares) @@ -40,18 +40,18 @@ func (daemon *Daemon) ContainerCreate(params *ContainerCreateConfig) (types.Cont if err != nil { if daemon.Graph().IsNotExist(err, params.Config.Image) { if strings.Contains(params.Config.Image, "@") { - return types.ContainerCreateResponse{"", warnings}, derr.ErrorCodeNoSuchImageHash.WithArgs(params.Config.Image) + return types.ContainerCreateResponse{ID: "", Warnings: warnings}, derr.ErrorCodeNoSuchImageHash.WithArgs(params.Config.Image) } img, tag := parsers.ParseRepositoryTag(params.Config.Image) if tag == "" { tag = tags.DefaultTag } - return types.ContainerCreateResponse{"", warnings}, derr.ErrorCodeNoSuchImageTag.WithArgs(img, tag) + return types.ContainerCreateResponse{ID: "", Warnings: warnings}, derr.ErrorCodeNoSuchImageTag.WithArgs(img, tag) } - return types.ContainerCreateResponse{"", warnings}, err + return types.ContainerCreateResponse{ID: "", Warnings: warnings}, err } - return types.ContainerCreateResponse{container.ID, warnings}, nil + return types.ContainerCreateResponse{ID: container.ID, Warnings: warnings}, nil } // Create creates a new container from the given configuration with a given name. diff --git a/daemon/inspect.go b/daemon/inspect.go index 86eba4da7a..1268bc0168 100644 --- a/daemon/inspect.go +++ b/daemon/inspect.go @@ -43,7 +43,12 @@ func (daemon *Daemon) ContainerInspect(name string, size bool) (*types.Container Networks: container.NetworkSettings.Networks, } - return &types.ContainerJSON{base, mountPoints, container.Config, networkSettings}, nil + return &types.ContainerJSON{ + ContainerJSONBase: base, + Mounts: mountPoints, + Config: container.Config, + NetworkSettings: networkSettings, + }, nil } // ContainerInspect120 serializes the master version of a container into a json type. @@ -63,15 +68,20 @@ func (daemon *Daemon) ContainerInspect120(name string) (*v1p20.ContainerJSON, er mountPoints := addMountPoints(container) config := &v1p20.ContainerConfig{ - container.Config, - container.Config.MacAddress, - container.Config.NetworkDisabled, - container.Config.ExposedPorts, - container.hostConfig.VolumeDriver, + Config: container.Config, + MacAddress: container.Config.MacAddress, + NetworkDisabled: container.Config.NetworkDisabled, + ExposedPorts: container.Config.ExposedPorts, + VolumeDriver: container.hostConfig.VolumeDriver, } networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings) - return &v1p20.ContainerJSON{base, mountPoints, config, networkSettings}, nil + return &v1p20.ContainerJSON{ + ContainerJSONBase: base, + Mounts: mountPoints, + Config: config, + NetworkSettings: networkSettings, + }, nil } func (daemon *Daemon) getInspectData(container *Container, size bool) (*types.ContainerJSONBase, error) { diff --git a/daemon/inspect_unix.go b/daemon/inspect_unix.go index 92c967a3af..d445660ff9 100644 --- a/daemon/inspect_unix.go +++ b/daemon/inspect_unix.go @@ -40,19 +40,25 @@ func (daemon *Daemon) ContainerInspectPre120(name string) (*v1p19.ContainerJSON, } config := &v1p19.ContainerConfig{ - container.Config, - container.Config.MacAddress, - container.Config.NetworkDisabled, - container.Config.ExposedPorts, - container.hostConfig.VolumeDriver, - container.hostConfig.Memory, - container.hostConfig.MemorySwap, - container.hostConfig.CPUShares, - container.hostConfig.CpusetCpus, + Config: container.Config, + MacAddress: container.Config.MacAddress, + NetworkDisabled: container.Config.NetworkDisabled, + ExposedPorts: container.Config.ExposedPorts, + VolumeDriver: container.hostConfig.VolumeDriver, + Memory: container.hostConfig.Memory, + MemorySwap: container.hostConfig.MemorySwap, + CPUShares: container.hostConfig.CPUShares, + CPUSet: container.hostConfig.CpusetCpus, } networkSettings := daemon.getBackwardsCompatibleNetworkSettings(container.NetworkSettings) - return &v1p19.ContainerJSON{base, volumes, volumesRW, config, networkSettings}, nil + return &v1p19.ContainerJSON{ + ContainerJSONBase: base, + Volumes: volumes, + VolumesRW: volumesRW, + Config: config, + NetworkSettings: networkSettings, + }, nil } func addMountPoints(container *Container) []types.MountPoint { diff --git a/graph/pull_v1.go b/graph/pull_v1.go index 754b041db1..51150dbee9 100644 --- a/graph/pull_v1.go +++ b/graph/pull_v1.go @@ -31,7 +31,7 @@ type v1Puller struct { func (p *v1Puller) Pull(tag string) (fallback bool, err error) { if utils.DigestReference(tag) { // Allowing fallback, because HTTPS v1 is before HTTP v2 - return true, registry.ErrNoSupport{errors.New("Cannot pull by digest with v1 registry")} + return true, registry.ErrNoSupport{Err: errors.New("Cannot pull by digest with v1 registry")} } tlsConfig, err := p.registryService.TLSConfig(p.repoInfo.Index.Name) diff --git a/pkg/archive/changes.go b/pkg/archive/changes.go index 49593eff45..e0bd4c461e 100644 --- a/pkg/archive/changes.go +++ b/pkg/archive/changes.go @@ -31,6 +31,18 @@ const ( ChangeDelete ) +func (c ChangeType) String() string { + switch c { + case ChangeModify: + return "C" + case ChangeAdd: + return "A" + case ChangeDelete: + return "D" + } + return "" +} + // Change represents a change, it wraps the change type and path. // It describes changes of the files in the path respect to the // parent layers. The change could be modify, add, delete. @@ -41,16 +53,7 @@ type Change struct { } func (change *Change) String() string { - var kind string - switch change.Kind { - case ChangeModify: - kind = "C" - case ChangeAdd: - kind = "A" - case ChangeDelete: - kind = "D" - } - return fmt.Sprintf("%s %s", kind, change.Path) + return fmt.Sprintf("%s %s", change.Kind, change.Path) } // for sort.Sort diff --git a/registry/registry.go b/registry/registry.go index 389bd959df..bd5251e1a3 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -39,14 +39,14 @@ var dockerUserAgent string func init() { httpVersion := make([]useragent.VersionInfo, 0, 6) - httpVersion = append(httpVersion, useragent.VersionInfo{"docker", dockerversion.VERSION}) - httpVersion = append(httpVersion, useragent.VersionInfo{"go", runtime.Version()}) - httpVersion = append(httpVersion, useragent.VersionInfo{"git-commit", dockerversion.GITCOMMIT}) + httpVersion = append(httpVersion, useragent.VersionInfo{Name: "docker", Version: dockerversion.VERSION}) + httpVersion = append(httpVersion, useragent.VersionInfo{Name: "go", Version: runtime.Version()}) + httpVersion = append(httpVersion, useragent.VersionInfo{Name: "git-commit", Version: dockerversion.GITCOMMIT}) if kernelVersion, err := kernel.GetKernelVersion(); err == nil { - httpVersion = append(httpVersion, useragent.VersionInfo{"kernel", kernelVersion.String()}) + httpVersion = append(httpVersion, useragent.VersionInfo{Name: "kernel", Version: kernelVersion.String()}) } - httpVersion = append(httpVersion, useragent.VersionInfo{"os", runtime.GOOS}) - httpVersion = append(httpVersion, useragent.VersionInfo{"arch", runtime.GOARCH}) + httpVersion = append(httpVersion, useragent.VersionInfo{Name: "os", Version: runtime.GOOS}) + httpVersion = append(httpVersion, useragent.VersionInfo{Name: "arch", Version: runtime.GOARCH}) dockerUserAgent = useragent.AppendVersions("", httpVersion...) From c70d1bde63a1370d86ea8af17cda17920fdc9fb7 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Mon, 2 Nov 2015 08:32:49 -0800 Subject: [PATCH 3/3] Update linting tools Signed-off-by: Alexander Morozov --- Dockerfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4c6825c966..2584d771ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -102,8 +102,7 @@ ENV GOARM 5 # ENV GOFMT_VERSION 1.3.3 # RUN curl -sSL https://storage.googleapis.com/golang/go${GOFMT_VERSION}.$(go env GOOS)-$(go env GOARCH).tar.gz | tar -C /go/bin -xz --strip-components=2 go/bin/gofmt -# Update this sha when we upgrade to go 1.5.0 -ENV GO_TOOLS_COMMIT 069d2f3bcb68257b627205f0486d6cc69a231ff9 +ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3 # Grab Go's cover tool for dead-simple code coverage testing # Grab Go's vet tool for examining go code to find suspicious constructs # and help prevent errors that the compiler might not catch @@ -112,7 +111,7 @@ RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \ && go install -v golang.org/x/tools/cmd/cover \ && go install -v golang.org/x/tools/cmd/vet # Grab Go's lint tool -ENV GO_LINT_COMMIT f42f5c1c440621302702cb0741e9d2ca547ae80f +ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456 RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \ && (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \ && go install -v github.com/golang/lint/golint