mirror of
https://github.com/containers/podman.git
synced 2025-06-23 10:38:20 +08:00
Add deadcode linter
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
This commit is contained in:
@ -5,10 +5,10 @@ run:
|
|||||||
linters:
|
linters:
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
|
- deadcode
|
||||||
- depguard
|
- depguard
|
||||||
- gofmt
|
- gofmt
|
||||||
- typecheck
|
- typecheck
|
||||||
# - deadcode
|
|
||||||
# - dupl
|
# - dupl
|
||||||
# - errcheck
|
# - errcheck
|
||||||
# - gochecknoglobals
|
# - gochecknoglobals
|
||||||
|
@ -10,17 +10,13 @@ import (
|
|||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/storage"
|
|
||||||
"github.com/fatih/camelcase"
|
"github.com/fatih/camelcase"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
stores = make(map[storage.Store]struct{})
|
|
||||||
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
idTruncLength = 12
|
idTruncLength = 12
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os/user"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func skipTestIfNotRoot(t *testing.T) {
|
|
||||||
u, err := user.Current()
|
|
||||||
if err != nil {
|
|
||||||
t.Skip("Could not determine user. Running without root may cause tests to fail")
|
|
||||||
} else if u.Uid != "0" {
|
|
||||||
t.Skip("tests will fail unless run as root")
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,7 +20,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
STOPPED = "Stopped"
|
|
||||||
RUNNING = "Running"
|
RUNNING = "Running"
|
||||||
PAUSED = "Paused"
|
PAUSED = "Paused"
|
||||||
EXITED = "Exited"
|
EXITED = "Exited"
|
||||||
|
@ -298,17 +298,3 @@ func outputJson(stats []*adapter.PodContainerStats) error {
|
|||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPodsByList(podList []string, r *libpod.Runtime) ([]*libpod.Pod, error) {
|
|
||||||
var (
|
|
||||||
pods []*libpod.Pod
|
|
||||||
)
|
|
||||||
for _, p := range podList {
|
|
||||||
pod, err := r.LookupPod(p)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
pods = append(pods, pod)
|
|
||||||
}
|
|
||||||
return pods, nil
|
|
||||||
}
|
|
||||||
|
@ -19,17 +19,14 @@ import (
|
|||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/containers/libpod/pkg/rootless"
|
"github.com/containers/libpod/pkg/rootless"
|
||||||
"github.com/containers/libpod/pkg/util"
|
"github.com/containers/libpod/pkg/util"
|
||||||
"github.com/cri-o/ocicni/pkg/ocicni"
|
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
"github.com/opentracing/opentracing-go"
|
"github.com/opentracing/opentracing-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
mountTruncLength = 12
|
|
||||||
hid = "CONTAINER ID"
|
hid = "CONTAINER ID"
|
||||||
himage = "IMAGE"
|
himage = "IMAGE"
|
||||||
hcommand = "COMMAND"
|
hcommand = "COMMAND"
|
||||||
@ -38,7 +35,6 @@ const (
|
|||||||
hports = "PORTS"
|
hports = "PORTS"
|
||||||
hnames = "NAMES"
|
hnames = "NAMES"
|
||||||
hsize = "SIZE"
|
hsize = "SIZE"
|
||||||
hinfra = "IS INFRA"
|
|
||||||
hpod = "POD"
|
hpod = "POD"
|
||||||
nspid = "PID"
|
nspid = "PID"
|
||||||
nscgroup = "CGROUPNS"
|
nscgroup = "CGROUPNS"
|
||||||
@ -74,34 +70,6 @@ type psTemplateParams struct {
|
|||||||
IsInfra bool
|
IsInfra bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// psJSONParams is used as a base structure for the psParams
|
|
||||||
// If template output is requested, psJSONParams will be converted to
|
|
||||||
// psTemplateParams.
|
|
||||||
// psJSONParams will be populated by data from libpod.Container,
|
|
||||||
// the members of the struct are the sama data types as their sources.
|
|
||||||
type psJSONParams struct {
|
|
||||||
ID string `json:"id"`
|
|
||||||
Image string `json:"image"`
|
|
||||||
ImageID string `json:"image_id"`
|
|
||||||
Command []string `json:"command"`
|
|
||||||
ExitCode int32 `json:"exitCode"`
|
|
||||||
Exited bool `json:"exited"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
StartedAt time.Time `json:"startedAt"`
|
|
||||||
ExitedAt time.Time `json:"exitedAt"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
PID int `json:"PID"`
|
|
||||||
Ports []ocicni.PortMapping `json:"ports"`
|
|
||||||
Size *shared.ContainerSize `json:"size,omitempty"`
|
|
||||||
Names string `json:"names"`
|
|
||||||
Labels fields.Set `json:"labels"`
|
|
||||||
Mounts []string `json:"mounts"`
|
|
||||||
ContainerRunning bool `json:"ctrRunning"`
|
|
||||||
Namespaces *shared.Namespace `json:"namespace,omitempty"`
|
|
||||||
Pod string `json:"pod,omitempty"`
|
|
||||||
IsInfra bool `json:"infra"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Type declaration and functions for sorting the PS output
|
// Type declaration and functions for sorting the PS output
|
||||||
type psSorted []shared.PsContainerOutput
|
type psSorted []shared.PsContainerOutput
|
||||||
|
|
||||||
@ -447,57 +415,6 @@ func sortPsOutput(sortBy string, psOutput psSorted) (psSorted, error) {
|
|||||||
return psOutput, nil
|
return psOutput, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLabels converts the labels to a string of the form "key=value, key2=value2"
|
|
||||||
func formatLabels(labels map[string]string) string {
|
|
||||||
var arr []string
|
|
||||||
if len(labels) > 0 {
|
|
||||||
for key, val := range labels {
|
|
||||||
temp := key + "=" + val
|
|
||||||
arr = append(arr, temp)
|
|
||||||
}
|
|
||||||
return strings.Join(arr, ",")
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// getMounts converts the volumes mounted to a string of the form "mount1, mount2"
|
|
||||||
// it truncates it if noTrunc is false
|
|
||||||
func getMounts(mounts []string, noTrunc bool) string {
|
|
||||||
return strings.Join(getMountsArray(mounts, noTrunc), ",")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getMountsArray(mounts []string, noTrunc bool) []string {
|
|
||||||
var arr []string
|
|
||||||
if len(mounts) == 0 {
|
|
||||||
return mounts
|
|
||||||
}
|
|
||||||
for _, mount := range mounts {
|
|
||||||
splitArr := strings.Split(mount, ":")
|
|
||||||
if len(splitArr[0]) > mountTruncLength && !noTrunc {
|
|
||||||
arr = append(arr, splitArr[0][:mountTruncLength]+"...")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
arr = append(arr, splitArr[0])
|
|
||||||
}
|
|
||||||
return arr
|
|
||||||
}
|
|
||||||
|
|
||||||
// portsToString converts the ports used to a string of the from "port1, port2"
|
|
||||||
func portsToString(ports []ocicni.PortMapping) string {
|
|
||||||
var portDisplay []string
|
|
||||||
if len(ports) == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
for _, v := range ports {
|
|
||||||
hostIP := v.HostIP
|
|
||||||
if hostIP == "" {
|
|
||||||
hostIP = "0.0.0.0"
|
|
||||||
}
|
|
||||||
portDisplay = append(portDisplay, fmt.Sprintf("%s:%d->%d/%s", hostIP, v.HostPort, v.ContainerPort, v.Protocol))
|
|
||||||
}
|
|
||||||
return strings.Join(portDisplay, ", ")
|
|
||||||
}
|
|
||||||
|
|
||||||
func printFormat(format string, containers []shared.PsContainerOutput) error {
|
func printFormat(format string, containers []shared.PsContainerOutput) error {
|
||||||
// return immediately if no containers are present
|
// return immediately if no containers are present
|
||||||
if len(containers) == 0 {
|
if len(containers) == 0 {
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
sysInfo = sysinfo.New(true)
|
sysInfo = sysinfo.New(true)
|
||||||
cmd = []string{"podman", "test", "alpine"}
|
|
||||||
CLI *cliconfig.PodmanCommand
|
CLI *cliconfig.PodmanCommand
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,11 +12,6 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
descriptionTruncLength = 44
|
|
||||||
maxQueries = 25
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
searchCommand cliconfig.SearchValues
|
searchCommand cliconfig.SearchValues
|
||||||
searchDescription = `Search registries for a given image. Can search all the default registries or a specific registry.
|
searchDescription = `Search registries for a given image. Can search all the default registries or a specific registry.
|
||||||
|
@ -35,11 +35,6 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getContext returns a non-nil, empty context
|
|
||||||
func getContext() context.Context {
|
|
||||||
return context.TODO()
|
|
||||||
}
|
|
||||||
|
|
||||||
func CreateContainer(ctx context.Context, c *cliconfig.PodmanCommand, runtime *libpod.Runtime) (*libpod.Container, *cc.CreateConfig, error) {
|
func CreateContainer(ctx context.Context, c *cliconfig.PodmanCommand, runtime *libpod.Runtime) (*libpod.Container, *cc.CreateConfig, error) {
|
||||||
var (
|
var (
|
||||||
healthCheck *manifest.Schema2HealthConfig
|
healthCheck *manifest.Schema2HealthConfig
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containers/buildah/pkg/formats"
|
"github.com/containers/buildah/pkg/formats"
|
||||||
"github.com/containers/image/types"
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
"github.com/containers/libpod/cmd/podman/cliconfig"
|
||||||
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
"github.com/containers/libpod/cmd/podman/libpodruntime"
|
||||||
"github.com/containers/libpod/libpod/image"
|
"github.com/containers/libpod/libpod/image"
|
||||||
@ -237,10 +236,6 @@ func isValidTrustType(t string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultPolicyPath() string {
|
|
||||||
return trust.DefaultPolicyPath(&types.SystemContext{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func getPolicyJSON(policyContentStruct trust.PolicyContent, systemRegistriesDirPath string) (map[string]map[string]interface{}, error) {
|
func getPolicyJSON(policyContentStruct trust.PolicyContent, systemRegistriesDirPath string) (map[string]map[string]interface{}, error) {
|
||||||
registryConfigs, err := trust.LoadAndMergeConfig(systemRegistriesDirPath)
|
registryConfigs, err := trust.LoadAndMergeConfig(systemRegistriesDirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
gosignal "os/signal"
|
gosignal "os/signal"
|
||||||
|
|
||||||
"github.com/containers/libpod/cmd/podman/cliconfig"
|
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/docker/docker/pkg/signal"
|
"github.com/docker/docker/pkg/signal"
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
@ -159,47 +158,6 @@ func (f *RawTtyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
|||||||
return bytes, err
|
return bytes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// For pod commands that have a latest and all flag, getPodsFromContext gets
|
|
||||||
// pods the user specifies. If there's an error before getting pods, the pods slice
|
|
||||||
// will be empty and error will be not nil. If an error occured after, the pod slice
|
|
||||||
// will hold all of the successful pods, and error will hold the last error.
|
|
||||||
// The remaining errors will be logged. On success, pods will hold all pods and
|
|
||||||
// error will be nil.
|
|
||||||
func getPodsFromContext(c *cliconfig.PodmanCommand, r *libpod.Runtime) ([]*libpod.Pod, error) {
|
|
||||||
args := c.InputArgs
|
|
||||||
var pods []*libpod.Pod
|
|
||||||
var lastError error
|
|
||||||
var err error
|
|
||||||
|
|
||||||
if c.Bool("all") {
|
|
||||||
pods, err = r.GetAllPods()
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "unable to get running pods")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if c.Bool("latest") {
|
|
||||||
pod, err := r.GetLatestPod()
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrapf(err, "unable to get latest pod")
|
|
||||||
}
|
|
||||||
pods = append(pods, pod)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, i := range args {
|
|
||||||
pod, err := r.LookupPod(i)
|
|
||||||
if err != nil {
|
|
||||||
if lastError != nil {
|
|
||||||
logrus.Errorf("%q", lastError)
|
|
||||||
}
|
|
||||||
lastError = errors.Wrapf(err, "unable to find pod %s", i)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
pods = append(pods, pod)
|
|
||||||
}
|
|
||||||
return pods, lastError
|
|
||||||
}
|
|
||||||
|
|
||||||
//printParallelOutput takes the map of parallel worker results and outputs them
|
//printParallelOutput takes the map of parallel worker results and outputs them
|
||||||
// to stdout
|
// to stdout
|
||||||
func printParallelOutput(m map[string]error, errCount int) error {
|
func printParallelOutput(m map[string]error, errCount int) error {
|
||||||
|
@ -30,7 +30,6 @@ var (
|
|||||||
CGROUP_MANAGER = "systemd"
|
CGROUP_MANAGER = "systemd"
|
||||||
ARTIFACT_DIR = "/tmp/.artifacts"
|
ARTIFACT_DIR = "/tmp/.artifacts"
|
||||||
RESTORE_IMAGES = []string{ALPINE, BB}
|
RESTORE_IMAGES = []string{ALPINE, BB}
|
||||||
defaultWaitTimeout = 90
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PodmanTestIntegration struct for command line options
|
// PodmanTestIntegration struct for command line options
|
||||||
|
Reference in New Issue
Block a user