Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
sudo apt -qy install libseccomp-dev
- uses: golangci/golangci-lint-action@v9
with:
version: v2.6
version: v2.9
skip-cache: true
# Extra linters, only checking new code from a pull request to main.
- name: lint-extra
Expand Down
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ linters:
- errorlint
- forbidigo
- nolintlint
- prealloc
- unconvert
- unparam
settings:
Expand Down Expand Up @@ -46,9 +47,10 @@ linters:
analyze-types: true
exclusions:
rules:
# forbidigo lints are only relevant for main code.
# forbidigo and prealloc lints are only relevant for main code.
- path: '(.+)_test\.go'
linters:
- forbidigo
- prealloc
presets:
- std-error-handling
2 changes: 1 addition & 1 deletion events.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func convertMemoryEntry(c cgroups.MemoryData) types.MemoryEntry {
}

func convertBlkioEntry(c []cgroups.BlkioStatEntry) []types.BlkioEntry {
var out []types.BlkioEntry
out := make([]types.BlkioEntry, 0, len(c))
for _, e := range c {
out = append(out, types.BlkioEntry(e))
}
Expand Down
3 changes: 2 additions & 1 deletion libcontainer/internal/userns/usernsfd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ func (m Mapping) toSys() (uids, gids []syscall.SysProcIDMap) {
// the uid and gid mappings (because the order doesn't matter to the kernel).
// The set of userns handles is indexed using this ID.
func (m Mapping) id() string {
var uids, gids []string
uids := make([]string, 0, len(m.UIDMappings))
for _, idmap := range m.UIDMappings {
uids = append(uids, fmt.Sprintf("%d:%d:%d", idmap.ContainerID, idmap.HostID, idmap.Size))
}
gids := make([]string, 0, len(m.GIDMappings))
for _, idmap := range m.GIDMappings {
gids = append(gids, fmt.Sprintf("%d:%d:%d", idmap.ContainerID, idmap.HostID, idmap.Size))
}
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/specconv/spec_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func initMaps() {
// Used by `runc features`.
func KnownNamespaces() []string {
initMaps()
var res []string
var res []string //nolint:prealloc
for k := range namespaceMapping {
Comment on lines -177 to 178
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using len(namespaceMapping) for the prealloc doesn't work here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ^^^ is one the functions used by runc features only, so I chose to ignore rather than fix prealloc warnings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, this one is it? Oh, okay. If we have the linter, I'd still do it... Not sure we want the linter, though

res = append(res, string(k))
}
Expand All @@ -186,7 +186,7 @@ func KnownNamespaces() []string {
// Used by `runc features`.
func KnownMountOptions() []string {
initMaps()
var res []string
var res []string //nolint:prealloc
for k := range mountFlags {
Comment on lines -189 to 190
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually should look like this:

res := make([]string, 0, len(mountFlags) + len(mountPropagationMapping) + len(recAttrFlags) + len(extensionFLags)

and this is kind of ugly, with no real performance benefit (as this is only used from runc features).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative to this is:

  func KnownMountOptions() []string {
        initMaps()
        all := slices.Concat(
                slices.Collect(maps.Keys(mountFlags)),
                slices.Collect(maps.Keys(mountPropagationMapping)),
                slices.Collect(maps.Keys(recAttrFlags)),
                slices.Collect(maps.Keys(extensionFlags)),
        )
        slices.Sort(all)
        return all
  }

which I don't like either as it creates some intermediate slices.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unsure the noise/signal ratio of this linter was going to be useful. Clearly it can force us to write horrible code (like here). I'm not sure this linter is worth having.... :-/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed (I agree it's more of a "recommendation" kind of linter). Kept some of the fixes which make sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kolyshkin did you push?

res = append(res, k)
}
Expand Down