Skip to content

Commit d86729e

Browse files
Merge pull request #2865 from baude/pr/2864
Revert "Switch to golangci-lint"
2 parents bc320be + 23602de commit d86729e

File tree

15 files changed

+261
-67
lines changed

15 files changed

+261
-67
lines changed

.cirrus.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ gating_task:
121121

122122
gate_script:
123123
# N/B: entrypoint.sh resets $GOSRC (same as make clean)
124+
- '/usr/local/bin/entrypoint.sh install.tools'
124125
- '/usr/local/bin/entrypoint.sh validate'
125126
- '/usr/local/bin/entrypoint.sh lint'
126127
- '${CIRRUS_WORKING_DIR}/${SCRIPT_BASE}/test/test_dot_cirrus_yaml.py'

.golangci.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.tool/lint

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
# Create the linter path for use later
8+
LINTER=${GOPATH}/bin/gometalinter
9+
10+
# Make sure gometalinter is installed
11+
if [ ! -f ${LINTER} ]; then
12+
echo >&2 "gometalinter must be installed. Please run 'make install.tools' and try again"
13+
exit 1
14+
fi
15+
16+
PKGS=$(find . -type d -not -path . -a -not -iwholename '*.git*' -a -not -iname '.tool' -a -not -iwholename '*vendor*' -a -not -iname 'hack' -a -not -iwholename '*.artifacts*' -a -not -iwholename '*contrib*' -a -not -iwholename '*test*' -a -not -iwholename '*logo*' -a -not -iwholename '*conmon*' -a -not -iwholename '*completions*' -a -not -iwholename '*docs*' -a -not -iwholename '*pause*' -a -not -iwholename './_output*' -a -not -iwholename '*ioprojectatomicpodman.go')
17+
18+
echo $PKGS
19+
20+
# Execute the linter
21+
${LINTER} \
22+
--concurrency=4\
23+
--enable-gc\
24+
--vendored-linters\
25+
--deadline=600s --disable-all\
26+
--enable=deadcode\
27+
--enable=errcheck\
28+
--enable=goconst\
29+
--enable=gofmt\
30+
--enable=golint\
31+
--enable=ineffassign\
32+
--enable=megacheck\
33+
--enable=misspell\
34+
--enable=structcheck\
35+
--enable=varcheck\
36+
--enable=vet\
37+
--enable=vetshadow\
38+
--exclude='error return value not checked.*\(errcheck\)$'\
39+
--exclude='declaration of.*err.*shadows declaration.*\(vetshadow\)$'\
40+
--exclude='.*_test\.go:.*error return value not checked.*\(errcheck\)$'\
41+
--exclude='duplicate of.*_test.go.*\(dupl\)$'\
42+
--exclude='cmd\/client\/.*\.go.*\(dupl\)$'\
43+
--exclude='libpod\/.*_easyjson.go:.*'\
44+
--exclude='.* other occurrence\(s\) of "(container|host|tmpfs|unknown)" found in: .*\(goconst\)$'\
45+
--exclude='vendor\/.*'\
46+
--exclude='podman\/.*'\
47+
--exclude='server\/seccomp\/.*\.go.*$'\
48+
${PKGS[@]}

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ endif
9898
touch $@
9999

100100
lint: .gopathok varlink_generate ## Execute the source code linter
101-
golangci-lint run --build-tags="$(BUILDTAGS)"
101+
@echo "checking lint"
102+
@./.tool/lint
102103

103104
gofmt: ## Verify the source code gofmt
104105
find . -name '*.go' ! -path './vendor/*' -exec gofmt -s -w {} \+
@@ -279,7 +280,7 @@ uninstall:
279280

280281
.PHONY: install.tools
281282

282-
install.tools: .install.gitvalidation .install.golangci-lint .install.md2man .install.ginkgo ## Install needed tools
283+
install.tools: .install.gitvalidation .install.gometalinter .install.md2man .install.ginkgo ## Install needed tools
283284

284285
.install.vndr: .gopathok
285286
$(GO) get -u github.com/LK4D4/vndr
@@ -294,10 +295,13 @@ install.tools: .install.gitvalidation .install.golangci-lint .install.md2man .in
294295
$(GO) get -u github.com/vbatts/git-validation; \
295296
fi
296297

