Skip to content
Merged
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 .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ run:

linters:
enable:
- gofmt
- gofumpt
Copy link
Contributor

Choose a reason for hiding this comment

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

Can gofmt pass after gofumpt? If so, can we run both? If gofumpt doesn't get updated in the future, then we can fall back to gofmt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can gofmt pass after gofumpt?

Yes it can. gofumpt is a superset.

If so, can we run both?

Does not make sense to me, as they are 99% similar and gofumpt is doing its job. Frankly, gofmt is somewhat abandoned, see e.g. golang/go#6996.

If gofumpt doesn't get updated in the future.

Oh, you mean to sort of re-check gofumpt results with gofmt. For that, we need to run gofumpt first in "fixing" mode, then run gofmt on top of it, which is a separate job.

golangci-lint runs all checkers in parallel, and so if we just add both gofumpt and gofmt, we'll end up double amount of linter warnings.

Now, I hope that we should trust @mvdan's good track record and rely on his promise of "running gofmt after gofumpt should be a no-op".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TL;DR: we don't want both gofumpt and gofmt as it will just double the amount of linter warnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, gofumpt output is designed to be a strict subset of gofmt output. If you see gofmt changing a program after gofumpt ran on it, or if gofumpt itself isn't stable when run twice in a row, that's a bug. There have been a few of those over the years, but they should be rare and relatively easy to fix when reported.

This comment was marked as spam.

3 changes: 1 addition & 2 deletions checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
imagePath = getDefaultImagePath(context)
}

if err := os.MkdirAll(imagePath, 0600); err != nil {
if err := os.MkdirAll(imagePath, 0o600); err != nil {
return "", "", err
}

Expand All @@ -109,7 +109,6 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
}

return imagePath, parentPath, nil

}

