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

[20.10 backport] Dockerfile: update golangci-lint v1.44.0 #43975

Merged
merged 25 commits into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
34f6b94
gosec: G404: Use of weak random number generator
thaJeztah Apr 16, 2021
e738a57
daemon/logger/journald: fix linting errors
thaJeztah Apr 16, 2021
7573e32
client: S1031: unnecessary nil check around range (gosimple)
thaJeztah Apr 16, 2021
fadf8bb
staticcheck: SA4001: &*x will be simplified to x. It will not copy x
thaJeztah Apr 16, 2021
2ddf6e5
gosimple: S1039: unnecessary use of fmt.Sprintf
thaJeztah Apr 16, 2021
e8b838e
gosec: G601: Implicit memory aliasing in for loop
thaJeztah Apr 16, 2021
b6de0ca
G601: Implicit memory aliasing in for loop
thaJeztah Apr 16, 2021
db7b3f4
unused: ignore false positives
thaJeztah Apr 16, 2021
14b475d
daemon/stats: fix notRunningErr / notFoundErr detected as unused (fal…
thaJeztah Apr 16, 2021
2de90eb
pkg/archive: RebaseArchiveEntries(): ignore G110
thaJeztah Apr 16, 2021
9e88f84
daemon/splunk: ignore G402: TLS MinVersion too low for now
thaJeztah May 31, 2021
45fa675
if-return: redundant if ...; err != nil check (revive)
thaJeztah May 31, 2021
fa6954c
reformat "nolint" comments
thaJeztah May 31, 2021
2fb7c9f
daemon/config: error strings should not be capitalized
thaJeztah May 31, 2021
f2f387b
daemon: var-declaration: should omit type bool (revive)
thaJeztah May 31, 2021
ec3bfba
graphdriver: temporarily ignore unsafeptr: possible misuse of reflect…
thaJeztah May 31, 2021
d223f37
golangci.yml: update regex for ignoring SA1019
thaJeztah Apr 16, 2021
9820255
golangci.yml: skip some tests
thaJeztah Apr 16, 2021
ae3a933
golangci.yml: do not limit max reported issues
thaJeztah May 31, 2021
50361d9
registry: trimV1Address(): simplify trimming trailing slash
thaJeztah Oct 5, 2021
adeb29c
client/request.go:157:8: SA1019: err.Temporary is deprecated (staticc…
thaJeztah Jan 31, 2022
0523323
daemon/logger/awslogs: suppress false positive on hardcoded creds (go…
thaJeztah Jan 28, 2022
e6aee04
client.NewClientWithOpts(): remove redundant type assertion (gosimple)
thaJeztah Jan 31, 2022
d97fd53
integration-cli: SA5011: possible nil pointer dereference (staticcheck)
thaJeztah Jan 28, 2022
a7299ae
Dockerfile: update golangci-lint v1.44.0
thaJeztah Jan 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions builder/builder-next/adapters/snapshot/snapshot.go
Expand Up @@ -383,10 +383,7 @@ func (s *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
if err != nil {
return err
}
if err := b.Put(keyIsCommitted, []byte{}); err != nil {
return err
}
return nil
return b.Put(keyIsCommitted, []byte{})
})
}

Expand Down
2 changes: 1 addition & 1 deletion builder/builder-next/worker/gc_unix.go
Expand Up @@ -12,7 +12,7 @@ func detectDefaultGCCap(root string) int64 {
if err := syscall.Statfs(root, &st); err != nil {
return defaultCap
}
diskSize := int64(st.Bsize) * int64(st.Blocks) // nolint unconvert
diskSize := int64(st.Bsize) * int64(st.Blocks) //nolint unconvert
avail := diskSize / 10
return (avail/(1<<30) + 1) * 1e9 // round up
}
9 changes: 5 additions & 4 deletions builder/dockerfile/builder.go
Expand Up @@ -257,18 +257,19 @@ func (b *Builder) dispatchDockerfileWithCancellation(parseResult []instructions.
totalCommands += len(stage.Commands)
}
shlex := shell.NewLex(escapeToken)
for _, meta := range metaArgs {
currentCommandIndex = printCommand(b.Stdout, currentCommandIndex, totalCommands, &meta)
for i := range metaArgs {
currentCommandIndex = printCommand(b.Stdout, currentCommandIndex, totalCommands, &metaArgs[i])

err := processMetaArg(meta, shlex, buildArgs)
err := processMetaArg(metaArgs[i], shlex, buildArgs)
if err != nil {
return nil, err
}
}

stagesResults := newStagesBuildResults()

for _, stage := range parseResult {
for _, s := range parseResult {
stage := s
if err := stagesResults.checkStageNameAvailable(stage.Name); err != nil {
return nil, err
}
Expand Down
3 changes: 0 additions & 3 deletions client/client.go
Expand Up @@ -135,9 +135,6 @@ func NewClientWithOpts(ops ...Opt) (*Client, error) {
}
}

if _, ok := c.client.Transport.(http.RoundTripper); !ok {
return nil, fmt.Errorf("unable to verify TLS configuration, invalid transport %v", c.client.Transport)
}
if c.scheme == "" {
c.scheme = "http"

Expand Down
12 changes: 4 additions & 8 deletions client/request.go
Expand Up @@ -150,10 +150,8 @@ func (cli *Client) doRequest(ctx context.Context, req *http.Request) (serverResp
if err.Timeout() {
return serverResp, ErrorConnectionFailed(cli.host)
}
if !err.Temporary() {
if strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") {
return serverResp, ErrorConnectionFailed(cli.host)
}
if strings.Contains(err.Error(), "connection refused") || strings.Contains(err.Error(), "dial unix") {
return serverResp, ErrorConnectionFailed(cli.host)
}
}

Expand Down Expand Up @@ -242,10 +240,8 @@ func (cli *Client) addHeaders(req *http.Request, headers headers) *http.Request
req.Header.Set(k, v)
}

if headers != nil {
for k, v := range headers {
req.Header[k] = v
}
for k, v := range headers {
req.Header[k] = v
}
return req
}
Expand Down
1 change: 1 addition & 0 deletions daemon/cluster/executor/container/adapter.go
Expand Up @@ -431,6 +431,7 @@ func (c *containerAdapter) remove(ctx context.Context) error {
func (c *containerAdapter) createVolumes(ctx context.Context) error {
// Create plugin volumes that are embedded inside a Mount
for _, mount := range c.container.task.Spec.GetContainer().Mounts {
mount := mount
if mount.Type != api.MountTypeVolume {
continue
}
Expand Down
8 changes: 4 additions & 4 deletions daemon/config/config_unix.go
Expand Up @@ -75,22 +75,22 @@ func (conf *Config) IsSwarmCompatible() error {
}

func verifyDefaultIpcMode(mode string) error {
const hint = "Use \"shareable\" or \"private\"."
const hint = `use "shareable" or "private"`

dm := containertypes.IpcMode(mode)
if !dm.Valid() {
return fmt.Errorf("Default IPC mode setting (%v) is invalid. "+hint, dm)
return fmt.Errorf("default IPC mode setting (%v) is invalid; "+hint, dm)
}
if dm != "" && !dm.IsPrivate() && !dm.IsShareable() {
return fmt.Errorf("IPC mode \"%v\" is not supported as default value. "+hint, dm)
return fmt.Errorf(`IPC mode "%v" is not supported as default value; `+hint, dm)
}
return nil
}

func verifyDefaultCgroupNsMode(mode string) error {
cm := containertypes.CgroupnsMode(mode)
if !cm.Valid() {
return fmt.Errorf("Default cgroup namespace mode (%v) is invalid. Use \"host\" or \"private\".", cm) // nolint: golint
return fmt.Errorf(`default cgroup namespace mode (%v) is invalid; use "host" or "private"`, cm)
}

return nil
Expand Down
3 changes: 2 additions & 1 deletion daemon/container.go
Expand Up @@ -279,7 +279,8 @@ func validateHostConfig(hostConfig *containertypes.HostConfig, platform string)
}
// Validate mounts; check if host directories still exist
parser := volumemounts.NewParser(platform)
for _, cfg := range hostConfig.Mounts {
for _, c := range hostConfig.Mounts {
cfg := c
if err := parser.ValidateMountConfig(&cfg); err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions daemon/daemon_unix.go
Expand Up @@ -194,8 +194,8 @@ func getBlkioWeightDevices(config containertypes.Resources) ([]specs.LinuxWeight
weight := weightDevice.Weight
d := specs.LinuxWeightDevice{Weight: &weight}
// The type is 32bit on mips.
d.Major = int64(unix.Major(uint64(stat.Rdev))) // nolint: unconvert
d.Minor = int64(unix.Minor(uint64(stat.Rdev))) // nolint: unconvert
d.Major = int64(unix.Major(uint64(stat.Rdev))) //nolint: unconvert
d.Minor = int64(unix.Minor(uint64(stat.Rdev))) //nolint: unconvert
blkioWeightDevices = append(blkioWeightDevices, d)
}

Expand Down Expand Up @@ -266,8 +266,8 @@ func getBlkioThrottleDevices(devs []*blkiodev.ThrottleDevice) ([]specs.LinuxThro
}
d := specs.LinuxThrottleDevice{Rate: d.Rate}
// the type is 32bit on mips
d.Major = int64(unix.Major(uint64(stat.Rdev))) // nolint: unconvert
d.Minor = int64(unix.Minor(uint64(stat.Rdev))) // nolint: unconvert
d.Major = int64(unix.Major(uint64(stat.Rdev))) //nolint: unconvert
d.Minor = int64(unix.Minor(uint64(stat.Rdev))) //nolint: unconvert
throttleDevices = append(throttleDevices, d)
}

Expand Down
4 changes: 2 additions & 2 deletions daemon/graphdriver/copy/copy.go
Expand Up @@ -147,7 +147,7 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyOpaqueXattrs bool) error
switch mode := f.Mode(); {
case mode.IsRegular():
// the type is 32bit on mips
id := fileID{dev: uint64(stat.Dev), ino: stat.Ino} // nolint: unconvert
id := fileID{dev: uint64(stat.Dev), ino: stat.Ino} //nolint: unconvert
if copyMode == Hardlink {
isHardlink = true
if err2 := os.Link(srcPath, dstPath); err2 != nil {
Expand Down Expand Up @@ -230,7 +230,7 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyOpaqueXattrs bool) error
}

// system.Chtimes doesn't support a NOFOLLOW flag atm
// nolint: unconvert
//nolint: unconvert
if f.IsDir() {
dirsToSetMtimes.PushFront(&dirMtimeInfo{dstPath: &dstPath, stat: stat})
} else if !isSymlink {
Expand Down
4 changes: 2 additions & 2 deletions daemon/graphdriver/devmapper/deviceset.go
Expand Up @@ -1535,7 +1535,7 @@ func getDeviceMajorMinor(file *os.File) (uint64, uint64, error) {
}

// the type is 32bit on mips
dev := uint64(stat.Rdev) // nolint: unconvert
dev := uint64(stat.Rdev) //nolint: unconvert
majorNum := major(dev)
minorNum := minor(dev)

Expand Down Expand Up @@ -1747,7 +1747,7 @@ func (devices *DeviceSet) initDevmapper(doInit bool) (retErr error) {
// - The target of this device is at major <maj> and minor <min>
// - If <inode> is defined, use that file inside the device as a loopback image. Otherwise use the device itself.
// The type Dev in Stat_t is 32bit on mips.
devices.devicePrefix = fmt.Sprintf("docker-%d:%d-%d", major(uint64(st.Dev)), minor(uint64(st.Dev)), st.Ino) // nolint: unconvert
devices.devicePrefix = fmt.Sprintf("docker-%d:%d-%d", major(uint64(st.Dev)), minor(uint64(st.Dev)), st.Ino) //nolint: unconvert
logger.Debugf("Generated prefix: %s", devices.devicePrefix)

// Check for the existence of the thin-pool device
Expand Down
2 changes: 1 addition & 1 deletion daemon/graphdriver/devmapper/devmapper_test.go
Expand Up @@ -42,7 +42,7 @@ func initLoopbacks() error {
// only create new loopback files if they don't exist
if _, err := os.Stat(loopPath); err != nil {
if mkerr := syscall.Mknod(loopPath,
uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil { // nolint: unconvert
uint32(statT.Mode|syscall.S_IFBLK), int((7<<8)|(i&0xff)|((i&0xfff00)<<12))); mkerr != nil { //nolint: unconvert
return mkerr
}
os.Chown(loopPath, int(statT.Uid), int(statT.Gid))
Expand Down
4 changes: 2 additions & 2 deletions daemon/graphdriver/graphtest/graphtest_unix.go
Expand Up @@ -303,10 +303,10 @@ func writeRandomFile(path string, size uint64) error {
}

// Cast to []byte
header := *(*reflect.SliceHeader)(unsafe.Pointer(&buf))
header := *(*reflect.SliceHeader)(unsafe.Pointer(&buf)) //nolint:govet // FIXME: unsafeptr: possible misuse of reflect.SliceHeader (govet) see https://github.com/moby/moby/issues/42444
header.Len *= 8
header.Cap *= 8
data := *(*[]byte)(unsafe.Pointer(&header))
data := *(*[]byte)(unsafe.Pointer(&header)) //nolint:govet // FIXME: unsafeptr: possible misuse of reflect.SliceHeader (govet) see https://github.com/moby/moby/issues/42444

return ioutil.WriteFile(path, data, 0700)
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/list.go
Expand Up @@ -553,7 +553,7 @@ func includeContainerInList(container *container.Snapshot, ctx *listContext) ite

if len(ctx.expose) > 0 || len(ctx.publish) > 0 {
var (
shouldSkip bool = true
shouldSkip = true
publishedPort nat.Port
exposedPort nat.Port
)
Expand Down
4 changes: 2 additions & 2 deletions daemon/logger/awslogs/cloudwatchlogs.go
Expand Up @@ -38,7 +38,7 @@ const (
tagKey = "tag"
datetimeFormatKey = "awslogs-datetime-format"
multilinePatternKey = "awslogs-multiline-pattern"
credentialsEndpointKey = "awslogs-credentials-endpoint"
credentialsEndpointKey = "awslogs-credentials-endpoint" //nolint:gosec // G101: Potential hardcoded credentials
forceFlushIntervalKey = "awslogs-force-flush-interval-seconds"
maxBufferedEventsKey = "awslogs-max-buffered-events"

Expand All @@ -62,7 +62,7 @@ const (
invalidSequenceTokenCode = "InvalidSequenceTokenException"
resourceNotFoundCode = "ResourceNotFoundException"

credentialsEndpoint = "http://169.254.170.2"
credentialsEndpoint = "http://169.254.170.2" //nolint:gosec // G101: Potential hardcoded credentials

userAgentHeader = "User-Agent"
)
Expand Down
5 changes: 2 additions & 3 deletions daemon/logger/journald/read.go
Expand Up @@ -126,10 +126,10 @@ func (s *journald) Close() error {
return nil
}

// convert error code returned from a sd_journal_* function
// CErr converts error code returned from a sd_journal_* function
// (which returns -errno) to a string
func CErr(ret C.int) string {
return C.GoString(C.strerror(C.int(-ret)))
return C.GoString(C.strerror(-ret))
}

func (s *journald) drainJournal(logWatcher *logger.LogWatcher, j *C.sd_journal, oldCursor *C.char, untilUnixMicro uint64) (*C.char, bool, int) {
Expand Down Expand Up @@ -378,7 +378,6 @@ func (s *journald) readLogs(logWatcher *logger.LogWatcher, config logger.ReadCon
}

C.free(unsafe.Pointer(cursor))
return
}

func (s *journald) ReadLogs(config logger.ReadConfig) *logger.LogWatcher {
Expand Down
3 changes: 2 additions & 1 deletion daemon/logger/local/local_test.go
Expand Up @@ -211,7 +211,8 @@ func copyLogMessage(src *logger.Message) *logger.Message {
dst.Err = src.Err
dst.Line = append(dst.Line, src.Line...)
if src.PLogMetaData != nil {
dst.PLogMetaData = &(*src.PLogMetaData)
lmd := *src.PLogMetaData
dst.PLogMetaData = &lmd
}
return dst
}
3 changes: 2 additions & 1 deletion daemon/logger/splunk/splunk.go
Expand Up @@ -170,7 +170,8 @@ func New(info logger.Info) (logger.Logger, error) {
return nil, fmt.Errorf("%s: %s is expected", driverName, splunkTokenKey)
}

tlsConfig := &tls.Config{}
// FIXME set minimum TLS version for splunk (see https://github.com/moby/moby/issues/42443)
tlsConfig := &tls.Config{} //nolint: gosec // G402: TLS MinVersion too low.

// Splunk is using autogenerated certificates by default,
// allow users to trust them with skipping verification
Expand Down
10 changes: 5 additions & 5 deletions daemon/network.go
Expand Up @@ -155,7 +155,7 @@ var (
func (daemon *Daemon) startIngressWorker() {
ingressJobsChannel = make(chan *ingressJob, 100)
go func() {
// nolint: gosimple
//nolint: gosimple
for {
select {
case r := <-ingressJobsChannel:
Expand Down Expand Up @@ -365,7 +365,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
n, err := c.NewNetwork(driver, create.Name, id, nwOptions...)
if err != nil {
if _, ok := err.(libnetwork.ErrDataStoreNotInitialized); ok {
// nolint: golint
//nolint: golint
return nil, errors.New("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.")
}
return nil, err
Expand Down Expand Up @@ -573,9 +573,9 @@ func (daemon *Daemon) GetNetworks(filter filters.Args, config types.NetworkListC
}

if config.Detailed {
for i, n := range list {
np := &n
buildDetailedNetworkResources(np, idx[n.ID], config.Verbose)
for i := range list {
np := &list[i]
buildDetailedNetworkResources(np, idx[np.ID], config.Verbose)
list[i] = *np
}
}
Expand Down
13 changes: 2 additions & 11 deletions daemon/stats/collector.go
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/docker/docker/api/types"
"github.com/docker/docker/container"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/pkg/pubsub"
"github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -131,7 +132,7 @@ func (s *Collector) Run() {

pair.publisher.Publish(*stats)

case notRunningErr, notFoundErr:
case errdefs.ErrConflict, errdefs.ErrNotFound:
// publish empty stats containing only name and ID if not running or not found
pair.publisher.Publish(types.StatsJSON{
Name: pair.container.Name,
Expand All @@ -150,13 +151,3 @@ func (s *Collector) Run() {
time.Sleep(s.interval)
}
}

type notRunningErr interface {
error
Conflict()
}

type notFoundErr interface {
error
NotFound()
}
2 changes: 1 addition & 1 deletion daemon/top_unix.go
Expand Up @@ -21,7 +21,7 @@ func validatePSArgs(psArgs string) error {
// NOTE: \\s does not detect unicode whitespaces.
// So we use fieldsASCII instead of strings.Fields in parsePSOutput.
// See https://github.com/docker/docker/pull/24358
// nolint: gosimple
//nolint: gosimple
re := regexp.MustCompile("\\s+([^\\s]*)=\\s*(PID[^\\s]*)")
for _, group := range re.FindAllStringSubmatch(psArgs, -1) {
if len(group) >= 3 {
Expand Down
4 changes: 3 additions & 1 deletion daemon/volumes_unix_test.go
Expand Up @@ -97,6 +97,8 @@ func TestBackportMountSpec(t *testing.T) {
return string(b)
}

mpc := *c.MountPoints["/jambolan"]

for _, x := range []expected{
{
mp: &volumemounts.MountPoint{
Expand Down Expand Up @@ -226,7 +228,7 @@ func TestBackportMountSpec(t *testing.T) {
comment: "partially configured named volume caused by #32613",
},
{
mp: &(*c.MountPoints["/jambolan"]), // copy the mountpoint, expect no changes
mp: &mpc,
comment: "volume defined in mounts API",
},
{
Expand Down
3 changes: 2 additions & 1 deletion distribution/push_v2.go
Expand Up @@ -330,7 +330,8 @@ func (pd *v2PushDescriptor) Upload(ctx context.Context, progressOutput progress.
// Attempt to find another repository in the same registry to mount the layer from to avoid an unnecessary upload
candidates := getRepositoryMountCandidates(pd.repoInfo, pd.hmacKey, maxMountAttempts, v2Metadata)
isUnauthorizedError := false
for _, mountCandidate := range candidates {
for _, mc := range candidates {
mountCandidate := mc
logrus.Debugf("attempting to mount layer %s (%s) from %s", diffID, mountCandidate.Digest, mountCandidate.SourceRepository)
createOpts := []distribution.BlobCreateOption{}

Expand Down
2 changes: 1 addition & 1 deletion hack/dockerfile/install/golangci_lint.installer
@@ -1,6 +1,6 @@
#!/bin/sh

: "${GOLANGCI_LINT_VERSION=v1.23.8}"
: "${GOLANGCI_LINT_VERSION=v1.44.0}"

install_golangci_lint() {
set -e
Expand Down