diff --git a/Dockerfile.build b/Dockerfile.build index 2f820ef4..2098a43f 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -6,4 +6,5 @@ RUN go get github.com/tools/godep \ golang.org/x/tools/cmd/cover \ github.com/mattn/goveralls \ github.com/gordonklaus/ineffassign \ - github.com/client9/misspell/cmd/misspell + github.com/client9/misspell/cmd/misspell \ + honnef.co/go/tools/cmd/gosimple diff --git a/Makefile b/Makefile index df3a619b..7e8af377 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: all all-local build build-local clean cross cross-local vet lint misspell check check-code check-format run-tests integration-tests check-local coveralls circle-ci-cross circle-ci-build circle-ci-check circle-ci +.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-code check-format run-tests integration-tests check-local coveralls circle-ci-cross circle-ci-build circle-ci-check circle-ci SHELL=/bin/bash build_image=libnetworkbuild dockerargs = --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork @@ -64,7 +64,7 @@ cross-local: check: ${build_image}.created @${docker} ./wrapmake.sh check-local -check-code: lint vet ineffassign +check-code: lint gosimple vet ineffassign check-format: fmt misspell @@ -153,6 +153,10 @@ ineffassign: ## run ineffassign @echo "🐳 $@" @test -z "$$(ineffassign . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)" +gosimple: ## run gosimple + @echo "🐳 $@" + @test -z "$$(gosimple . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)" + # CircleCI's Docker fails when cleaning up using the --rm flag # The following targets are a workaround for this circle-ci-cross: ${build_image}.created diff --git a/agent.go b/agent.go index a45a5695..b93ca288 100644 --- a/agent.go +++ b/agent.go @@ -383,15 +383,11 @@ func (c *controller) agentClose() { agent.Lock() for _, cancelFuncs := range agent.driverCancelFuncs { - for _, cancel := range cancelFuncs { - cancelList = append(cancelList, cancel) - } + cancelList = append(cancelList, cancelFuncs...) } // Add also the cancel functions for the network db - for _, cancel := range agent.coreCancelFuncs { - cancelList = append(cancelList, cancel) - } + cancelList = append(cancelList, agent.coreCancelFuncs...) agent.Unlock() for _, cancel := range cancelList { diff --git a/endpoint_info.go b/endpoint_info.go index 202c27b3..17e93b97 100644 --- a/endpoint_info.go +++ b/endpoint_info.go @@ -154,9 +154,7 @@ func (epi *endpointInterface) CopyTo(dstEpi *endpointInterface) error { dstEpi.v6PoolID = epi.v6PoolID if len(epi.llAddrs) != 0 { dstEpi.llAddrs = make([]*net.IPNet, 0, len(epi.llAddrs)) - for _, ll := range epi.llAddrs { - dstEpi.llAddrs = append(dstEpi.llAddrs, ll) - } + dstEpi.llAddrs = append(dstEpi.llAddrs, epi.llAddrs...) } for _, route := range epi.routes { diff --git a/libnetwork_linux_test.go b/libnetwork_linux_test.go index db1eee1c..679b004f 100644 --- a/libnetwork_linux_test.go +++ b/libnetwork_linux_test.go @@ -903,9 +903,7 @@ func runParallelTests(t *testing.T, thrNumber int) { } if thrNumber != first { - select { - case <-start: - } + <-start thrdone := make(chan struct{}) done <- thrdone @@ -972,9 +970,7 @@ func runParallelTests(t *testing.T, thrNumber int) { } if thrNumber == first { for thrdone := range done { - select { - case <-thrdone: - } + <-thrdone } testns.Close() diff --git a/libnetwork_test.go b/libnetwork_test.go index c9c645f1..1b3fa431 100644 --- a/libnetwork_test.go +++ b/libnetwork_test.go @@ -64,11 +64,7 @@ func createController() error { return err } controller, err = libnetwork.New(append(cfgOptions, config.OptionDriverConfig(bridgeNetType, genericOption))...) - if err != nil { - return err - } - - return nil + return err } func createTestNetwork(networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) { diff --git a/network.go b/network.go index 9f99064e..72deeea6 100644 --- a/network.go +++ b/network.go @@ -434,15 +434,11 @@ func (n *network) applyConfigurationTo(to *network) error { } if len(n.ipamV4Config) > 0 { to.ipamV4Config = make([]*IpamConf, 0, len(n.ipamV4Config)) - for _, v4conf := range n.ipamV4Config { - to.ipamV4Config = append(to.ipamV4Config, v4conf) - } + to.ipamV4Config = append(to.ipamV4Config, n.ipamV4Config...) } if len(n.ipamV6Config) > 0 { to.ipamV6Config = make([]*IpamConf, 0, len(n.ipamV6Config)) - for _, v6conf := range n.ipamV6Config { - to.ipamV6Config = append(to.ipamV6Config, v6conf) - } + to.ipamV6Config = append(to.ipamV6Config, n.ipamV6Config...) } if len(n.generic) > 0 { to.generic = options.Generic{} @@ -873,8 +869,7 @@ func (n *network) resolveDriver(name string, load bool) (driverapi.Driver, *driv d, cap := c.drvRegistry.Driver(name) if d == nil { if load { - var err error - err = c.loadDriver(name) + err := c.loadDriver(name) if err != nil { return nil, nil, err } @@ -1451,11 +1446,7 @@ func (n *network) ipamAllocate() error { } err = n.ipamAllocateVersion(6, ipam) - if err != nil { - return err - } - - return nil + return err } func (n *network) requestPoolHelper(ipam ipamapi.Ipam, addressSpace, preferredPool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) { @@ -1654,9 +1645,7 @@ func (n *network) getIPInfo(ipVer int) []*IpamInfo { } l := make([]*IpamInfo, 0, len(info)) n.Lock() - for _, d := range info { - l = append(l, d) - } + l = append(l, info...) n.Unlock() return l } @@ -1870,7 +1859,7 @@ func (n *network) ResolveName(req string, ipType int) ([]net.IP, bool) { // the docker network domain. If the network is not v6 enabled // set ipv6Miss to filter the DNS query from going to external // resolvers. - if ok && n.enableIPv6 == false { + if ok && !n.enableIPv6 { ipv6Miss = true } ipSet, ok = sr.svcIPv6Map.Get(req) diff --git a/resolver.go b/resolver.go index cc769262..ff472d00 100644 --- a/resolver.go +++ b/resolver.go @@ -446,7 +446,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) { defer co.Close() // limits the number of outstanding concurrent queries. - if r.forwardQueryStart() == false { + if !r.forwardQueryStart() { old := r.tStamp r.tStamp = time.Now() if r.tStamp.Sub(old) > logInterval { diff --git a/sandbox.go b/sandbox.go index 9454c5c2..46674067 100644 --- a/sandbox.go +++ b/sandbox.go @@ -621,7 +621,7 @@ func (sb *sandbox) resolveName(req string, networkName string, epList []*endpoin func (sb *sandbox) SetKey(basePath string) error { start := time.Now() defer func() { - logrus.Debugf("sandbox set key processing took %s for container %s", time.Now().Sub(start), sb.ContainerID()) + logrus.Debugf("sandbox set key processing took %s for container %s", time.Since(start), sb.ContainerID()) }() if basePath == "" { @@ -773,9 +773,7 @@ func (sb *sandbox) restoreOslSandbox() error { } Ifaces[fmt.Sprintf("%s+%s", i.srcName, i.dstPrefix)] = ifaceOptions if joinInfo != nil { - for _, r := range joinInfo.StaticRoutes { - routes = append(routes, r) - } + routes = append(routes, joinInfo.StaticRoutes...) } if ep.needResolver() { sb.startResolver(true) @@ -789,11 +787,7 @@ func (sb *sandbox) restoreOslSandbox() error { // restore osl sandbox err := sb.osSbox.Restore(Ifaces, routes, gwep.joinInfo.gw, gwep.joinInfo.gw6) - if err != nil { - return err - } - - return nil + return err } func (sb *sandbox) populateNetworkResources(ep *endpoint) error { @@ -958,9 +952,7 @@ func (sb *sandbox) joinLeaveStart() { joinLeaveDone := sb.joinLeaveDone sb.Unlock() - select { - case <-joinLeaveDone: - } + <-joinLeaveDone sb.Lock() } diff --git a/sandbox_externalkey_unix.go b/sandbox_externalkey_unix.go index 4a7ac06b..c33398f9 100644 --- a/sandbox_externalkey_unix.go +++ b/sandbox_externalkey_unix.go @@ -52,7 +52,6 @@ func processSetKeyReexec() { controllerID := os.Args[2] err = SetExternalKey(controllerID, containerID, fmt.Sprintf("/proc/%d/ns/net", state.Pid)) - return } // SetExternalKey provides a convenient way to set an External key to a sandbox diff --git a/sandbox_store.go b/sandbox_store.go index 38b2bd7e..b92a544d 100644 --- a/sandbox_store.go +++ b/sandbox_store.go @@ -115,9 +115,7 @@ func (sbs *sbState) CopyTo(o datastore.KVObject) error { dstSbs.dbExists = sbs.dbExists dstSbs.EpPriority = sbs.EpPriority - for _, eps := range sbs.Eps { - dstSbs.Eps = append(dstSbs.Eps, eps) - } + dstSbs.Eps = append(dstSbs.Eps, sbs.Eps...) if len(sbs.ExtDNS2) > 0 { for _, dns := range sbs.ExtDNS2 {