From c17daf2b09402ec02910fa2f63a5dda64b97fcbb Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 14 Aug 2024 13:14:02 +0200 Subject: [PATCH] update golangci-lint to 1.60.1 Fixes new spotted issues around printf() formats and using os.Setenv() in tests. Signed-off-by: Paul Holzinger --- Makefile | 2 +- cmd/podman/containers/create.go | 2 +- libpod/container_top_linux.go | 2 +- pkg/annotations/validate.go | 3 ++- pkg/autoupdate/autoupdate.go | 2 +- pkg/machine/ignition/ignition.go | 2 +- pkg/specgen/generate/config_linux.go | 2 +- pkg/specgen/generate/pod_create.go | 2 +- pkg/systemd/activation_test.go | 10 +++++----- pkg/systemd/quadlet/quadlet.go | 4 ++-- 10 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 84d2b0bcb4..bf61d5b6f8 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ BUILDTAGS += ${EXTRA_BUILDTAGS} # N/B: This value is managed by Renovate, manual changes are # possible, as long as they don't disturb the formatting # (i.e. DO NOT ADD A 'v' prefix!) -GOLANGCI_LINT_VERSION := 1.59.1 +GOLANGCI_LINT_VERSION := 1.60.1 PYTHON ?= $(shell command -v python3 python|head -n1) PKG_MANAGER ?= $(shell command -v dnf yum|head -n1) # ~/.local/bin is not in PATH on all systems diff --git a/cmd/podman/containers/create.go b/cmd/podman/containers/create.go index 5edeb2afac..15e714b342 100644 --- a/cmd/podman/containers/create.go +++ b/cmd/podman/containers/create.go @@ -314,7 +314,7 @@ func CreateInit(c *cobra.Command, vals entities.ContainerCreateOptions, isInfra vals.ShmSizeSystemd = c.Flag("shm-size-systemd").Value.String() } if (c.Flag("dns").Changed || c.Flag("dns-option").Changed || c.Flag("dns-search").Changed) && vals.Net != nil && (vals.Net.Network.NSMode == specgen.NoNetwork || vals.Net.Network.IsContainer()) { - return vals, fmt.Errorf("conflicting options: dns and the network mode: " + string(vals.Net.Network.NSMode)) + return vals, errors.New("conflicting options: dns and the network mode: " + string(vals.Net.Network.NSMode)) } noHosts, err := c.Flags().GetBool("no-hosts") if err != nil { diff --git a/libpod/container_top_linux.go b/libpod/container_top_linux.go index 0b85a5a705..bc8ed2511b 100644 --- a/libpod/container_top_linux.go +++ b/libpod/container_top_linux.go @@ -411,7 +411,7 @@ func (c *Container) execPSinContainer(args []string) ([]string, error) { if logrus.GetLevel() >= logrus.DebugLevel { // If we're running in debug mode or higher, we might want to have a // look at stderr which includes debug logs from conmon. - logrus.Debugf(errBuf.String()) + logrus.Debug(errBuf.String()) } if err := <-outErrChan; err != nil { diff --git a/pkg/annotations/validate.go b/pkg/annotations/validate.go index 4ddeea30ed..1e9c3bf866 100644 --- a/pkg/annotations/validate.go +++ b/pkg/annotations/validate.go @@ -1,6 +1,7 @@ package annotations import ( + "errors" "fmt" "regexp" "strings" @@ -41,7 +42,7 @@ func isDNS1123Subdomain(value string) error { } if !dns1123SubdomainRegexp.MatchString(value) { - return fmt.Errorf(regexErrorMsg(dns1123SubdomainErrorMsg, dns1123SubdomainFmt, "example.com")) + return errors.New(regexErrorMsg(dns1123SubdomainErrorMsg, dns1123SubdomainFmt, "example.com")) } return nil diff --git a/pkg/autoupdate/autoupdate.go b/pkg/autoupdate/autoupdate.go index df6627e378..f82090399f 100644 --- a/pkg/autoupdate/autoupdate.go +++ b/pkg/autoupdate/autoupdate.go @@ -131,7 +131,7 @@ func AutoUpdate(ctx context.Context, runtime *libpod.Runtime, options entities.A // Connect to DBUS. conn, err := systemd.ConnectToDBUS() if err != nil { - logrus.Errorf(err.Error()) + logrus.Error(err.Error()) allErrors = append(allErrors, err) return nil, allErrors } diff --git a/pkg/machine/ignition/ignition.go b/pkg/machine/ignition/ignition.go index 58e7b622f1..62bf7a872f 100644 --- a/pkg/machine/ignition/ignition.go +++ b/pkg/machine/ignition/ignition.go @@ -303,7 +303,7 @@ func getFiles(usrName string, uid int, rootful bool, vmtype define.VMType, _ boo lingerExample.Add("Service", "ExecStart", "/usr/bin/sleep infinity") lingerExampleFile, err := lingerExample.ToString() if err != nil { - logrus.Warnf(err.Error()) + logrus.Warn(err.Error()) } containers := `[containers] diff --git a/pkg/specgen/generate/config_linux.go b/pkg/specgen/generate/config_linux.go index ddca2b151c..5954b78c22 100644 --- a/pkg/specgen/generate/config_linux.go +++ b/pkg/specgen/generate/config_linux.go @@ -176,7 +176,7 @@ func shouldMask(mask string, unmask []string) bool { for _, m1 := range strings.Split(m, ":") { match, err := filepath.Match(m1, mask) if err != nil { - logrus.Errorf(err.Error()) + logrus.Error(err.Error()) } if match { return false diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go index 79348aec8b..c4c8dc4511 100644 --- a/pkg/specgen/generate/pod_create.go +++ b/pkg/specgen/generate/pod_create.go @@ -268,7 +268,7 @@ func MapSpec(p *specgen.PodSpecGenerator) (*specgen.SpecGenerator, error) { spec.ConmonPidFile = p.InfraConmonPidFile } - if p.Sysctl != nil && len(p.Sysctl) > 0 { + if len(p.Sysctl) > 0 { spec.Sysctl = p.Sysctl } diff --git a/pkg/systemd/activation_test.go b/pkg/systemd/activation_test.go index 687472206f..0a411bcaa0 100644 --- a/pkg/systemd/activation_test.go +++ b/pkg/systemd/activation_test.go @@ -14,19 +14,19 @@ func TestSocketActivated(t *testing.T) { assert.False(SocketActivated()) // different pid - assert.NoError(os.Setenv("LISTEN_PID", "1")) + t.Setenv("LISTEN_PID", "1") assert.False(SocketActivated()) // same pid no fds - assert.NoError(os.Setenv("LISTEN_PID", strconv.Itoa(os.Getpid()))) - assert.NoError(os.Setenv("LISTEN_FDS", "0")) + t.Setenv("LISTEN_PID", strconv.Itoa(os.Getpid())) + t.Setenv("LISTEN_FDS", "0") assert.False(SocketActivated()) // same pid some fds - assert.NoError(os.Setenv("LISTEN_FDS", "1")) + t.Setenv("LISTEN_FDS", "1") assert.True(SocketActivated()) // FDNAME is ok too (but not required) - assert.NoError(os.Setenv("LISTEN_FDNAMES", "/meshuggah/rocks")) + t.Setenv("LISTEN_FDNAMES", "/meshuggah/rocks") assert.True(SocketActivated()) } diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index 2762f7d06a..2509259d3d 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -1775,7 +1775,7 @@ func handleUserRemap(unitFile *parser.UnitFile, groupName string, podman *Podman autoOpts = append(autoOpts, fmt.Sprintf("size=%v", uidSize)) } - podman.addf("--userns=" + usernsOpts("auto", autoOpts)) + podman.add("--userns=" + usernsOpts("auto", autoOpts)) case "keep-id": if !isUser { return fmt.Errorf("RemapUsers=keep-id is unsupported for system units") @@ -1795,7 +1795,7 @@ func handleUserRemap(unitFile *parser.UnitFile, groupName string, podman *Podman keepidOpts = append(keepidOpts, "gid="+gidMaps[0]) } - podman.addf("--userns=" + usernsOpts("keep-id", keepidOpts)) + podman.add("--userns=" + usernsOpts("keep-id", keepidOpts)) default: return fmt.Errorf("unsupported RemapUsers option '%s'", remapUsers)