From 868e28042178fb33d70508e3ba9f11891ce9fda4 Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Sun, 4 Nov 2018 15:09:19 +0100 Subject: Lint: Update metalinter dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We fixated on old metalinter dependency in past based on experience of metalinter being oftentimes broke and hence broking our build. See 762f508d9ca97cdbaee6053b663e98aee9cae081 in cri-o for more details. Now, dated metalinter is messing up with my environment (like it is panicing on containters/storage) so let's see if we can move to more current version of metalinter. Signed-off-by: Šimon Lukašík --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 04d6230d6..18d0a0274 100644 --- a/Makefile +++ b/Makefile @@ -283,7 +283,7 @@ install.tools: .install.gitvalidation .install.gometalinter .install.md2man .ins if [ ! -x "$(GOBIN)/gometalinter" ]; then \ $(GO) get -u github.com/alecthomas/gometalinter; \ cd $(FIRST_GOPATH)/src/github.com/alecthomas/gometalinter; \ - git checkout 23261fa046586808612c61da7a81d75a658e0814; \ + git checkout e8d801238da6f0dfd14078d68f9b53fa50a7eeb5; \ $(GO) install github.com/alecthomas/gometalinter; \ $(GOBIN)/gometalinter --install; \ fi -- cgit v1.2.3-54-g00ecf From 9f8f9a0d1b59eddc15ba3523f55e6d3cc872822e Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Sun, 4 Nov 2018 18:50:53 +0100 Subject: Lint: Exclude autogenerated files from lint test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- .tool/lint | 1 + 1 file changed, 1 insertion(+) diff --git a/.tool/lint b/.tool/lint index b7006c8fd..60ba3f32a 100755 --- a/.tool/lint +++ b/.tool/lint @@ -40,6 +40,7 @@ ${LINTER} \ --exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$'\ --exclude='duplicate of.*_test.go.*\(dupl\)$'\ --exclude='cmd\/client\/.*\.go.*\(dupl\)$'\ + --exclude='libpod\/.*_easyjson.go:.*'\ --exclude='vendor\/.*'\ --exclude='podman\/.*'\ --exclude='server\/seccomp\/.*\.go.*$'\ -- cgit v1.2.3-54-g00ecf From 9497b2254ce516d54649592c22a2338dcb2300eb Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Mon, 5 Nov 2018 18:59:57 +0100 Subject: Lint: InspectImage varlink api should return errors that occurred MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not just nil. Addressing: pkg/varlinkapi/images.go:273:15:warning: ineffectual assignment to err (ineffassign) Signed-off-by: Šimon Lukašík --- pkg/varlinkapi/images.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go index d14c61c39..42e285b53 100644 --- a/pkg/varlinkapi/images.go +++ b/pkg/varlinkapi/images.go @@ -271,6 +271,9 @@ func (i *LibpodAPI) InspectImage(call iopodman.VarlinkCall, name string) error { return call.ReplyImageNotFound(name) } inspectInfo, err := newImage.Inspect(getContext()) + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } b, err := json.Marshal(inspectInfo) if err != nil { return call.ReplyErrorOccurred(fmt.Sprintf("unable to serialize")) -- cgit v1.2.3-54-g00ecf From 223d102ec79496a3a7e92d75b32eb9938f461c28 Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Fri, 9 Nov 2018 10:23:24 +0100 Subject: Lint: Do not ignore errors from docker run command when selinux enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redefining err by := operator within block makes this err variable block local. Addressing lint: libpod/oci.go:368:3:warning: ineffectual assignment to err (ineffassign) Signed-off-by: Šimon Lukašík --- libpod/oci.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libpod/oci.go b/libpod/oci.go index 233bacfbb..71da830b5 100644 --- a/libpod/oci.go +++ b/libpod/oci.go @@ -350,7 +350,8 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res // Set the label of the conmon process to be level :s0 // This will allow the container processes to talk to fifo-files // passed into the container by conmon - plabel, err := selinux.CurrentLabel() + var plabel string + plabel, err = selinux.CurrentLabel() if err != nil { childPipe.Close() return errors.Wrapf(err, "Failed to get current SELinux label") @@ -360,7 +361,7 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res runtime.LockOSThread() if c["level"] != "s0" && c["level"] != "" { c["level"] = "s0" - if err := label.SetProcessLabel(c.Get()); err != nil { + if err = label.SetProcessLabel(c.Get()); err != nil { runtime.UnlockOSThread() return err } -- cgit v1.2.3-54-g00ecf From 4e755515300d450139d85354082efdedf6fb5357 Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Fri, 9 Nov 2018 10:40:03 +0100 Subject: Lint: Tests: add missing assertions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addressing: ineffectual assignment to err (ineffassign) Signed-off-by: Šimon Lukašík --- libpod/container_graph_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libpod/container_graph_test.go b/libpod/container_graph_test.go index bba3d7aad..25461f1f4 100644 --- a/libpod/container_graph_test.go +++ b/libpod/container_graph_test.go @@ -205,6 +205,7 @@ func TestBuildContainerGraphFourContainersNoEdges(t *testing.T) { ctr3, err := getTestCtrN("3", tmpDir) assert.NoError(t, err) ctr4, err := getTestCtrN("4", tmpDir) + assert.NoError(t, err) graph, err := buildContainerGraph([]*Container{ctr1, ctr2, ctr3, ctr4}) assert.NoError(t, err) @@ -241,6 +242,7 @@ func TestBuildContainerGraphFourContainersTwoInCycle(t *testing.T) { ctr3, err := getTestCtrN("3", tmpDir) assert.NoError(t, err) ctr4, err := getTestCtrN("4", tmpDir) + assert.NoError(t, err) ctr1.config.IPCNsCtr = ctr2.config.ID ctr2.config.UserNsCtr = ctr1.config.ID @@ -260,6 +262,7 @@ func TestBuildContainerGraphFourContainersAllInCycle(t *testing.T) { ctr3, err := getTestCtrN("3", tmpDir) assert.NoError(t, err) ctr4, err := getTestCtrN("4", tmpDir) + assert.NoError(t, err) ctr1.config.IPCNsCtr = ctr2.config.ID ctr2.config.UserNsCtr = ctr3.config.ID ctr3.config.NetNsCtr = ctr4.config.ID @@ -281,6 +284,7 @@ func TestBuildContainerGraphFourContainersNoneInCycle(t *testing.T) { ctr3, err := getTestCtrN("3", tmpDir) assert.NoError(t, err) ctr4, err := getTestCtrN("4", tmpDir) + assert.NoError(t, err) ctr1.config.IPCNsCtr = ctr2.config.ID ctr1.config.NetNsCtr = ctr3.config.ID ctr2.config.UserNsCtr = ctr3.config.ID -- cgit v1.2.3-54-g00ecf From 7457815ba930fdabff6ee57f4b7ec29d9fbcfcf8 Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Sat, 10 Nov 2018 10:26:57 +0100 Subject: Lint: Extract constant unknownPackage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Addressing goconst warning: 3 other occurrence(s) of "Unknown" found Signed-off-by: Šimon Lukašík --- libpod/oci_linux.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libpod/oci_linux.go b/libpod/oci_linux.go index e6b7cbe4f..b159eae78 100644 --- a/libpod/oci_linux.go +++ b/libpod/oci_linux.go @@ -19,6 +19,8 @@ import ( "golang.org/x/sys/unix" ) +const unknownPackage = "Unknown" + func (r *OCIRuntime) moveConmonToCgroup(ctr *Container, cgroupParent string, cmd *exec.Cmd) error { if os.Geteuid() == 0 { if r.cgroupManager == SystemdCgroupsManager { @@ -112,7 +114,7 @@ func (r *OCIRuntime) createContainer(ctr *Container, cgroupParent string, restor } func rpmVersion(path string) string { - output := "Unknown" + output := unknownPackage cmd := exec.Command("/usr/bin/rpm", "-q", "-f", path) if outp, err := cmd.Output(); err == nil { output = string(outp) @@ -121,7 +123,7 @@ func rpmVersion(path string) string { } func dpkgVersion(path string) string { - output := "Unknown" + output := unknownPackage cmd := exec.Command("/usr/bin/dpkg", "-S", path) if outp, err := cmd.Output(); err == nil { output = string(outp) @@ -130,14 +132,14 @@ func dpkgVersion(path string) string { } func (r *OCIRuntime) pathPackage() string { - if out := rpmVersion(r.path); out != "Unknown" { + if out := rpmVersion(r.path); out != unknownPackage { return out } return dpkgVersion(r.path) } func (r *OCIRuntime) conmonPackage() string { - if out := rpmVersion(r.conmonPath); out != "Unknown" { + if out := rpmVersion(r.conmonPath); out != unknownPackage { return out } return dpkgVersion(r.conmonPath) -- cgit v1.2.3-54-g00ecf From e93834576036ef0a5e1d5867e522d1d90a63d358 Mon Sep 17 00:00:00 2001 From: Šimon Lukašík Date: Sat, 10 Nov 2018 10:44:03 +0100 Subject: Lint: Silence few given goconst lint warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While we have these string literals on repeated on multiple places in the library, I cannot see real tangible benefit extracting these to constants considering following facts: (1) while 'unknown' or 'host' are repeated, they are often times used in different context and thus perhaps worth extra const per each use. (2) while these string literals repeat, the library is full of string literals with special meaning that should be made constants too (3) readability would suffer Signed-off-by: Šimon Lukašík --- .tool/lint | 1 + 1 file changed, 1 insertion(+) diff --git a/.tool/lint b/.tool/lint index 60ba3f32a..f7bf81c1d 100755 --- a/.tool/lint +++ b/.tool/lint @@ -41,6 +41,7 @@ ${LINTER} \ --exclude='duplicate of.*_test.go.*\(dupl\)$'\ --exclude='cmd\/client\/.*\.go.*\(dupl\)$'\ --exclude='libpod\/.*_easyjson.go:.*'\ + --exclude='.* other occurrence\(s\) of "(container|host|tmpfs|unknown)" found in: .*\(goconst\)$'\ --exclude='vendor\/.*'\ --exclude='podman\/.*'\ --exclude='server\/seccomp\/.*\.go.*$'\ -- cgit v1.2.3-54-g00ecf