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

Add Golangci-lint to CI #272

Merged
merged 1 commit into from
Mar 7, 2023
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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ jobs:
with:
working-directory: src/github.com/containerd/cgroups

lint:
name: Lint
timeout-minutes: 10
needs: [project]
runs-on: ubuntu-22.04

strategy:
matrix:
go-version: [1.19.x, 1.20.x]

steps:
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- name: Checkout cgroups
uses: actions/checkout@v3
with:
path: src/github.com/containerd/cgroups

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.51.1
args: --verbose
working-directory: src/github.com/containerd/cgroups

test:
name: Test cgroups
timeout-minutes: 15
Expand Down
101 changes: 85 additions & 16 deletions cgroup1/cgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func TestCreate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand All @@ -60,7 +64,11 @@ func TestStat(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand All @@ -82,7 +90,11 @@ func TestAdd(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand All @@ -105,7 +117,11 @@ func TestAddFilteredSubsystems(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -162,7 +178,11 @@ func TestAddTask(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand All @@ -185,7 +205,11 @@ func TestAddTaskFilteredSubsystems(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -227,7 +251,11 @@ func TestListPids(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -262,7 +290,11 @@ func TestListTasksPids(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -349,12 +381,21 @@ func TestLoad(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
return
}
defer func() {
if err := control.Delete(); err != nil {
t.Errorf("failed to delete cgroup: %v", err)
}
}()
if control, err = Load(StaticPath("test"), WithHiearchy(mock.hierarchy)); err != nil {
t.Error(err)
return
Expand All @@ -370,7 +411,11 @@ func TestLoadWithMissingSubsystems(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
subsystems, err := mock.hierarchy()
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -404,7 +449,11 @@ func TestDelete(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand All @@ -420,7 +469,11 @@ func TestCreateSubCgroup(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -458,7 +511,11 @@ func TestFreezeThaw(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand Down Expand Up @@ -487,7 +544,11 @@ func TestSubsystems(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("test"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
Expand All @@ -510,13 +571,21 @@ func TestCpusetParent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
control, err := New(StaticPath("/parent/child"), &specs.LinuxResources{}, WithHiearchy(mock.hierarchy))
if err != nil {
t.Error(err)
return
}
defer control.Delete()
defer func() {
if err := control.Delete(); err != nil {
t.Errorf("failed to delete cgroup: %v", err)
}
}()
for _, file := range []string{
"parent/cpuset.cpus",
"parent/cpuset.mems",
Expand Down
6 changes: 5 additions & 1 deletion cgroup1/cpuacct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func TestGetUsage(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
cpuacct := NewCpuacct(mock.root)
if cpuacct == nil {
t.Fatal("cpuacct is nil")
Expand Down
24 changes: 20 additions & 4 deletions cgroup1/pids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ func TestPids(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
pids := NewPids(mock.root)
if pids == nil {
t.Fatal("pids is nil")
Expand Down Expand Up @@ -89,7 +93,11 @@ func TestPidsMissingCurrent(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
pids := NewPids(mock.root)
if pids == nil {
t.Fatal("pids is nil")
Expand All @@ -106,7 +114,11 @@ func TestPidsMissingMax(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
pids := NewPids(mock.root)
if pids == nil {
t.Fatal("pids is nil")
Expand Down Expand Up @@ -135,7 +147,11 @@ func TestPidsOverflowMax(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer mock.delete()
defer func() {
if err := mock.delete(); err != nil {
t.Errorf("failed delete: %v", err)
}
}()
pids := NewPids(mock.root)
if pids == nil {
t.Fatal("pids is nil")
Expand Down
5 changes: 2 additions & 3 deletions cgroup1/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

const (
SystemdDbus Name = "systemd"
defaultSlice = "system.slice"
defaultSlice Name = "system.slice"
)

var (
Expand All @@ -56,7 +56,7 @@ func Systemd() ([]Subsystem, error) {

func Slice(slice, name string) Path {
if slice == "" {
slice = defaultSlice
slice = string(defaultSlice)
}
return func(subsystem Name) (string, error) {
return filepath.Join(slice, name), nil
Expand All @@ -70,7 +70,6 @@ func NewSystemd(root string) (*SystemdController, error) {
}

type SystemdController struct {
mu sync.Mutex
root string
}

Expand Down
4 changes: 2 additions & 2 deletions cgroup2/devicefilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func (p *program) appendDevice(dev specs.LinuxDeviceCgroup) error {
}
p.insts = append(p.insts, acceptBlock(dev.Allow)...)
// set blockSym to the first instruction we added in this iteration
p.insts[prevBlockLastIdx+1] = p.insts[prevBlockLastIdx+1].Sym(blockSym)
p.insts[prevBlockLastIdx+1] = p.insts[prevBlockLastIdx+1].WithSymbol(blockSym)
p.blockID++
return nil
}
Expand All @@ -180,7 +180,7 @@ func (p *program) finalize() (asm.Instructions, error) {
blockSym := fmt.Sprintf("block-%d", p.blockID)
p.insts = append(p.insts,
// R0 <- 0
asm.Mov.Imm32(asm.R0, 0).Sym(blockSym),
asm.Mov.Imm32(asm.R0, 0).WithSymbol(blockSym),
asm.Return(),
)
p.blockID = -1
Expand Down
5 changes: 5 additions & 0 deletions cgroup2/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"go.uber.org/goleak"
)

//nolint:staticcheck // Staticcheck false positives for nil pointer deference after t.Fatal
func TestEventChanCleanupOnCgroupRemoval(t *testing.T) {
checkCgroupMode(t)

Expand Down Expand Up @@ -212,6 +213,10 @@ func TestMoveTo(t *testing.T) {
return
}
desProcs, err := destination.Procs(true)
if err != nil {
t.Error(err)
return
}
desMap := make(map[int]bool)
for _, p := range desProcs {
desMap[int(p)] = true
Expand Down