297-
.install.golangci-lint: .gopathok
298-
if [ ! -x "$(GOBIN)/golangci-lint" ]; then \
299-
curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh |\
300-
sh -s -- -b $(GOBIN) v1.15.0 ;\
298+
.install.gometalinter: .gopathok
299+
if [ ! -x "$(GOBIN)/gometalinter" ]; then \
300+
$(GO) get -u github.com/alecthomas/gometalinter; \
301+
cd $(FIRST_GOPATH)/src/github.com/alecthomas/gometalinter; \
302+
git checkout e8d801238da6f0dfd14078d68f9b53fa50a7eeb5; \
303+
$(GO) install github.com/alecthomas/gometalinter; \
304+
$(GOBIN)/gometalinter --install; \
301305
fi
302306

303307
.install.md2man: .gopathok

cmd/podman/common.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ import (
1010
"github.com/containers/libpod/cmd/podman/cliconfig"
1111
"github.com/containers/libpod/libpod"
1212
"github.com/containers/libpod/pkg/rootless"
13+
"github.com/containers/storage"
1314
"github.com/fatih/camelcase"
1415
jsoniter "github.com/json-iterator/go"
1516
"github.com/pkg/errors"
1617
"github.com/spf13/cobra"
1718
)
1819

19-
var json = jsoniter.ConfigCompatibleWithStandardLibrary
20+
var (
21+
stores = make(map[storage.Store]struct{})
22+
json = jsoniter.ConfigCompatibleWithStandardLibrary
23+
)
2024

2125
const (
2226
idTruncLength = 12

cmd/podman/common_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"os/user"
5+
"testing"
6+
)
7+
8+
func skipTestIfNotRoot(t *testing.T) {
9+
u, err := user.Current()
10+
if err != nil {
11+
t.Skip("Could not determine user. Running without root may cause tests to fail")
12+
} else if u.Uid != "0" {
13+
t.Skip("tests will fail unless run as root")
14+
}
15+
}

cmd/podman/pod_ps.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
)
2121

