Skip to content

Commit

Permalink
Merge pull request #6557 from rhatdan/lint
Browse files Browse the repository at this point in the history
Turn on More linters
  • Loading branch information
openshift-merge-robot authored Jun 15, 2020
2 parents e94e3fd + 200cfa4 commit f4c3b71
Show file tree
Hide file tree
Showing 74 changed files with 296 additions and 435 deletions.
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ run:
- pkg/spec
- pkg/varlink
- pkg/varlinkapi
- docs/varlink
skip-files:
- iopodman.go
- swagger.go
Expand All @@ -25,10 +26,6 @@ linters:
- gosec
- lll
- maligned
- misspell
- prealloc
- unparam
- nakedret
linters-settings:
errcheck:
check-blank: false
Expand Down
27 changes: 12 additions & 15 deletions cmd/podman/common/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/pkg/errors"
)

func getCPULimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (*specs.LinuxCPU, error) {
func getCPULimits(c *ContainerCLIOpts) *specs.LinuxCPU {
cpu := &specs.LinuxCPU{}
hasLimits := false

Expand Down Expand Up @@ -67,12 +67,12 @@ func getCPULimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string)
}

if !hasLimits {
return nil, nil
return nil
}
return cpu, nil
return cpu
}

func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (*specs.LinuxBlockIO, error) {
func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts) (*specs.LinuxBlockIO, error) {
var err error
io := &specs.LinuxBlockIO{}
hasLimits := false
Expand All @@ -87,7 +87,7 @@ func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (
}

if len(c.BlkIOWeightDevice) > 0 {
if err := parseWeightDevices(c.BlkIOWeightDevice, s); err != nil {
if err := parseWeightDevices(s, c.BlkIOWeightDevice); err != nil {
return nil, err
}
hasLimits = true
Expand Down Expand Up @@ -127,7 +127,7 @@ func getIOLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (
return io, nil
}

func getPidsLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) *specs.LinuxPids {
func getPidsLimits(c *ContainerCLIOpts) *specs.LinuxPids {
pids := &specs.LinuxPids{}
if c.CGroupsMode == "disabled" && c.PIDsLimit != 0 {
return nil
Expand All @@ -146,7 +146,7 @@ func getPidsLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string)
return nil
}

func getMemoryLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string) (*specs.LinuxMemory, error) {
func getMemoryLimits(s *specgen.SpecGenerator, c *ContainerCLIOpts) (*specs.LinuxMemory, error) {
var err error
memory := &specs.LinuxMemory{}
hasLimits := false
Expand Down Expand Up @@ -446,19 +446,16 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
if s.ResourceLimits == nil {
s.ResourceLimits = &specs.LinuxResources{}
}
s.ResourceLimits.Memory, err = getMemoryLimits(s, c, args)
if err != nil {
return err
}
s.ResourceLimits.BlockIO, err = getIOLimits(s, c, args)
s.ResourceLimits.Memory, err = getMemoryLimits(s, c)
if err != nil {
return err
}
s.ResourceLimits.Pids = getPidsLimits(s, c, args)
s.ResourceLimits.CPU, err = getCPULimits(s, c, args)
s.ResourceLimits.BlockIO, err = getIOLimits(s, c)
if err != nil {
return err
}
s.ResourceLimits.Pids = getPidsLimits(c)
s.ResourceLimits.CPU = getCPULimits(c)
if s.ResourceLimits.CPU == nil && s.ResourceLimits.Pids == nil && s.ResourceLimits.BlockIO == nil && s.ResourceLimits.Memory == nil {
s.ResourceLimits = nil
}
Expand Down Expand Up @@ -700,7 +697,7 @@ func makeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, start
return &hc, nil
}

func parseWeightDevices(weightDevs []string, s *specgen.SpecGenerator) error {
func parseWeightDevices(s *specgen.SpecGenerator, weightDevs []string) error {
for _, val := range weightDevs {
split := strings.SplitN(val, ":", 2)
if len(split) != 2 {
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ func init() {
func mount(cmd *cobra.Command, args []string) error {
var (
errs utils.OutputErrors
mrs []mountReporter
)
reports, err := registry.ContainerEngine().ContainerMount(registry.GetContext(), args, mountOpts)
if err != nil {
Expand All @@ -90,6 +89,7 @@ func mount(cmd *cobra.Command, args []string) error {
if mountOpts.Format == "json" {
return printJSON(reports)
}
mrs := make([]mountReporter, 0, len(reports))
for _, r := range reports {
mrs = append(mrs, mountReporter{r})
}
Expand All @@ -110,7 +110,7 @@ func printJSON(reports []*entities.ContainerMountReport) error {
Names []string
Mountpoint string `json:"mountpoint"`
}
var jreports []jreport
jreports := make([]jreport, 0, len(reports))

for _, r := range reports {
jreports = append(jreports, jreport{
Expand Down
9 changes: 5 additions & 4 deletions cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func listFlagSet(flags *pflag.FlagSet) {
_ = flags.MarkHidden("latest")
}
}
func checkFlags(c *cobra.Command, args []string) error {
func checkFlags(c *cobra.Command) error {
// latest, and last are mutually exclusive.
if listOpts.Last >= 0 && listOpts.Latest {
return errors.Errorf("last and latest are mutually exclusive")
Expand Down Expand Up @@ -144,8 +144,7 @@ func getResponses() ([]entities.ListContainer, error) {
}

func ps(cmd *cobra.Command, args []string) error {
var responses []psReporter
if err := checkFlags(cmd, args); err != nil {
if err := checkFlags(cmd); err != nil {
return err
}
for _, f := range filters {
Expand All @@ -172,6 +171,7 @@ func ps(cmd *cobra.Command, args []string) error {
return quietOut(listContainers)
}

responses := make([]psReporter, 0, len(listContainers))
for _, r := range listContainers {
responses = append(responses, psReporter{r})
}
Expand Down Expand Up @@ -351,7 +351,8 @@ func portsToString(ports []ocicni.PortMapping) string {
first int32
last int32
}
var portDisplay []string
portDisplay := []string{}

if len(ports) == 0 {
return ""
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/containers/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func outputStats(reports []*define.ContainerStats) error {
tm.MoveCursor(1, 1)
tm.Flush()
}
var stats []*containerStats
stats := make([]*containerStats, 0, len(reports))
for _, r := range reports {
stats = append(stats, &containerStats{r})
}
Expand Down Expand Up @@ -228,7 +228,7 @@ func outputJSON(stats []*containerStats) error {
BlockIO string `json:"block_io"`
Pids string `json:"pids"`
}
var jstats []jstat
jstats := make([]jstat, 0, len(stats))
for _, j := range stats {
jstats = append(jstats, jstat{
Id: j.ID(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/generate/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {
flags.BoolVarP(&systemdOptions.New, "new", "", false, "Create a new container instead of starting an existing one")
flags.StringVar(&systemdOptions.ContainerPrefix, "container-prefix", "container", "Systemd unit name prefix for containers")
flags.StringVar(&systemdOptions.PodPrefix, "pod-prefix", "pod", "Systemd unit name prefix for pods")
flags.StringVar(&systemdOptions.Separator, "separator", "-", "Systemd unit name seperator between name/id and prefix")
flags.StringVar(&systemdOptions.Separator, "separator", "-", "Systemd unit name separator between name/id and prefix")
flags.SetNormalizeFunc(utils.AliasFlags)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func history(cmd *cobra.Command, args []string) error {
}
return err
}
var hr []historyreporter
hr := make([]historyreporter, 0, len(results.Layers))
for _, l := range results.Layers {
hr = append(hr, historyreporter{l})
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/inspect/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func newInspector(options entities.InspectOptions) (*inspector, error) {
// inspect inspects the specified container/image names or IDs.
func (i *inspector) inspect(namesOrIDs []string) error {
// data - dumping place for inspection results.
var data []interface{}
var data []interface{} //nolint
ctx := context.Background()

if len(namesOrIDs) == 0 {
Expand Down Expand Up @@ -132,7 +132,7 @@ func (i *inspector) inspect(namesOrIDs []string) error {
}

func (i *inspector) inspectAll(ctx context.Context, namesOrIDs []string) ([]interface{}, error) {
var data []interface{}
var data []interface{} //nolint
for _, name := range namesOrIDs {
imgData, err := i.imageEngine.Inspect(ctx, []string{name}, i.options)
if err == nil {
Expand Down
5 changes: 1 addition & 4 deletions cmd/podman/networks/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@ func init() {
}

func networkList(cmd *cobra.Command, args []string) error {
var (
nlprs []ListPrintReports
)

// validate the filter pattern.
if len(networkListOptions.Filter) > 0 {
tokens := strings.Split(networkListOptions.Filter, "=")
Expand All @@ -82,6 +78,7 @@ func networkList(cmd *cobra.Command, args []string) error {
return jsonOut(responses)
}

nlprs := make([]ListPrintReports, 0, len(responses))
for _, r := range responses {
nlprs = append(nlprs, ListPrintReports{r})
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/podman/pods/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func pods(cmd *cobra.Command, args []string) error {
var (
w io.Writer = os.Stdout
row string
lpr []ListPodReporter
)

if psInput.Quiet && len(psInput.Format) > 0 {
Expand Down Expand Up @@ -102,6 +101,7 @@ func pods(cmd *cobra.Command, args []string) error {
return nil
}

lpr := make([]ListPodReporter, 0, len(responses))
for _, r := range responses {
lpr = append(lpr, ListPodReporter{r})
}
Expand Down Expand Up @@ -220,7 +220,7 @@ func (l ListPodReporter) InfraId() string { //nolint
}

func (l ListPodReporter) ContainerIds() string {
var ctrids []string
ctrids := make([]string, 0, len(l.Containers))
for _, c := range l.Containers {
id := c.Id
if !noTrunc {
Expand All @@ -232,15 +232,15 @@ func (l ListPodReporter) ContainerIds() string {
}

func (l ListPodReporter) ContainerNames() string {
var ctrNames []string
ctrNames := make([]string, 0, len(l.Containers))
for _, c := range l.Containers {
ctrNames = append(ctrNames, c.Names)
}
return strings.Join(ctrNames, ",")
}

func (l ListPodReporter) ContainerStatuses() string {
var statuses []string
statuses := make([]string, 0, len(l.Containers))
for _, c := range l.Containers {
statuses = append(statuses, c.Status)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/podman/system/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,13 @@ func printSummary(reports *entities.SystemDfReport, userFormat string) error {

func printVerbose(reports *entities.SystemDfReport) error {
var (
dfImages []*dfImage
dfContainers []*dfContainer
dfVolumes []*dfVolume
w io.Writer = os.Stdout
w io.Writer = os.Stdout
)

// Images
fmt.Print("\nImages space usage:\n\n")
// convert to dfImage for output
dfImages := make([]*dfImage, 0, len(reports.Images))
for _, d := range reports.Images {
dfImages = append(dfImages, &dfImage{SystemDfImageReport: d})
}
Expand All @@ -170,6 +168,7 @@ func printVerbose(reports *entities.SystemDfReport) error {
fmt.Print("\nContainers space usage:\n\n")

// convert to dfContainers for output
dfContainers := make([]*dfContainer, 0, len(reports.Containers))
for _, d := range reports.Containers {
dfContainers = append(dfContainers, &dfContainer{SystemDfContainerReport: d})
}
Expand All @@ -183,6 +182,7 @@ func printVerbose(reports *entities.SystemDfReport) error {
// Volumes
fmt.Print("\nLocal Volumes space usage:\n\n")

dfVolumes := make([]*dfVolume, 0, len(reports.Volumes))
// convert to dfVolume for output
for _, d := range reports.Volumes {
dfVolumes = append(dfVolumes, &dfVolume{SystemDfVolumeReport: d})
Expand Down
4 changes: 1 addition & 3 deletions libpod/boltdb_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ func (s *BoltState) Refresh() error {
return errors.Wrapf(err, "error unmarshalling state for container %s", string(id))
}

if err := resetState(state); err != nil {
return errors.Wrapf(err, "error resetting state for container %s", string(id))
}
resetState(state)

newStateBytes, err := json.Marshal(state)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions libpod/boltdb_state_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,7 @@ func (s *BoltState) getContainerFromDB(id []byte, ctr *Container, ctrsBkt *bolt.
ociRuntime, ok := s.runtime.ociRuntimes[runtimeName]
if !ok {
// Use a MissingRuntime implementation
ociRuntime, err = getMissingRuntime(runtimeName, s.runtime)
if err != nil {
return err
}
ociRuntime = getMissingRuntime(runtimeName, s.runtime)
}
ctr.ociRuntime = ociRuntime
}
Expand Down
4 changes: 2 additions & 2 deletions libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Container) Init(ctx context.Context) (err error) {
}

// don't recursively start
if err := c.checkDependenciesAndHandleError(ctx); err != nil {
if err := c.checkDependenciesAndHandleError(); err != nil {
return err
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func (c *Container) RestartWithTimeout(ctx context.Context, timeout uint) (err e
}
}

if err = c.checkDependenciesAndHandleError(ctx); err != nil {
if err = c.checkDependenciesAndHandleError(); err != nil {
return err
}

Expand Down
Loading

0 comments on commit f4c3b71

Please sign in to comment.