Skip to content

Commit

Permalink
Merge pull request #2148 from Luap99/go-1.22
Browse files Browse the repository at this point in the history
update to Go 1.22 and golangci-lint 1.60.3
  • Loading branch information
openshift-merge-bot[bot] authored Sep 3, 2024
2 parents 8a7b0a6 + 1750dbd commit 08f9c11
Show file tree
Hide file tree
Showing 35 changed files with 26 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
permissions: read-all

env:
LINT_VERSION: v1.56.2
LINT_VERSION: v1.60.3

jobs:
codespell:
Expand Down
16 changes: 3 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ run:
linters:
enable-all: true
disable:
# linters deprecated by upstreams ...
- interfacer
- varcheck
- deadcode
- scopelint
- maligned
- nosnakecase
- exhaustivestruct
- structcheck
- ifshort
- golint
# linters explicitly disabled for the below mentioned reasons ...
- funlen # too aggressive/wishful size/statement limit
- gochecknoinits # too many hard to fix init() funcs across the code
Expand All @@ -41,9 +30,8 @@ linters:
- errname
- errorlint
- exhaustive
- exhaustivestruct
- gochecknoglobals
- goerr113
- err113
- gomnd
- nolintlint
- wrapcheck
Expand All @@ -60,12 +48,14 @@ linters:
- maintidx
- ireturn
- exhaustruct
- execinquery
- gosec
- godot
- gocyclo
- dogsled
- tparallel
- thelper
- mnd #way to many false positives
- nilnil
- nilerr
- interfacebloat
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ vendor:
.PHONY: install.tools
install.tools: build/golangci-lint .install.md2man

build/golangci-lint: VERSION=v1.56.2
build/golangci-lint: VERSION=v1.60.3
build/golangci-lint:
curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/$(VERSION)/install.sh | sh -s -- -b ./build $(VERSION)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/containers/common

// Warning: Ensure the "go" and "toolchain" versions match exactly to prevent unwanted auto-updates

go 1.21.0
go 1.22.0

