mirror of
https://github.com/containers/podman.git
synced 2025-12-02 19:28:58 +08:00
Merge pull request #3552 from baude/golangcilint2
golangci-lint pass number 2
This commit is contained in:
@@ -639,10 +639,7 @@ 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
|
||||
}
|
||||
|
||||
@@ -650,10 +647,7 @@ func (c *Container) UserVolumes() []string {
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -661,10 +655,7 @@ func (c *Container) Entrypoint() []string {
|
||||
// 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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package events
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -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 {
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -984,11 +992,15 @@ 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 {
|
||||
@@ -996,7 +1008,7 @@ func (ir *Runtime) Import(ctx context.Context, path, reference string, writer io
|
||||
}
|
||||
newImage, err := ir.NewFromLocal(reference)
|
||||
if err == nil {
|
||||
defer newImage.newImageEvent(events.Import)
|
||||
newImage.newImageEvent(events.Import)
|
||||
}
|
||||
return newImage, err
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package libpod
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package libpod
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"github.com/containers/libpod/pkg/errorhandling"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
|
||||
cnitypes "github.com/containernetworking/cni/pkg/types/current"
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
"github.com/containers/libpod/pkg/errorhandling"
|
||||
"github.com/containers/libpod/pkg/firewall"
|
||||
"github.com/containers/libpod/pkg/netns"
|
||||
"github.com/containers/libpod/pkg/rootless"
|
||||
@@ -151,8 +151,8 @@ func checkSlirpFlags(path string) (bool, bool, error) {
|
||||
|
||||
// Configure the network namespace for a rootless container
|
||||
func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
|
||||
defer ctr.rootlessSlirpSyncR.Close()
|
||||
defer ctr.rootlessSlirpSyncW.Close()
|
||||
defer errorhandling.CloseQuiet(ctr.rootlessSlirpSyncR)
|
||||
defer errorhandling.CloseQuiet(ctr.rootlessSlirpSyncW)
|
||||
|
||||
path := r.config.NetworkCmdPath
|
||||
|
||||
@@ -201,7 +201,11 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
|
||||
if err := cmd.Start(); err != nil {
|
||||
return errors.Wrapf(err, "failed to start slirp4netns process")
|
||||
}
|
||||
defer cmd.Process.Release()
|
||||
defer func() {
|
||||
if err := cmd.Process.Release(); err != nil {
|
||||
logrus.Errorf("unable to release comman process: %q", err)
|
||||
}
|
||||
}()
|
||||
|
||||
b := make([]byte, 16)
|
||||
for {
|
||||
@@ -268,7 +272,11 @@ func (r *Runtime) setupRootlessNetNS(ctr *Container) (err error) {
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "cannot open connection to %s", apiSocket)
|
||||
}
|
||||
defer conn.Close()
|
||||
defer func() {
|
||||
if err := conn.Close(); err != nil {
|
||||
logrus.Errorf("unable to close connection: %q", err)
|
||||
}
|
||||
}()
|
||||
hostIP := i.HostIP
|
||||
if hostIP == "" {
|
||||
hostIP = "0.0.0.0"
|
||||
|
||||
@@ -273,7 +273,9 @@ func (r *OCIRuntime) updateContainerStatus(ctr *Container, useRuntime bool) erro
|
||||
}
|
||||
return errors.Wrapf(err, "error getting container %s state. stderr/out: %s", ctr.ID(), out)
|
||||
}
|
||||
defer cmd.Wait()
|
||||
defer func() {
|
||||
_ = cmd.Wait()
|
||||
}()
|
||||
|
||||
if err := errPipe.Close(); err != nil {
|
||||
return err
|
||||
|
||||
@@ -124,7 +124,11 @@ func (r *OCIRuntime) createContainer(ctr *Container, cgroupParent string, restor
|
||||
if err = unix.Unshare(unix.CLONE_NEWNS); err != nil {
|
||||
return err
|
||||
}
|
||||
defer unix.Setns(int(fd.Fd()), unix.CLONE_NEWNS)
|
||||
defer func() {
|
||||
if err := unix.Setns(int(fd.Fd()), unix.CLONE_NEWNS); err != nil {
|
||||
logrus.Errorf("unable to clone new namespace: %q", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// don't spread our mounts around. We are setting only /sys to be slave
|
||||
// so that the cleanup process is still able to umount the storage and the
|
||||
@@ -376,7 +380,9 @@ func (r *OCIRuntime) createOCIContainer(ctr *Container, cgroupParent string, res
|
||||
errorhandling.CloseQuiet(childPipe)
|
||||
return err
|
||||
}
|
||||
defer cmd.Wait()
|
||||
defer func() {
|
||||
_ = cmd.Wait()
|
||||
}()
|
||||
|
||||
// We don't need childPipe on the parent side
|
||||
if err := childPipe.Close(); err != nil {
|
||||
|
||||
@@ -1152,10 +1152,7 @@ func WithUserVolumes(volumes []string) CtrCreateOption {
|
||||
}
|
||||
|
||||
ctr.config.UserVolumes = make([]string, 0, len(volumes))
|
||||
for _, vol := range volumes {
|
||||
ctr.config.UserVolumes = append(ctr.config.UserVolumes, vol)
|
||||
}
|
||||
|
||||
ctr.config.UserVolumes = append(ctr.config.UserVolumes, volumes...)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -1172,10 +1169,7 @@ func WithEntrypoint(entrypoint []string) CtrCreateOption {
|
||||
}
|
||||
|
||||
ctr.config.Entrypoint = make([]string, 0, len(entrypoint))
|
||||
for _, str := range entrypoint {
|
||||
ctr.config.Entrypoint = append(ctr.config.Entrypoint, str)
|
||||
}
|
||||
|
||||
ctr.config.Entrypoint = append(ctr.config.Entrypoint, entrypoint...)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -1192,10 +1186,7 @@ func WithCommand(command []string) CtrCreateOption {
|
||||
}
|
||||
|
||||
ctr.config.Command = make([]string, 0, len(command))
|
||||
for _, str := range command {
|
||||
ctr.config.Command = append(ctr.config.Command, str)
|
||||
}
|
||||
|
||||
ctr.config.Command = append(ctr.config.Command, command...)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user