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

Misc linter nits #2695

Merged
merged 7 commits into from
Dec 4, 2020
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 libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func RemovePaths(paths map[string]string) (err error) {
}
}
if len(paths) == 0 {
//nolint:ineffassign // done to help garbage collecting: opencontainers/runc#2506
//nolint:ineffassign,staticcheck // done to help garbage collecting: opencontainers/runc#2506
paths = make(map[string]string)
return nil
}
Expand Down
19 changes: 3 additions & 16 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,7 @@ var criuFeatures *criurpc.CriuFeatures

func (c *linuxContainer) checkCriuFeatures(criuOpts *CriuOpts, rpcOpts *criurpc.CriuOpts, criuFeat *criurpc.CriuFeatures) error {

var t criurpc.CriuReqType
t = criurpc.CriuReqType_FEATURE_CHECK
t := criurpc.CriuReqType_FEATURE_CHECK

// make sure the features we are looking for are really not from
// some previous check
Expand Down Expand Up @@ -764,11 +763,7 @@ func (c *linuxContainer) checkCriuVersion(minVersion int) error {
const descriptorsFilename = "descriptors.json"

func (c *linuxContainer) addCriuDumpMount(req *criurpc.CriuReq, m *configs.Mount) {
mountDest := m.Destination
if strings.HasPrefix(mountDest, c.config.Rootfs) {
mountDest = mountDest[len(c.config.Rootfs):]
}

mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs)
extMnt := &criurpc.ExtMountMap{
Key: proto.String(mountDest),
Val: proto.String(mountDest),
Expand Down Expand Up @@ -1146,11 +1141,7 @@ func (c *linuxContainer) Checkpoint(criuOpts *CriuOpts) error {
}

func (c *linuxContainer) addCriuRestoreMount(req *criurpc.CriuReq, m *configs.Mount) {
mountDest := m.Destination
if strings.HasPrefix(mountDest, c.config.Rootfs) {
mountDest = mountDest[len(c.config.Rootfs):]
}

mountDest := strings.TrimPrefix(m.Destination, c.config.Rootfs)
extMnt := &criurpc.ExtMountMap{
Key: proto.String(mountDest),
Val: proto.String(m.Source),
Expand Down Expand Up @@ -1810,10 +1801,6 @@ func (c *linuxContainer) saveState(s *State) (retErr error) {
return os.Rename(tmpFile.Name(), stateFilePath)
}

func (c *linuxContainer) deleteState() error {
return os.Remove(filepath.Join(c.root, stateFilename))
}

func (c *linuxContainer) currentStatus() (Status, error) {
if err := c.refreshState(); err != nil {
return -1, err
Expand Down
15 changes: 6 additions & 9 deletions libcontainer/integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ func TestProcessEmptyCaps(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

outputStatus := string(stdout.Bytes())
outputStatus := stdout.String()

lines := strings.Split(outputStatus, "\n")

Expand Down Expand Up @@ -419,7 +419,7 @@ func TestProcessCaps(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

outputStatus := string(stdout.Bytes())
outputStatus := stdout.String()

lines := strings.Split(outputStatus, "\n")

Expand All @@ -444,10 +444,7 @@ func TestProcessCaps(t *testing.T) {
t.Fatal("Could not parse effective caps", err)
}

var netAdminMask uint64
var netAdminBit uint
netAdminBit = 12 // from capability.h
netAdminMask = 1 << netAdminBit
const netAdminMask = 1 << unix.CAP_NET_ADMIN
if effectiveCaps&netAdminMask != netAdminMask {
t.Fatal("CAP_NET_ADMIN is not set as expected")
}
Expand Down Expand Up @@ -483,7 +480,7 @@ func TestAdditionalGroups(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

outputGroups := string(stdout.Bytes())
outputGroups := stdout.String()

// Check that the groups output has the groups that we specified
if !strings.Contains(outputGroups, "audio") {
Expand Down Expand Up @@ -1082,7 +1079,7 @@ func TestSysctl(t *testing.T) {
// Wait for process
waitProcess(&pconfig, t)

shmmniOutput := string(bytes.TrimSpace(stdout.Bytes()))
shmmniOutput := strings.TrimSpace(stdout.String())
if shmmniOutput != "8192" {
t.Fatalf("kernel.shmmni property expected to be 8192, but is %s", shmmniOutput)
}
Expand Down Expand Up @@ -1210,7 +1207,7 @@ func TestOomScoreAdj(t *testing.T) {

// Wait for process
waitProcess(&pconfig, t)
outputOomScoreAdj := string(bytes.TrimSpace(stdout.Bytes()))
outputOomScoreAdj := strings.TrimSpace(stdout.String())

// Check that the oom_score_adj matches the value that was set as part of config.
if outputOomScoreAdj != strconv.Itoa(*config.OomScoreAdj) {
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/integration/execin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestExecInAdditionalGroups(t *testing.T) {
stdinW.Close()
waitProcess(process, t)

outputGroups := string(stdout.Bytes())
outputGroups := stdout.String()

// Check that the groups output has the groups that we specified
if !strings.Contains(outputGroups, "audio") {
Expand Down Expand Up @@ -471,7 +471,7 @@ func TestExecinPassExtraFiles(t *testing.T) {
stdinW.Close()
waitProcess(process, t)

out := string(stdout.Bytes())
out := stdout.String()
// fd 5 is the directory handle for /proc/$$/fd
if out != "0 1 2 3 4 5" {
t.Fatalf("expected to have the file descriptors '0 1 2 3 4 5' passed to exec, got '%s'", out)
Expand Down
5 changes: 3 additions & 2 deletions libcontainer/intelrdt/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package intelrdt

import (
"bufio"
"github.com/sirupsen/logrus"
"io"
"io/ioutil"
"os"
"path/filepath"

"github.com/sirupsen/logrus"
)

var (
Expand All @@ -21,10 +22,10 @@ type monFeatures struct {

func getMonFeatures(intelRdtRoot string) (monFeatures, error) {
file, err := os.Open(filepath.Join(intelRdtRoot, "info", "L3_MON", "mon_features"))
defer file.Close()
if err != nil {
return monFeatures{}, err
}
defer file.Close()
return parseMonFeatures(file)
}

Expand Down