require (
github.com/BurntSushi/toml v1.4.0
Expand Down
2 changes: 1 addition & 1 deletion libimage/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (i *Image) applyFilters(ctx context.Context, filters compiledFilters, tree
// meantime, so do an extra check and make the
// error non-fatal (see containers/podman/issues/12582).
if errCorrupted := i.isCorrupted(ctx, ""); errCorrupted != nil {
logrus.Errorf(errCorrupted.Error())
logrus.Error(errCorrupted.Error())
return false, nil
}
return false, err
Expand Down
4 changes: 2 additions & 2 deletions libimage/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func TestTagAndUntagParallel(t *testing.T) {

// Test tag in parallel, the extra go routine is critical for the test do not remove that.
wg.Add(tagCount)
for i := 0; i < tagCount; i++ {
for i := range tagCount {
name := fmt.Sprintf("localhost/tag-%d:latest", i)
names = append(names, name)
go func(name string) {
Expand All @@ -331,7 +331,7 @@ func TestTagAndUntagParallel(t *testing.T) {

// Test untag in parallel
wg.Add(tagCount)
for i := 0; i < tagCount; i++ {
for i := range tagCount {
name := fmt.Sprintf("localhost/tag-%d:latest", i)
names = append(names, name)
go func(name string) {
Expand Down
4 changes: 2 additions & 2 deletions libimage/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (r *Runtime) searchImageInRegistry(ctx context.Context, term, registry stri
}

paramsArr := []SearchResult{}
for i := 0; i < limit; i++ {
for i := range limit {
// Check whether query matches filters
if !(filterMatchesAutomatedFilter(&options.Filter, results[i]) && filterMatchesOfficialFilter(&options.Filter, results[i]) && filterMatchesStarFilter(&options.Filter, results[i])) {
continue
Expand Down Expand Up @@ -275,7 +275,7 @@ func searchRepositoryTags(ctx context.Context, sys *types.SystemContext, registr
}
}
paramsArr := []SearchResult{}
for i := 0; i < limit; i++ {
for i := range limit {
params := SearchResult{
Name: imageRef.DockerReference().Name(),
Tag: tags[i],
Expand Down
1 change: 0 additions & 1 deletion libnetwork/cni/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ var _ = Describe("Config", func() {
})

for _, driver := range []string{"macvlan", "ipvlan"} {
driver := driver
It(fmt.Sprintf("create %s config with none ipam driver", driver), func() {
network := types.Network{
Driver: driver,
Expand Down
2 changes: 0 additions & 2 deletions libnetwork/cni/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma
}

for name, netOpts := range options.Networks {
netOpts := netOpts
network := n.networks[name]
rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, &netOpts)

Expand Down Expand Up @@ -237,7 +236,6 @@ func (n *cniNetwork) teardown(namespacePath string, options types.TeardownOption
var multiErr *multierror.Error
teardown := func() error {
for name, netOpts := range options.Networks {
netOpts := netOpts
rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, &netOpts)

cniConfList, newRt, err := getCachedNetworkConfig(n.cniConf, name, rt)
Expand Down
4 changes: 0 additions & 4 deletions libnetwork/etchosts/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func TestNew(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
baseHostFile := tt.baseFileName
if !tt.noWriteBaseFile {
Expand Down Expand Up @@ -364,7 +363,6 @@ func TestAdd(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "hosts")
assert.NoErrorf(t, err, "failed to create base host file: %v", err)
Expand Down Expand Up @@ -460,7 +458,6 @@ func TestAddIfExists(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "hosts")
assert.NoErrorf(t, err, "failed to create base host file: %v", err)
Expand Down Expand Up @@ -523,7 +520,6 @@ func TestRemove(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
f, err := os.CreateTemp(t.TempDir(), "hosts")
assert.NoErrorf(t, err, "failed to create base host file: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion libnetwork/internal/util/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestNextSubnet(t *testing.T) {
}

func TestGetRandomIPv6Subnet(t *testing.T) {
for i := 0; i < 1000; i++ {
for i := range 1000 {
t.Run(fmt.Sprintf("GetRandomIPv6Subnet %d", i), func(t *testing.T) {
sub, err := getRandomIPv6Subnet()
if err != nil {
Expand Down
3 changes: 0 additions & 3 deletions libnetwork/internal/util/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func TestParseMTU(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := ParseMTU(tt.args.mtuOption)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -113,7 +112,6 @@ func TestParseVlan(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := ParseVlan(tt.args.vlanOption)
if (err != nil) != tt.wantErr {
Expand Down Expand Up @@ -202,7 +200,6 @@ func TestParseIsolate(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := ParseIsolate(tt.args.isolateOption)
if (err != nil) != tt.wantErr {
Expand Down
2 changes: 1 addition & 1 deletion libnetwork/internal/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func GetFreeIPv4NetworkSubnet(usedNetworks []*net.IPNet, subnetPools []config.Su
// GetFreeIPv6NetworkSubnet returns a unused ipv6 subnet
func GetFreeIPv6NetworkSubnet(usedNetworks []*net.IPNet) (*types.Subnet, error) {
// FIXME: Is 10000 fine as limit? We should prevent an endless loop.
for i := 0; i < 10000; i++ {
for range 10000 {
// RFC4193: Choose the ipv6 subnet random and NOT sequentially.
network, err := getRandomIPv6Subnet()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion libnetwork/internal/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TestGetFreeIPv4NetworkSubnet(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got, err := GetFreeIPv4NetworkSubnet(tt.args.usedNetworks, tt.args.subnetPools)
if (err != nil) != tt.wantErr {
Expand Down
1 change: 0 additions & 1 deletion libnetwork/internal/util/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func ValidateSetupOptions(n NetUtil, namespacePath string, options types.SetupOp
return errors.New("must specify at least one network")
}
for name, netOpts := range options.Networks {
netOpts := netOpts
network, err := n.Network(name)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion libnetwork/netavark/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (n *netavarkNetwork) networkCreate(newNetwork *types.Network, defaultNet bo

// generate random network ID
var i int
for i = 0; i < 1000; i++ {
for i = range 1000 {
id := stringid.GenerateNonCryptoID()
if _, err := n.getNetwork(id); err != nil {
newNetwork.ID = id
Expand Down
2 changes: 1 addition & 1 deletion libnetwork/netavark/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ var _ = Describe("IPAM", func() {
Expect(err).ToNot(HaveOccurred())
}

for i := 0; i < 30; i++ {
for i := range 30 {
opts := types.NetworkOptions{
ContainerID: fmt.Sprintf("id-%d", i),
Networks: map[string]types.PerNetworkOptions{
Expand Down
3 changes: 0 additions & 3 deletions libnetwork/resolvconf/resolv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func TestNew(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
base := filepath.Join(t.TempDir(), "resolv.conf")
target := filepath.Join(t.TempDir(), "new-resolv.conf")
Expand Down Expand Up @@ -185,7 +184,6 @@ options edns0
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
resolvPath := filepath.Join(t.TempDir(), "resolv.conf")
err := os.WriteFile(resolvPath, []byte(tt.content), 0o644)
Expand Down Expand Up @@ -228,7 +226,6 @@ options edns0
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
resolvPath := filepath.Join(t.TempDir(), "resolv.conf")
err := os.WriteFile(resolvPath, []byte(tt.content), 0o644)
Expand Down
2 changes: 1 addition & 1 deletion libnetwork/slirp4netns/slirp4netns.go
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ func setupRootlessPortMappingViaSlirp(ports []types.PortMapping, cmd *exec.Cmd,
if hostIP == "" {
hostIP = "0.0.0.0"
}
for i := uint16(0); i < port.Range; i++ {
for i := range port.Range {
if err := openSlirp4netnsPort(apiSocket, protocol, hostIP, port.HostPort+i, port.ContainerPort+i); err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion libnetwork/util/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func TestGenerateFilterFunc(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
for _, entry := range tt.args.keys {
if _, err := createFilterFuncs(entry, tt.args.labels); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cgroups/systemd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func systemdCreate(resources *configs.Resources, path string, c *systemdDbus.Con
slice = strings.TrimSuffix(slice, "/")

var lastError error
for i := 0; i < 2; i++ {
for i := range 2 {
properties := []systemdDbus.Property{
systemdDbus.PropDescription("cgroup " + name),
systemdDbus.PropWants(slice),
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/default_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func getDefaultProcessLimits() []string {
dat, err := os.ReadFile("/proc/sys/kernel/pid_max")
if err == nil {
val := strings.TrimSuffix(string(dat), "\n")
max, err := strconv.ParseUint(val, 10, 64)
maxLimit, err := strconv.ParseUint(val, 10, 64)
if err == nil {
rlim = unix.Rlimit{Cur: max, Max: max}
rlim = unix.Rlimit{Cur: maxLimit, Max: maxLimit}
}
}
defaultLimits := []string{}
Expand Down
3 changes: 0 additions & 3 deletions pkg/filters/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func TestMatchLabelFilters(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := MatchLabelFilters(tt.args.filterValues, tt.args.labels); got != tt.want {
t.Errorf("MatchLabelFilters() = %v, want %v", got, tt.want)
Expand Down Expand Up @@ -148,7 +147,6 @@ func TestMatchNegatedLabelFilters(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
if got := MatchNegatedLabelFilters(tt.args.filterValues, tt.args.labels); got != tt.want {
t.Errorf("MatchNegatedLabelFilters() = %v, want %v", got, tt.want)
Expand Down Expand Up @@ -180,7 +178,6 @@ func TestComputeUntilTimestamp(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
_, err := ComputeUntilTimestamp(tt.args)
if (err != nil) != tt.wantErr {
Expand Down
1 change: 0 additions & 1 deletion pkg/hooks/exec/runtimeconfigfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func RuntimeConfigFilterWithOptions(ctx context.Context, options RuntimeConfigFi
return nil, err
}
for i, hook := range options.Hooks {
hook := hook
var stdout bytes.Buffer
hookErr, err = RunWithOptions(ctx, RunOptions{Hook: &hook, Dir: options.Dir, State: data, Stdout: &stdout, PostKillTimeout: options.PostKillTimeout})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func testStringSlice(t *testing.T, values [][]string, set func(List, digest.Dige
}
}

func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Digest, map[string]string) error, clear func(List, *digest.Digest) error, get func(List, *digest.Digest) (map[string]string, error)) {
func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Digest, map[string]string) error, clearFunc func(List, *digest.Digest) error, get func(List, *digest.Digest) (map[string]string, error)) {
bytes, err := os.ReadFile(ociFixture)
if err != nil {
t.Fatalf("error loading blob: %v", err)
Expand All @@ -221,7 +221,7 @@ func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Di
instance := expectedInstance
for _, instanceDigest := range []*digest.Digest{nil, &instance} {
for _, testMap := range values {
if err = clear(list, instanceDigest); err != nil {
if err = clearFunc(list, instanceDigest); err != nil {
t.Fatalf("error clearing %v: %v", testMap, err)
}
if err = set(list, instanceDigest, testMap); err != nil {
Expand All @@ -247,7 +247,7 @@ func testMap(t *testing.T, values []map[string]string, set func(List, *digest.Di
t.Fatalf("expected map value %q=%q, got %q", k, v, values[k])
}
}
if err = clear(list, instanceDigest); err != nil {
if err = clearFunc(list, instanceDigest); err != nil {
t.Fatalf("error clearing %v: %v", testMap, err)
}
values, err = get(list, instanceDigest)
Expand Down
2 changes: 1 addition & 1 deletion pkg/netns/netns_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewNSAtPath(nsPath string) (ns.NetNS, error) {
// NewNS creates a new persistent (bind-mounted) network namespace and returns
// an object representing that namespace, without switching to it.
func NewNS() (ns.NetNS, error) {
for i := 0; i < 10000; i++ {
for range 10000 {
b := make([]byte, 16)
_, err := rand.Reader.Read(b)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/report/camelcase/camelcase.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Split(src string) (entries []string) {
}
// handle upper case -> lower case sequences, e.g.
// "PDFL", "oader" -> "PDF", "Loader"
for i := 0; i < len(runes)-1; i++ {
for i := range len(runes) - 1 {
if unicode.IsUpper(runes[i][0]) && unicode.IsLower(runes[i+1][0]) {
runes[i+1] = append([]rune{runes[i][len(runes[i])-1]}, runes[i+1]...)
runes[i] = runes[i][:len(runes[i])-1]
Expand Down
1 change: 0 additions & 1 deletion pkg/report/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func TestFormatter_ParseTable(t *testing.T) {
}

for loop, tc := range testCase {
tc := tc
name := fmt.Sprintf("Loop#%d", loop)
t.Run(name, func(t *testing.T) {
buf := new(bytes.Buffer)
Expand Down
Loading

0 comments on commit 08f9c11

Please sign in to comment.