func setPageServer(context *cli.Context, options *libcontainer.CriuOpts) {
Expand Down
2 changes: 1 addition & 1 deletion contrib/cmd/recvtty/recvtty.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func main() {
pidPath := ctx.String("pid-file")
if pidPath != "" {
pid := fmt.Sprintf("%d\n", os.Getpid())
if err := ioutil.WriteFile(pidPath, []byte(pid), 0644); err != nil {
if err := ioutil.WriteFile(pidPath, []byte(pid), 0o644); err != nil {
return err
}
}
Expand Down
17 changes: 8 additions & 9 deletions libcontainer/cgroups/fs/blkio.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
)

type BlkioGroup struct {
}
type BlkioGroup struct{}

func (s *BlkioGroup) Name() string {
return "blkio"
Expand Down Expand Up @@ -161,7 +160,7 @@ func (s *BlkioGroup) GetStats(path string, stats *cgroups.Stats) error {
filename string
blkioStatEntriesPtr *[]cgroups.BlkioStatEntry
}
var bfqDebugStats = []blkioStatInfo{
bfqDebugStats := []blkioStatInfo{
{
filename: "blkio.bfq.sectors_recursive",
blkioStatEntriesPtr: &stats.BlkioStats.SectorsRecursive,
Expand Down Expand Up @@ -195,7 +194,7 @@ func (s *BlkioGroup) GetStats(path string, stats *cgroups.Stats) error {
blkioStatEntriesPtr: &stats.BlkioStats.IoServiceBytesRecursive,
},
}
var bfqStats = []blkioStatInfo{
bfqStats := []blkioStatInfo{
{
filename: "blkio.bfq.io_serviced_recursive",
blkioStatEntriesPtr: &stats.BlkioStats.IoServicedRecursive,
Expand All @@ -205,7 +204,7 @@ func (s *BlkioGroup) GetStats(path string, stats *cgroups.Stats) error {
blkioStatEntriesPtr: &stats.BlkioStats.IoServiceBytesRecursive,
},
}
var cfqStats = []blkioStatInfo{
cfqStats := []blkioStatInfo{
{
filename: "blkio.sectors_recursive",
blkioStatEntriesPtr: &stats.BlkioStats.SectorsRecursive,
Expand Down Expand Up @@ -239,7 +238,7 @@ func (s *BlkioGroup) GetStats(path string, stats *cgroups.Stats) error {
blkioStatEntriesPtr: &stats.BlkioStats.IoServiceBytesRecursive,
},
}
var throttleRecursiveStats = []blkioStatInfo{
throttleRecursiveStats := []blkioStatInfo{
{
filename: "blkio.throttle.io_serviced_recursive",
blkioStatEntriesPtr: &stats.BlkioStats.IoServicedRecursive,
Expand All @@ -249,7 +248,7 @@ func (s *BlkioGroup) GetStats(path string, stats *cgroups.Stats) error {
blkioStatEntriesPtr: &stats.BlkioStats.IoServiceBytesRecursive,
},
}
var baseStats = []blkioStatInfo{
baseStats := []blkioStatInfo{
{
filename: "blkio.throttle.io_serviced",
blkioStatEntriesPtr: &stats.BlkioStats.IoServicedRecursive,
Expand All @@ -259,7 +258,7 @@ func (s *BlkioGroup) GetStats(path string, stats *cgroups.Stats) error {
blkioStatEntriesPtr: &stats.BlkioStats.IoServiceBytesRecursive,
},
}
var orderedStats = [][]blkioStatInfo{
orderedStats := [][]blkioStatInfo{
bfqDebugStats,
bfqStats,
cfqStats,
Expand All @@ -280,7 +279,7 @@ func (s *BlkioGroup) GetStats(path string, stats *cgroups.Stats) error {
return err
}
*statInfo.blkioStatEntriesPtr = blkioStats
//finish if all stats are gathered
// finish if all stats are gathered
if i == len(statGroup)-1 {
return nil
}
Expand Down
5 changes: 3 additions & 2 deletions libcontainer/cgroups/fs/blkio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ func TestBlkioStatsNoFilesBFQDebug(t *testing.T) {
cpuset := &CpusetGroup{}
actualStats := *cgroups.NewStats()
err := cpuset.GetStats(helper.CgroupPath, &actualStats)

if err != nil {
t.Errorf(fmt.Sprintf("test case '%s' failed unexpectedly: %s", testCase.desc, err))
}
Expand Down Expand Up @@ -576,7 +575,6 @@ func TestBlkioStatsNoFilesCFQ(t *testing.T) {
cpuset := &CpusetGroup{}
actualStats := *cgroups.NewStats()
err := cpuset.GetStats(helper.CgroupPath, &actualStats)

if err != nil {
t.Errorf(fmt.Sprintf("test case '%s' failed unexpectedly: %s", testCase.desc, err))
}
Expand Down Expand Up @@ -759,6 +757,7 @@ func TestBlkioSetThrottleReadBpsDevice(t *testing.T) {
t.Fatal("Got the wrong value, set blkio.throttle.read_bps_device failed.")
}
}

func TestBlkioSetThrottleWriteBpsDevice(t *testing.T) {
helper := NewCgroupTestUtil("blkio", t)
defer helper.cleanup()
Expand Down Expand Up @@ -789,6 +788,7 @@ func TestBlkioSetThrottleWriteBpsDevice(t *testing.T) {
t.Fatal("Got the wrong value, set blkio.throttle.write_bps_device failed.")
}
}

func TestBlkioSetThrottleReadIOpsDevice(t *testing.T) {
helper := NewCgroupTestUtil("blkio", t)
defer helper.cleanup()
Expand Down Expand Up @@ -819,6 +819,7 @@ func TestBlkioSetThrottleReadIOpsDevice(t *testing.T) {
t.Fatal("Got the wrong value, set blkio.throttle.read_iops_device failed.")
}
}

func TestBlkioSetThrottleWriteIOpsDevice(t *testing.T) {
helper := NewCgroupTestUtil("blkio", t)
defer helper.cleanup()
Expand Down
5 changes: 2 additions & 3 deletions libcontainer/cgroups/fs/cpu.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
)

type CpuGroup struct {
}
type CpuGroup struct{}

func (s *CpuGroup) Name() string {
return "cpu"
Expand All @@ -26,7 +25,7 @@ func (s *CpuGroup) Apply(path string, d *cgroupData) error {
if path == "" {
return nil
}
if err := os.MkdirAll(path, 0755); err != nil {
if err := os.MkdirAll(path, 0o755); err != nil {
return err
}
// We should set the real-Time group scheduling settings before moving
Expand Down
3 changes: 2 additions & 1 deletion libcontainer/cgroups/fs/cpu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ func TestCpuStats(t *testing.T) {
expectedStats := cgroups.ThrottlingData{
Periods: nrPeriods,
ThrottledPeriods: nrThrottled,
ThrottledTime: throttledTime}
ThrottledTime: throttledTime,
}

expectThrottlingDataEquals(t, expectedStats, actualStats.CpuStats.ThrottlingData)
}
Expand Down
5 changes: 2 additions & 3 deletions libcontainer/cgroups/fs/cpuacct.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ const (
clockTicks uint64 = 100
)

type CpuacctGroup struct {
}
type CpuacctGroup struct{}

func (s *CpuacctGroup) Name() string {
return "cpuacct"
Expand Down Expand Up @@ -144,7 +143,7 @@ func getPercpuUsageInModes(path string) ([]uint64, []uint64, error) {
defer file.Close()

scanner := bufio.NewScanner(file)
scanner.Scan() //skipping header line
scanner.Scan() // skipping header line

for scanner.Scan() {
lineFields := strings.SplitN(scanner.Text(), " ", cuacctUsageAllColumnsNumber+1)
Expand Down
24 changes: 16 additions & 8 deletions libcontainer/cgroups/fs/cpuacct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@ func TestCpuacctStats(t *testing.T) {

expectedStats := cgroups.CpuUsage{
TotalUsage: uint64(12262454190222160),
PercpuUsage: []uint64{1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187,
1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086},
PercpuUsageInKernelmode: []uint64{637727786389114, 638197595421064, 638956774598358, 637985531181620,
638837766495476, 638763309884944, 640081778921247, 638716766259495},
PercpuUsageInUsermode: []uint64{962250696038415, 981956408513304, 1002658817529022, 994937703492523,
874843781648690, 872544369885276, 870104915696359, 870202363887496},
PercpuUsage: []uint64{
1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187,
1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086,
},
PercpuUsageInKernelmode: []uint64{
637727786389114, 638197595421064, 638956774598358, 637985531181620,
638837766495476, 638763309884944, 640081778921247, 638716766259495,
},
PercpuUsageInUsermode: []uint64{
962250696038415, 981956408513304, 1002658817529022, 994937703492523,
874843781648690, 872544369885276, 870104915696359, 870202363887496,
},
UsageInKernelmode: (uint64(291429664) * nanosecondsInSecond) / clockTicks,
UsageInUsermode: (uint64(452278264) * nanosecondsInSecond) / clockTicks,
}
Expand Down Expand Up @@ -78,8 +84,10 @@ func TestCpuacctStatsWithoutUsageAll(t *testing.T) {

expectedStats := cgroups.CpuUsage{
TotalUsage: uint64(12262454190222160),
PercpuUsage: []uint64{1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187,
1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086},
PercpuUsage: []uint64{
1564936537989058, 1583937096487821, 1604195415465681, 1596445226820187,
1481069084155629, 1478735613864327, 1477610593414743, 1476362015778086,
},
PercpuUsageInKernelmode: []uint64{},
PercpuUsageInUsermode: []uint64{},
UsageInKernelmode: (uint64(291429664) * nanosecondsInSecond) / clockTicks,
Expand Down
7 changes: 3 additions & 4 deletions libcontainer/cgroups/fs/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
"golang.org/x/sys/unix"
)

type CpusetGroup struct {
}
type CpusetGroup struct{}

func (s *CpusetGroup) Name() string {
return "cpuset"
Expand Down Expand Up @@ -156,7 +155,7 @@ func (s *CpusetGroup) ApplyDir(dir string, r *configs.Resources, pid int) error
if err := cpusetEnsureParent(filepath.Dir(dir)); err != nil {
return err
}
if err := os.Mkdir(dir, 0755); err != nil && !os.IsExist(err) {
if err := os.Mkdir(dir, 0o755); err != nil && !os.IsExist(err) {
return err
}
// We didn't inherit cpuset configs from parent, but we have
Expand Down Expand Up @@ -206,7 +205,7 @@ func cpusetEnsureParent(current string) error {
if err := cpusetEnsureParent(parent); err != nil {
return err
}
if err := os.Mkdir(current, 0755); err != nil && !os.IsExist(err) {
if err := os.Mkdir(current, 0o755); err != nil && !os.IsExist(err) {
return err
}
return cpusetCopyIfNeeded(current, parent)
Expand Down
5 changes: 2 additions & 3 deletions libcontainer/cgroups/fs/cpuset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ func TestCPUSetStatsCorrect(t *testing.T) {
MemorySpreadSlab: 1,
MemoryPressure: 34377,
SchedLoadBalance: 1,
SchedRelaxDomainLevel: -1}
SchedRelaxDomainLevel: -1,
}
if !reflect.DeepEqual(expectedStats, actualStats.CPUSetStats) {
t.Fatalf("Expected Cpuset stats usage %#v but found %#v",
expectedStats, actualStats.CPUSetStats)
}

}

func TestCPUSetStatsMissingFiles(t *testing.T) {
Expand Down Expand Up @@ -226,7 +226,6 @@ func TestCPUSetStatsMissingFiles(t *testing.T) {
cpuset := &CpusetGroup{}
actualStats := *cgroups.NewStats()
err := cpuset.GetStats(helper.CgroupPath, &actualStats)

if err != nil {
t.Errorf("failed unexpectedly: %q", err)
}
Expand Down
3 changes: 1 addition & 2 deletions libcontainer/cgroups/fs/freezer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import (
"golang.org/x/sys/unix"
)

type FreezerGroup struct {
}
type FreezerGroup struct{}

func (s *FreezerGroup) Name() string {
return "freezer"
Expand Down
8 changes: 5 additions & 3 deletions libcontainer/cgroups/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ func NewManager(cg *configs.Cgroup, paths map[string]string, rootless bool) cgro
}

// The absolute path to the root of the cgroup hierarchies.
var cgroupRootLock sync.Mutex
var cgroupRoot string
var (
cgroupRootLock sync.Mutex
cgroupRoot string
)

const defaultCgroupRoot = "/sys/fs/cgroup"

Expand Down Expand Up @@ -393,7 +395,7 @@ func join(path string, pid int) error {
if path == "" {
return nil
}
if err := os.MkdirAll(path, 0755); err != nil {
if err := os.MkdirAll(path, 0o755); err != nil {
return err
}
return cgroups.WriteCgroupProc(path, pid)
Expand Down
3 changes: 1 addition & 2 deletions libcontainer/cgroups/fs/hugetlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
)

type HugetlbGroup struct {
}
type HugetlbGroup struct{}

func (s *HugetlbGroup) Name() string {
return "hugetlb"
Expand Down
3 changes: 1 addition & 2 deletions libcontainer/cgroups/fs/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ const (
cgroupMemoryMaxUsage = "memory.max_usage_in_bytes"
)

type MemoryGroup struct {
}
type MemoryGroup struct{}

func (s *MemoryGroup) Name() string {
return "memory"
Expand Down
8 changes: 5 additions & 3 deletions libcontainer/cgroups/fs/memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestMemorySetMemorySwappinessDefault(t *testing.T) {
helper := NewCgroupTestUtil("memory", t)
defer helper.cleanup()

swappinessBefore := 60 //default is 60
swappinessBefore := 60 // default is 60
swappinessAfter := uint64(0)

helper.writeFileContents(map[string]string{
Expand Down Expand Up @@ -243,7 +243,8 @@ func TestMemoryStats(t *testing.T) {
if err != nil {
t.Fatal(err)
}
expectedStats := cgroups.MemoryStats{Cache: 512, Usage: cgroups.MemoryData{Usage: 2048, MaxUsage: 4096, Failcnt: 100, Limit: 8192}, SwapUsage: cgroups.MemoryData{Usage: 2048, MaxUsage: 4096, Failcnt: 100, Limit: 8192}, KernelUsage: cgroups.MemoryData{Usage: 2048, MaxUsage: 4096, Failcnt: 100, Limit: 8192}, Stats: map[string]uint64{"cache": 512, "rss": 1024}, UseHierarchy: true,
expectedStats := cgroups.MemoryStats{
Cache: 512, Usage: cgroups.MemoryData{Usage: 2048, MaxUsage: 4096, Failcnt: 100, Limit: 8192}, SwapUsage: cgroups.MemoryData{Usage: 2048, MaxUsage: 4096, Failcnt: 100, Limit: 8192}, KernelUsage: cgroups.MemoryData{Usage: 2048, MaxUsage: 4096, Failcnt: 100, Limit: 8192}, Stats: map[string]uint64{"cache": 512, "rss": 1024}, UseHierarchy: true,
PageUsageByNUMA: cgroups.PageUsageByNUMA{
PageUsageByNUMAInner: cgroups.PageUsageByNUMAInner{
Total: cgroups.PageStats{Total: 44611, Nodes: map[uint8]uint64{0: 32631, 1: 7501, 2: 1982, 3: 2497}},
Expand All @@ -257,7 +258,8 @@ func TestMemoryStats(t *testing.T) {
Anon: cgroups.PageStats{Total: 46096, Nodes: map[uint8]uint64{0: 12597, 1: 18890, 2: 283, 3: 14326}},
Unevictable: cgroups.PageStats{Total: 20, Nodes: map[uint8]uint64{0: 0, 1: 0, 2: 0, 3: 20}},
},
}}
},
}
expectMemoryStatEquals(t, expectedStats, actualStats.MemoryStats)
}

Expand Down
3 changes: 1 addition & 2 deletions libcontainer/cgroups/fs/net_cls.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
)

type NetClsGroup struct {
}
type NetClsGroup struct{}

func (s *NetClsGroup) Name() string {
return "net_cls"
Expand Down
3 changes: 1 addition & 2 deletions libcontainer/cgroups/fs/net_prio.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
)

type NetPrioGroup struct {
}
type NetPrioGroup struct{}

func (s *NetPrioGroup) Name() string {
return "net_prio"
Expand Down
Loading