Skip to content

Commit

Permalink
Merge pull request #3552 from baude/golangcilint2
Browse files Browse the repository at this point in the history
golangci-lint pass number 2
  • Loading branch information
openshift-merge-robot authored Jul 11, 2019
2 parents 2b64f88 + a78c885 commit d614372
Show file tree
Hide file tree
Showing 30 changed files with 138 additions and 130 deletions.
3 changes: 0 additions & 3 deletions cmd/podman/pod_ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,6 @@ func generatePodPsOutput(pods []*adapter.Pod, opts podPsOptions) error {

switch opts.Format {
case formats.JSONString:
if err != nil {
return errors.Wrapf(err, "unable to create JSON for output")
}
out = formats.JSONStructArray{Output: podPsToGeneric([]podPsTemplateParams{}, psOutput)}
default:
psOutput, err := getPodTemplateOutput(psOutput, opts)
Expand Down
5 changes: 4 additions & 1 deletion cmd/podman/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ func psDisplay(c *cliconfig.PsValues, runtime *adapter.LocalRuntime) error {
}

pss, err := runtime.Ps(c, opts)
if err != nil {
return err
}
// Here and down
if opts.Sort != "" {
pss, err = sortPsOutput(opts.Sort, pss)
Expand Down Expand Up @@ -376,8 +379,8 @@ func psDisplay(c *cliconfig.PsValues, runtime *adapter.LocalRuntime) error {
size = units.HumanSizeWithPrecision(0, 0)
} else {
size = units.HumanSizeWithPrecision(float64(container.Size.RwSize), 3) + " (virtual " + units.HumanSizeWithPrecision(float64(container.Size.RootFsSize), 3) + ")"
fmt.Fprintf(w, "\t%s", size)
}
fmt.Fprintf(w, "\t%s", size)
}

} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/podman/shared/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func generateContainerFilterFuncs(filter, filterValue string, r *libpod.Runtime)
}
return func(c *libpod.Container) bool {
ec, exited, err := c.ExitCode()
if ec == int32(exitCode) && err == nil && exited == true {
if ec == int32(exitCode) && err == nil && exited {
return true
}
return false
Expand Down Expand Up @@ -611,7 +611,7 @@ func getNamespaceInfo(path string) (string, error) {

// getStrFromSquareBrackets gets the string inside [] from a string
func getStrFromSquareBrackets(cmd string) string {
reg, err := regexp.Compile(".*\\[|\\].*")
reg, err := regexp.Compile(`.*\[|\].*`)
if err != nil {
return ""
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/shared/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ func CreateContainer(ctx context.Context, c *GenericCLIResults, runtime *libpod.
imageName = newImage.ID()
}

var healthCheckCommandInput string
// if the user disabled the healthcheck with "none", we skip adding it
healthCheckCommandInput = c.String("healthcheck-command")
healthCheckCommandInput := c.String("healthcheck-command")

// the user didnt disable the healthcheck but did pass in a healthcheck command
// now we need to make a healthcheck from the commandline input
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/shared/create_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func verifyContainerResources(config *cc.CreateConfig, update bool) ([]string, e
if config.Resources.KernelMemory > 0 && config.Resources.KernelMemory < linuxMinMemory {
return warnings, fmt.Errorf("minimum kernel memory limit allowed is 4MB")
}
if config.Resources.DisableOomKiller == true && !sysInfo.OomKillDisable {
if config.Resources.DisableOomKiller && !sysInfo.OomKillDisable {
// only produce warnings if the setting wasn't to *disable* the OOM Kill; no point
// warning the caller if they already wanted the feature to be off
warnings = addWarning(warnings, "Your kernel does not support OomKillDisable. OomKillDisable discarded.")
Expand Down
3 changes: 1 addition & 2 deletions cmd/podman/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ func statsCmd(c *cliconfig.StatsValues) error {
}

var ctrs []*libpod.Container
var containerFunc func() ([]*libpod.Container, error)

containerFunc = runtime.GetRunningContainers
containerFunc := runtime.GetRunningContainers
if len(c.InputArgs) > 0 {
containerFunc = func() ([]*libpod.Container, error) { return runtime.GetContainersByList(c.InputArgs) }
} else if latest {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func printImageChildren(layerMap map[string]*image.LayerInfo, layerID string, pr
if !ok {
return fmt.Errorf("lookup error: layerid %s, not found", layerID)
}
fmt.Printf(prefix)
fmt.Print(prefix)

//initialize intend with middleItem to reduce middleItem checks.
intend := middleItem
Expand Down
15 changes: 3 additions & 12 deletions libpod/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,32 +639,23 @@ func (c *Container) HostsAdd() []string {
// trigger some OCI hooks.
func (c *Container) UserVolumes() []string {
volumes := make([]string, 0, len(c.config.UserVolumes))
for _, vol := range c.config.UserVolumes {
volumes = append(volumes, vol)
}

volumes = append(volumes, c.config.UserVolumes...)
return volumes
}

// Entrypoint is the container's entrypoint.
// This is not added to the spec, but is instead used during image commit.
func (c *Container) Entrypoint() []string {
entrypoint := make([]string, 0, len(c.config.Entrypoint))
for _, str := range c.config.Entrypoint {
entrypoint = append(entrypoint, str)
}

entrypoint = append(entrypoint, c.config.Entrypoint...)
return entrypoint
}

// Command is the container's command
// This is not added to the spec, but is instead used during image commit
func (c *Container) Command() []string {
command := make([]string, 0, len(c.config.Command))
for _, str := range c.config.Command {
command = append(command, str)
}

command = append(command, c.config.Command...)
return command
}

Expand Down
2 changes: 1 addition & 1 deletion libpod/container_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (c *Container) Exec(tty, privileged bool, env, cmd []string, user, workDir
break
}
}
if found == true {
if found {
sessionID = stringid.GenerateNonCryptoID()
}
}
Expand Down
2 changes: 0 additions & 2 deletions libpod/container_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,4 @@ func startNode(ctx context.Context, node *containerNode, setError bool, ctrError
for _, successor := range node.dependedOn {
startNode(ctx, successor, ctrErrored, ctrErrors, ctrsVisited, restart)
}

return
}
8 changes: 2 additions & 6 deletions libpod/container_inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,7 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) (*InspectCon
if spec.Process != nil {
ctrConfig.Tty = spec.Process.Terminal
ctrConfig.Env = []string{}
for _, val := range spec.Process.Env {
ctrConfig.Env = append(ctrConfig.Env, val)
}
ctrConfig.Env = append(ctrConfig.Env, spec.Process.Env...)
ctrConfig.WorkingDir = spec.Process.Cwd
}

Expand All @@ -466,9 +464,7 @@ func (c *Container) generateInspectContainerConfig(spec *spec.Spec) (*InspectCon
// Leave empty is not explicitly overwritten by user
if len(c.config.Command) != 0 {
ctrConfig.Cmd = []string{}
for _, val := range c.config.Command {
ctrConfig.Cmd = append(ctrConfig.Cmd, val)
}
ctrConfig.Cmd = append(ctrConfig.Cmd, c.config.Command...)
}

// Leave empty if not explicitly overwritten by user
Expand Down
28 changes: 0 additions & 28 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,34 +815,6 @@ func (c *Container) checkDependenciesRunning() ([]string, error) {
return notRunning, nil
}

// Check if a container's dependencies are running
// Returns a []string containing the IDs of dependencies that are not running
// Assumes depencies are already locked, and will be passed in
// Accepts a map[string]*Container containing, at a minimum, the locked
// dependency containers
// (This must be a map from container ID to container)
func (c *Container) checkDependenciesRunningLocked(depCtrs map[string]*Container) ([]string, error) {
deps := c.Dependencies()
notRunning := []string{}

for _, dep := range deps {
depCtr, ok := depCtrs[dep]
if !ok {
return nil, errors.Wrapf(define.ErrNoSuchCtr, "container %s depends on container %s but it is not on containers passed to checkDependenciesRunning", c.ID(), dep)
}

if err := c.syncContainer(); err != nil {
return nil, err
}

if depCtr.state.State != define.ContainerStateRunning {
notRunning = append(notRunning, dep)
}
}

return notRunning, nil
}

func (c *Container) completeNetworkSetup() error {
netDisabled, err := c.NetworkDisabled()
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions libpod/events/filters.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package events

import (
"fmt"
"strings"
"time"

Expand All @@ -23,7 +22,7 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
}, nil
case "EVENT", "STATUS":
return func(e *Event) bool {
return fmt.Sprintf("%s", e.Status) == filterValue
return string(e.Status) == filterValue
}, nil
case "IMAGE":
return func(e *Event) bool {
Expand Down Expand Up @@ -54,7 +53,7 @@ func generateEventFilter(filter, filterValue string) (func(e *Event) bool, error
}, nil
case "TYPE":
return func(e *Event) bool {
return fmt.Sprintf("%s", e.Type) == filterValue
return string(e.Type) == filterValue
}, nil
}
return nil, errors.Errorf("%s is an invalid filter", filter)
Expand Down
3 changes: 1 addition & 2 deletions libpod/events/nullout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func (e EventToNull) Read(options ReadOptions) error {
// NewNullEventer returns a new null eventer. You should only do this for
// the purposes on internal libpod testing.
func NewNullEventer() Eventer {
var e Eventer
e = EventToNull{}
e := EventToNull{}
return e
}
2 changes: 1 addition & 1 deletion libpod/healthcheck_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Container) createTimer() error {
if rootless.IsRootless() {
cmd = append(cmd, "--user")
}
cmd = append(cmd, "--unit", fmt.Sprintf("%s", c.ID()), fmt.Sprintf("--on-unit-inactive=%s", c.HealthCheckConfig().Interval.String()), "--timer-property=AccuracySec=1s", podman, "healthcheck", "run", c.ID())
cmd = append(cmd, "--unit", c.ID(), fmt.Sprintf("--on-unit-inactive=%s", c.HealthCheckConfig().Interval.String()), "--timer-property=AccuracySec=1s", podman, "healthcheck", "run", c.ID())

conn, err := getConnection()
if err != nil {
Expand Down
30 changes: 21 additions & 9 deletions libpod/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ func getImageDigest(ctx context.Context, src types.ImageReference, sc *types.Sys
if err != nil {
return "", err
}
defer newImg.Close()
defer func() {
if err := newImg.Close(); err != nil {
logrus.Errorf("failed to close image: %q", err)
}
}()
imageDigest := newImg.ConfigInfo().Digest
if err = imageDigest.Validate(); err != nil {
return "", errors.Wrapf(err, "error getting config info")
Expand Down Expand Up @@ -513,7 +517,7 @@ func (i *Image) TagImage(tag string) error {
if err := i.reloadImage(); err != nil {
return err
}
defer i.newImageEvent(events.Tag)
i.newImageEvent(events.Tag)
return nil
}

Expand All @@ -538,7 +542,7 @@ func (i *Image) UntagImage(tag string) error {
if err := i.reloadImage(); err != nil {
return err
}
defer i.newImageEvent(events.Untag)
i.newImageEvent(events.Untag)
return nil
}

Expand Down Expand Up @@ -574,7 +578,11 @@ func (i *Image) PushImageToReference(ctx context.Context, dest types.ImageRefere
if err != nil {
return err
}
defer policyContext.Destroy()
defer func() {
if err := policyContext.Destroy(); err != nil {
logrus.Errorf("failed to destroy policy context: %q", err)
}
}()

// Look up the source image, expecting it to be in local storage
src, err := is.Transport.ParseStoreReference(i.imageruntime.store, i.ID())
Expand All @@ -588,7 +596,7 @@ func (i *Image) PushImageToReference(ctx context.Context, dest types.ImageRefere
if err != nil {
return errors.Wrapf(err, "Error copying image to the remote destination")
}
defer i.newImageEvent(events.Push)
i.newImageEvent(events.Push)
return nil
}

Expand Down Expand Up @@ -984,19 +992,23 @@ func (ir *Runtime) Import(ctx context.Context, path, reference string, writer io
if err != nil {
return nil, err
}
defer policyContext.Destroy()
defer func() {
if err := policyContext.Destroy(); err != nil {
logrus.Errorf("failed to destroy policy context: %q", err)
}
}()
copyOptions := getCopyOptions(sc, writer, nil, nil, signingOptions, "", nil)
dest, err := is.Transport.ParseStoreReference(ir.store, reference)
if err != nil {
errors.Wrapf(err, "error getting image reference for %q", reference)
return nil, errors.Wrapf(err, "error getting image reference for %q", reference)
}
_, err = cp.Image(ctx, policyContext, dest, src, copyOptions)
if err != nil {
return nil, err
}
newImage, err := ir.NewFromLocal(reference)
if err == nil {
defer newImage.newImageEvent(events.Import)
newImage.newImageEvent(events.Import)
}
return newImage, err
}
Expand Down Expand Up @@ -1339,7 +1351,7 @@ func (i *Image) Save(ctx context.Context, source, format, output string, moreTag
if err := i.PushImageToReference(ctx, destRef, manifestType, "", "", writer, compress, SigningOptions{}, &DockerRegistryOptions{}, additionaltags); err != nil {
return errors.Wrapf(err, "unable to save %q", source)
}
defer i.newImageEvent(events.Save)
i.newImageEvent(events.Save)
return nil
}

Expand Down
8 changes: 6 additions & 2 deletions libpod/image/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,11 @@ func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goa
if err != nil {
return nil, err
}
defer policyContext.Destroy()
defer func() {
if err := policyContext.Destroy(); err != nil {
logrus.Errorf("failed to destroy policy context: %q", err)
}
}()

systemRegistriesConfPath := registries.SystemRegistriesConfPath()

Expand Down Expand Up @@ -304,7 +308,7 @@ func (ir *Runtime) doPullImage(ctx context.Context, sc *types.SystemContext, goa
return nil, pullErrors
}
if len(images) > 0 {
defer ir.newImageEvent(events.Pull, images[0])
ir.newImageEvent(events.Pull, images[0])
}
return images, nil
}
Expand Down
3 changes: 1 addition & 2 deletions libpod/kube.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package libpod

import (
"fmt"
"math/rand"
"os"
"strconv"
Expand Down Expand Up @@ -179,7 +178,7 @@ func addContainersAndVolumesToPodObject(containers []v1.Container, volumes []v1.
labels["app"] = removeUnderscores(podName)
om := v12.ObjectMeta{
// The name of the pod is container_name-libpod
Name: fmt.Sprintf("%s", removeUnderscores(podName)),
Name: removeUnderscores(podName),
Labels: labels,
// CreationTimestamp seems to be required, so adding it; in doing so, the timestamp
// will reflect time this is run (not container create time) because the conversion
Expand Down
5 changes: 1 addition & 4 deletions libpod/logs/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,5 @@ func NewLogLine(line string) (*LogLine, error) {

// Partial returns a bool if the log line is a partial log type
func (l *LogLine) Partial() bool {
if l.ParseLogType == PartialLogType {
return true
}
return false
return l.ParseLogType == PartialLogType
}
Loading

0 comments on commit d614372

Please sign in to comment.