2222
const (
23+
STOPPED = "Stopped"
2324
RUNNING = "Running"
2425
PAUSED = "Paused"
2526
EXITED = "Exited"

cmd/podman/pod_stats.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,3 +298,17 @@ func outputJson(stats []*adapter.PodContainerStats) error {
298298
fmt.Println(string(b))
299299
return nil
300300
}
301+
302+
func getPodsByList(podList []string, r *libpod.Runtime) ([]*libpod.Pod, error) {
303+
var (
304+
pods []*libpod.Pod
305+
)
306+
for _, p := range podList {
307+
pod, err := r.LookupPod(p)
308+
if err != nil {
309+
return nil, err
310+
}
311+
pods = append(pods, pod)
312+
}
313+
return pods, nil
314+
}

cmd/podman/ps.go

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,35 @@ import (
1818
"github.com/containers/libpod/cmd/podman/shared"
1919
"github.com/containers/libpod/libpod"
2020
"github.com/containers/libpod/pkg/util"
21+
"github.com/cri-o/ocicni/pkg/ocicni"
2122
"github.com/docker/go-units"
2223
"github.com/opentracing/opentracing-go"
2324
"github.com/pkg/errors"
2425
"github.com/sirupsen/logrus"
2526
"github.com/spf13/cobra"
27+
"k8s.io/apimachinery/pkg/fields"
2628
)
2729

2830
const (
29-
hid = "CONTAINER ID"
30-
himage = "IMAGE"
31-
hcommand = "COMMAND"
32-
hcreated = "CREATED"
33-
hstatus = "STATUS"
34-
hports = "PORTS"
35-
hnames = "NAMES"
36-
hsize = "SIZE"
37-
hpod = "POD"
38-
nspid = "PID"
39-
nscgroup = "CGROUPNS"
40-
nsipc = "IPC"
41-
nsmnt = "MNT"
42-
nsnet = "NET"
43-
nspidns = "PIDNS"
44-
nsuserns = "USERNS"
45-
nsuts = "UTS"
31+
mountTruncLength = 12
32+
hid = "CONTAINER ID"
33+
himage = "IMAGE"
34+
hcommand = "COMMAND"
35+
hcreated = "CREATED"
36+
hstatus = "STATUS"
37+
hports = "PORTS"
38+
hnames = "NAMES"
39+
hsize = "SIZE"
40+
hinfra = "IS INFRA"
41+
hpod = "POD"
42+
nspid = "PID"
43+
nscgroup = "CGROUPNS"
44+
nsipc = "IPC"
45+
nsmnt = "MNT"
46+
nsnet = "NET"
47+
nspidns = "PIDNS"
48+
nsuserns = "USERNS"
49+
nsuts = "UTS"
4650
)
4751

4852
type psTemplateParams struct {
@@ -69,6 +73,34 @@ type psTemplateParams struct {
6973
IsInfra bool
7074
}
7175

76+
// psJSONParams is used as a base structure for the psParams
77+
// If template output is requested, psJSONParams will be converted to
78+
// psTemplateParams.
79+
// psJSONParams will be populated by data from libpod.Container,
80+
// the members of the struct are the sama data types as their sources.
81+
type psJSONParams struct {
82+
ID string `json:"id"`
83+
Image string `json:"image"`
84+
ImageID string `json:"image_id"`
85+
Command []string `json:"command"`
86+
ExitCode int32 `json:"exitCode"`
87+
Exited bool `json:"exited"`
88+
CreatedAt time.Time `json:"createdAt"`
89+
StartedAt time.Time `json:"startedAt"`
90+
ExitedAt time.Time `json:"exitedAt"`
91+
Status string `json:"status"`
92+
PID int `json:"PID"`
93+
Ports []ocicni.PortMapping `json:"ports"`
94+
Size *shared.ContainerSize `json:"size,omitempty"`
95+
Names string `json:"names"`
96+
Labels fields.Set `json:"labels"`
97+
Mounts []string `json:"mounts"`
98+
ContainerRunning bool `json:"ctrRunning"`
99+
Namespaces *shared.Namespace `json:"namespace,omitempty"`
100+
Pod string `json:"pod,omitempty"`
101+
IsInfra bool `json:"infra"`
102+
}
103+
72104
// Type declaration and functions for sorting the PS output
73105
type psSorted []shared.PsContainerOutput
74106

@@ -411,6 +443,57 @@ func sortPsOutput(sortBy string, psOutput psSorted) (psSorted, error) {
411443
return psOutput, nil
412444
}
413445

446+
// getLabels converts the labels to a string of the form "key=value, key2=value2"
447+
func formatLabels(labels map[string]string) string {
448+
var arr []string
449+
if len(labels) > 0 {
450+
for key, val := range labels {
451+
temp := key + "=" + val
452+
arr = append(arr, temp)
453+
}
454+
return strings.Join(arr, ",")
455+
}
456+
return ""
457+
}
458+
459+
// getMounts converts the volumes mounted to a string of the form "mount1, mount2"
460+
// it truncates it if noTrunc is false
461+
func getMounts(mounts []string, noTrunc bool) string {
462+
return strings.Join(getMountsArray(mounts, noTrunc), ",")
463+
}
464+
465+
func getMountsArray(mounts []string, noTrunc bool) []string {
466+
var arr []string
467+
if len(mounts) == 0 {
468+
return mounts
469+
}
470+
for _, mount := range mounts {
471+
splitArr := strings.Split(mount, ":")
472+
if len(splitArr[0]) > mountTruncLength && !noTrunc {
473+
arr = append(arr, splitArr[0][:mountTruncLength]+"...")
474+
continue
475+
}
476+
arr = append(arr, splitArr[0])
477+
}
478+
return arr
479+
}
480+
481+
// portsToString converts the ports used to a string of the from "port1, port2"
482+
func portsToString(ports []ocicni.PortMapping) string {
483+
var portDisplay []string
484+
if len(ports) == 0 {
485+
return ""
486+
}
487+
for _, v := range ports {
488+
hostIP := v.HostIP
489+
if hostIP == "" {
490+
hostIP = "0.0.0.0"
491+
}
492+
portDisplay = append(portDisplay, fmt.Sprintf("%s:%d->%d/%s", hostIP, v.HostPort, v.ContainerPort, v.Protocol))
493+
}
494+
return strings.Join(portDisplay, ", ")
495+
}
496+
414497
func printFormat(format string, containers []shared.PsContainerOutput) error {
415498
// return immediately if no containers are present
416499
if len(containers) == 0 {

cmd/podman/run_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
var (
2020
sysInfo = sysinfo.New(true)
21+
cmd = []string{"podman", "test", "alpine"}
2122
CLI *cliconfig.PodmanCommand
2223
)
2324

0 commit comments

Comments
 (0)