enable unparam linter

The unparam linter is useful to detect unused function parameters and
return values.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2022-04-22 15:10:13 +02:00
parent ad3da638ce
commit c7b16645af
30 changed files with 118 additions and 157 deletions

View File

@ -34,7 +34,6 @@ linters:
- ifshort
- forbidigo
- exhaustive
- unparam
- gofumpt
- gci
- godot

View File

@ -142,7 +142,7 @@ func create(cmd *cobra.Command, args []string) error {
}
s.RawImageName = rawImageName
if _, err := createPodIfNecessary(cmd, s, cliVals.Net); err != nil {
if err := createPodIfNecessary(cmd, s, cliVals.Net); err != nil {
return err
}
@ -345,13 +345,13 @@ func PullImage(imageName string, cliVals entities.ContainerCreateOptions) (strin
// createPodIfNecessary automatically creates a pod when requested. if the pod name
// has the form new:ID, the pod ID is created and the name in the spec generator is replaced
// with ID.
func createPodIfNecessary(cmd *cobra.Command, s *specgen.SpecGenerator, netOpts *entities.NetOptions) (*entities.PodCreateReport, error) {
func createPodIfNecessary(cmd *cobra.Command, s *specgen.SpecGenerator, netOpts *entities.NetOptions) error {
if !strings.HasPrefix(s.Pod, "new:") {
return nil, nil
return nil
}
podName := strings.Replace(s.Pod, "new:", "", 1)
if len(podName) < 1 {
return nil, errors.Errorf("new pod name must be at least one character")
return errors.Errorf("new pod name must be at least one character")
}
var err error
@ -359,7 +359,7 @@ func createPodIfNecessary(cmd *cobra.Command, s *specgen.SpecGenerator, netOpts
if cliVals.UserNS != "" {
uns, err = specgen.ParseNamespace(cliVals.UserNS)
if err != nil {
return nil, err
return err
}
}
createOptions := entities.PodCreateOptions{
@ -383,7 +383,7 @@ func createPodIfNecessary(cmd *cobra.Command, s *specgen.SpecGenerator, netOpts
podSpec.PodSpecGen = *podGen
podGen, err = entities.ToPodSpecGen(podSpec.PodSpecGen, &createOptions)
if err != nil {
return nil, err
return err
}
infraOpts := entities.NewInfraContainerCreateOptions()
@ -391,14 +391,15 @@ func createPodIfNecessary(cmd *cobra.Command, s *specgen.SpecGenerator, netOpts
infraOpts.Quiet = true
infraOpts.Hostname, err = cmd.Flags().GetString("hostname")
if err != nil {
return nil, err
return err
}
podGen.InfraContainerSpec = specgen.NewSpecGenerator("", false)
podGen.InfraContainerSpec.NetworkOptions = podGen.NetworkOptions
err = specgenutil.FillOutSpecGen(podGen.InfraContainerSpec, &infraOpts, []string{})
if err != nil {
return nil, err
return err
}
podSpec.PodSpecGen = *podGen
return registry.ContainerEngine().PodCreate(context.Background(), podSpec)
_, err = registry.ContainerEngine().PodCreate(context.Background(), podSpec)
return err
}

View File

@ -197,7 +197,7 @@ func run(cmd *cobra.Command, args []string) error {
s.Passwd = &runOpts.Passwd
runOpts.Spec = s
if _, err := createPodIfNecessary(cmd, s, cliVals.Net); err != nil {
if err := createPodIfNecessary(cmd, s, cliVals.Net); err != nil {
return err
}

View File

@ -112,7 +112,7 @@ func add(cmd *cobra.Command, args []string) error {
iden = cOpts.Identity
}
if uri.Path == "" || uri.Path == "/" {
if uri.Path, err = getUDS(cmd, uri, iden); err != nil {
if uri.Path, err = getUDS(uri, iden); err != nil {
return err
}
}
@ -204,7 +204,7 @@ func GetUserInfo(uri *url.URL) (*url.Userinfo, error) {
return url.User(usr.Username), nil
}
func getUDS(cmd *cobra.Command, uri *url.URL, iden string) (string, error) {
func getUDS(uri *url.URL, iden string) (string, error) {
cfg, err := ValidateAndConfigure(uri, iden)
if err != nil {
return "", errors.Wrapf(err, "failed to validate")

View File

@ -889,7 +889,7 @@ func (c *Container) CopyFromArchive(ctx context.Context, containerPath string, c
}
}
return c.copyFromArchive(ctx, containerPath, chown, rename, tarStream)
return c.copyFromArchive(containerPath, chown, rename, tarStream)
}
// CopyToArchive copies the contents from the specified path *inside* the
@ -904,7 +904,7 @@ func (c *Container) CopyToArchive(ctx context.Context, containerPath string, tar
}
}
return c.copyToArchive(ctx, containerPath, tarStream)
return c.copyToArchive(containerPath, tarStream)
}
// Stat the specified path *inside* the container and return a file info.
@ -934,6 +934,6 @@ func (c *Container) Stat(ctx context.Context, containerPath string) (*define.Fil
}()
}
info, _, _, err := c.stat(ctx, mountPoint, containerPath)
info, _, _, err := c.stat(mountPoint, containerPath)
return info, err
}

View File

@ -4,7 +4,6 @@
package libpod
import (
"context"
"io"
"os"
"path/filepath"
@ -24,7 +23,7 @@ import (
"golang.org/x/sys/unix"
)
func (c *Container) copyFromArchive(ctx context.Context, path string, chown bool, rename map[string]string, reader io.Reader) (func() error, error) {
func (c *Container) copyFromArchive(path string, chown bool, rename map[string]string, reader io.Reader) (func() error, error) {
var (
mountPoint string
resolvedRoot string
@ -93,7 +92,7 @@ func (c *Container) copyFromArchive(ctx context.Context, path string, chown bool
Rename: rename,
}
return c.joinMountAndExec(ctx,
return c.joinMountAndExec(
func() error {
return buildahCopiah.Put(resolvedRoot, resolvedPath, putOptions, decompressed)
},
@ -101,7 +100,7 @@ func (c *Container) copyFromArchive(ctx context.Context, path string, chown bool
}, nil
}
func (c *Container) copyToArchive(ctx context.Context, path string, writer io.Writer) (func() error, error) {
func (c *Container) copyToArchive(path string, writer io.Writer) (func() error, error) {
var (
mountPoint string
unmount func()
@ -121,7 +120,7 @@ func (c *Container) copyToArchive(ctx context.Context, path string, writer io.Wr
unmount = func() { c.unmount(false) }
}
statInfo, resolvedRoot, resolvedPath, err := c.stat(ctx, mountPoint, path)
statInfo, resolvedRoot, resolvedPath, err := c.stat(mountPoint, path)
if err != nil {
unmount()
return nil, err
@ -165,7 +164,7 @@ func (c *Container) copyToArchive(ctx context.Context, path string, writer io.Wr
// container's user namespace.
IgnoreUnreadable: rootless.IsRootless() && c.state.State == define.ContainerStateRunning,
}
return c.joinMountAndExec(ctx,
return c.joinMountAndExec(
func() error {
return buildahCopiah.Get(resolvedRoot, "", getOptions, []string{resolvedPath}, writer)
},
@ -216,7 +215,7 @@ func idtoolsToRuntimeSpec(idMaps []idtools.IDMap) (convertedIDMap []specs.LinuxI
// container's file system.
//
// Note, if the container is not running `f()` will be executed as is.
func (c *Container) joinMountAndExec(ctx context.Context, f func() error) error {
func (c *Container) joinMountAndExec(f func() error) error {
if c.state.State != define.ContainerStateRunning {
return f()
}

View File

@ -2632,7 +2632,7 @@ func (c *Container) generateGroupEntry() (string, error) {
addedGID = gid
}
if c.config.User != "" {
entry, _, err := c.generateUserGroupEntry(addedGID)
entry, err := c.generateUserGroupEntry(addedGID)
if err != nil {
return "", err
}
@ -2685,9 +2685,9 @@ func (c *Container) generateCurrentUserGroupEntry() (string, int, error) {
// Make an entry in /etc/group for the group the container was specified to run
// as.
func (c *Container) generateUserGroupEntry(addedGID int) (string, int, error) {
func (c *Container) generateUserGroupEntry(addedGID int) (string, error) {
if c.config.User == "" {
return "", 0, nil
return "", nil
}
splitUser := strings.SplitN(c.config.User, ":", 2)
@ -2698,20 +2698,20 @@ func (c *Container) generateUserGroupEntry(addedGID int) (string, int, error) {
gid, err := strconv.ParseUint(group, 10, 32)
if err != nil {
return "", 0, nil // nolint: nilerr
return "", nil // nolint: nilerr
}
if addedGID != 0 && addedGID == int(gid) {
return "", 0, nil
return "", nil
}
// Check if the group already exists
_, err = lookup.GetGroup(c.state.Mountpoint, group)
if err != runcuser.ErrNoGroupEntries {
return "", 0, err
return "", err
}
return fmt.Sprintf("%d:x:%d:%s\n", gid, gid, splitUser[0]), int(gid), nil
return fmt.Sprintf("%d:x:%d:%s\n", gid, gid, splitUser[0]), nil
}
// generatePasswdEntry generates an entry or entries into /etc/passwd as
@ -2751,7 +2751,7 @@ func (c *Container) generatePasswdEntry() (string, error) {
addedUID = uid
}
if c.config.User != "" {
entry, _, _, err := c.generateUserPasswdEntry(addedUID)
entry, err := c.generateUserPasswdEntry(addedUID)
if err != nil {
return "", err
}
@ -2838,13 +2838,13 @@ func (c *Container) userPasswdEntry(u *user.User) (string, error) {
// Accepts one argument, that being any UID that has already been added to the
// passwd file by other functions; if it matches the UID we were given, we don't
// need to do anything.
func (c *Container) generateUserPasswdEntry(addedUID int) (string, int, int, error) {
func (c *Container) generateUserPasswdEntry(addedUID int) (string, error) {
var (
groupspec string
gid int
)
if c.config.User == "" {
return "", 0, 0, nil
return "", nil
}
splitSpec := strings.SplitN(c.config.User, ":", 2)
userspec := splitSpec[0]
@ -2854,17 +2854,17 @@ func (c *Container) generateUserPasswdEntry(addedUID int) (string, int, int, err
// If a non numeric User, then don't generate passwd
uid, err := strconv.ParseUint(userspec, 10, 32)
if err != nil {
return "", 0, 0, nil // nolint: nilerr
return "", nil // nolint: nilerr
}
if addedUID != 0 && int(uid) == addedUID {
return "", 0, 0, nil
return "", nil
}
// Lookup the user to see if it exists in the container image
_, err = lookup.GetUser(c.state.Mountpoint, userspec)
if err != runcuser.ErrNoPasswdEntries {
return "", 0, 0, err
return "", err
}
if groupspec != "" {
@ -2874,7 +2874,7 @@ func (c *Container) generateUserPasswdEntry(addedUID int) (string, int, int, err
} else {
group, err := lookup.GetGroup(c.state.Mountpoint, groupspec)
if err != nil {
return "", 0, 0, errors.Wrapf(err, "unable to get gid %s from group file", groupspec)
return "", errors.Wrapf(err, "unable to get gid %s from group file", groupspec)
}
gid = group.Gid
}
@ -2882,10 +2882,10 @@ func (c *Container) generateUserPasswdEntry(addedUID int) (string, int, int, err
if c.config.PasswdEntry != "" {
entry := c.passwdEntry(fmt.Sprintf("%d", uid), fmt.Sprintf("%d", uid), fmt.Sprintf("%d", gid), "container user", c.WorkingDir())
return entry, int(uid), gid, nil
return entry, nil
}
return fmt.Sprintf("%d:*:%d:%d:container user:%s:/bin/sh\n", uid, uid, gid, c.WorkingDir()), int(uid), gid, nil
return fmt.Sprintf("%d:*:%d:%d:container user:%s:/bin/sh\n", uid, uid, gid, c.WorkingDir()), nil
}
func (c *Container) passwdEntry(username string, uid, gid, name, homeDir string) string {

View File

@ -30,14 +30,14 @@ func TestGenerateUserPasswdEntry(t *testing.T) {
Mountpoint: "/does/not/exist/tmp/",
},
}
user, _, _, err := c.generateUserPasswdEntry(0)
user, err := c.generateUserPasswdEntry(0)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, user, "123:*:123:456:container user:/:/bin/sh\n")
c.config.User = "567"
user, _, _, err = c.generateUserPasswdEntry(0)
user, err = c.generateUserPasswdEntry(0)
if err != nil {
t.Fatal(err)
}
@ -56,14 +56,14 @@ func TestGenerateUserGroupEntry(t *testing.T) {
Mountpoint: "/does/not/exist/tmp/",
},
}
group, _, err := c.generateUserGroupEntry(0)
group, err := c.generateUserGroupEntry(0)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, group, "456:x:456:123\n")
c.config.User = "567"
group, _, err = c.generateUserGroupEntry(0)
group, err = c.generateUserGroupEntry(0)
if err != nil {
t.Fatal(err)
}

View File

@ -4,7 +4,6 @@
package libpod
import (
"context"
"os"
"path/filepath"
"strings"
@ -18,12 +17,12 @@ import (
// statInsideMount stats the specified path *inside* the container's mount and PID
// namespace. It returns the file info along with the resolved root ("/") and
// the resolved path (relative to the root).
func (c *Container) statInsideMount(ctx context.Context, containerPath string) (*copier.StatForItem, string, string, error) {
func (c *Container) statInsideMount(containerPath string) (*copier.StatForItem, string, string, error) {
resolvedRoot := "/"
resolvedPath := c.pathAbs(containerPath)
var statInfo *copier.StatForItem
err := c.joinMountAndExec(ctx,
err := c.joinMountAndExec(
func() error {
var statErr error
statInfo, statErr = secureStat(resolvedRoot, resolvedPath)
@ -38,7 +37,7 @@ func (c *Container) statInsideMount(ctx context.Context, containerPath string) (
// along with the resolved root and the resolved path. Both paths are absolute
// to the host's root. Note that the paths may resolved outside the
// container's mount point (e.g., to a volume or bind mount).
func (c *Container) statOnHost(ctx context.Context, mountPoint string, containerPath string) (*copier.StatForItem, string, string, error) {
func (c *Container) statOnHost(mountPoint string, containerPath string) (*copier.StatForItem, string, string, error) {
// Now resolve the container's path. It may hit a volume, it may hit a
// bind mount, it may be relative.
resolvedRoot, resolvedPath, err := c.resolvePath(mountPoint, containerPath)
@ -50,7 +49,7 @@ func (c *Container) statOnHost(ctx context.Context, mountPoint string, container
return statInfo, resolvedRoot, resolvedPath, err
}
func (c *Container) stat(ctx context.Context, containerMountPoint string, containerPath string) (*define.FileInfo, string, string, error) {
func (c *Container) stat(containerMountPoint string, containerPath string) (*define.FileInfo, string, string, error) {
var (
resolvedRoot string
resolvedPath string
@ -75,11 +74,11 @@ func (c *Container) stat(ctx context.Context, containerMountPoint string, contai
if c.state.State == define.ContainerStateRunning {
// If the container is running, we need to join it's mount namespace
// and stat there.
statInfo, resolvedRoot, resolvedPath, statErr = c.statInsideMount(ctx, containerPath)
statInfo, resolvedRoot, resolvedPath, statErr = c.statInsideMount(containerPath)
} else {
// If the container is NOT running, we need to resolve the path
// on the host.
statInfo, resolvedRoot, resolvedPath, statErr = c.statOnHost(ctx, containerMountPoint, containerPath)
statInfo, resolvedRoot, resolvedPath, statErr = c.statOnHost(containerMountPoint, containerPath)
}
if statErr != nil {

View File

@ -74,7 +74,7 @@ func (c *Container) convertPortMappings() []types.PortMapping {
return newPorts
}
func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOptions) (types.NetworkOptions, error) {
func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOptions) types.NetworkOptions {
opts := types.NetworkOptions{
ContainerID: c.config.ID,
ContainerName: getCNIPodName(c),
@ -88,7 +88,7 @@ func (c *Container) getNetworkOptions(networkOpts map[string]types.PerNetworkOpt
} else {
opts.Networks = networkOpts
}
return opts, nil
return opts
}
type RootlessNetNS struct {
@ -653,10 +653,7 @@ func (r *Runtime) configureNetNS(ctr *Container, ctrNS ns.NetNS) (status map[str
return nil, nil
}
netOpts, err := ctr.getNetworkOptions(networks)
if err != nil {
return nil, err
}
netOpts := ctr.getNetworkOptions(networks)
netStatus, err := r.setUpNetwork(ctrNS.Path(), netOpts)
if err != nil {
return nil, err
@ -814,10 +811,7 @@ func (r *Runtime) teardownCNI(ctr *Container) error {
}
if !ctr.config.NetMode.IsSlirp4netns() && len(networks) > 0 {
netOpts, err := ctr.getNetworkOptions(networks)
if err != nil {
return err
}
netOpts := ctr.getNetworkOptions(networks)
return r.teardownNetwork(ctr.state.NetNS.Path(), netOpts)
}
return nil
@ -1000,12 +994,10 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
if c.state.NetNS == nil {
if networkNSPath := c.joinedNetworkNSPath(); networkNSPath != "" {
if result, err := c.inspectJoinedNetworkNS(networkNSPath); err == nil {
if basicConfig, err := resultToBasicNetworkConfig(result); err == nil {
// fallback to dummy configuration
settings.InspectBasicNetworkConfig = basicConfig
settings.InspectBasicNetworkConfig = resultToBasicNetworkConfig(result)
return settings, nil
}
}
// do not propagate error inspecting a joined network ns
logrus.Errorf("Inspecting network namespace: %s of container %s: %v", networkNSPath, c.ID(), err)
}
@ -1047,14 +1039,8 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
result := netStatus[name]
addedNet := new(define.InspectAdditionalNetwork)
addedNet.NetworkID = name
basicConfig, err := resultToBasicNetworkConfig(result)
if err != nil {
return nil, err
}
addedNet.Aliases = opts.Aliases
addedNet.InspectBasicNetworkConfig = basicConfig
addedNet.InspectBasicNetworkConfig = resultToBasicNetworkConfig(result)
settings.Networks[name] = addedNet
}
@ -1074,11 +1060,7 @@ func (c *Container) getContainerNetworkInfo() (*define.InspectNetworkSettings, e
if len(netStatus) == 1 {
for _, status := range netStatus {
basicConfig, err := resultToBasicNetworkConfig(status)
if err != nil {
return nil, err
}
settings.InspectBasicNetworkConfig = basicConfig
settings.InspectBasicNetworkConfig = resultToBasicNetworkConfig(status)
}
}
return settings, nil
@ -1152,7 +1134,7 @@ func (c *Container) inspectJoinedNetworkNS(networkns string) (q types.StatusBloc
// resultToBasicNetworkConfig produces an InspectBasicNetworkConfig from a CNI
// result
func resultToBasicNetworkConfig(result types.StatusBlock) (define.InspectBasicNetworkConfig, error) {
func resultToBasicNetworkConfig(result types.StatusBlock) define.InspectBasicNetworkConfig {
config := define.InspectBasicNetworkConfig{}
interfaceNames := make([]string, 0, len(result.Interfaces))
for interfaceName := range result.Interfaces {
@ -1190,7 +1172,7 @@ func resultToBasicNetworkConfig(result types.StatusBlock) (define.InspectBasicNe
config.AdditionalMacAddresses = append(config.AdditionalMacAddresses, netInt.MacAddress.String())
}
}
return config, nil
return config
}
type logrusDebugWriter struct {

View File

@ -241,7 +241,6 @@ func Test_ocicniPortsToNetTypesPorts(t *testing.T) {
func Test_resultToBasicNetworkConfig(t *testing.T) {
testCases := []struct {
description string
expectError bool
inputResult types.StatusBlock
expectedNetworkConfig define.InspectBasicNetworkConfig
}{
@ -431,15 +430,7 @@ func Test_resultToBasicNetworkConfig(t *testing.T) {
tc := tcl
t.Run(tc.description, func(t *testing.T) {
t.Parallel()
actualNetworkConfig, err := resultToBasicNetworkConfig(tc.inputResult)
if tc.expectError && err == nil {
t.Fatalf("Expected error didn't happen")
}
if !tc.expectError && err != nil {
t.Fatalf("Unexpected error happened: %v", err)
}
actualNetworkConfig := resultToBasicNetworkConfig(tc.inputResult)
if !reflect.DeepEqual(tc.expectedNetworkConfig, actualNetworkConfig) {
t.Fatalf(

View File

@ -439,7 +439,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
// }
// }
conmonEnv := r.configureConmonEnv(c, runtimeDir)
conmonEnv := r.configureConmonEnv(runtimeDir)
var filesToClose []*os.File
if options.PreserveFDs > 0 {

View File

@ -1181,7 +1181,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
}
// 0, 1 and 2 are stdin, stdout and stderr
conmonEnv := r.configureConmonEnv(ctr, runtimeDir)
conmonEnv := r.configureConmonEnv(runtimeDir)
var filesToClose []*os.File
if preserveFDs > 0 {
@ -1312,7 +1312,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
// configureConmonEnv gets the environment values to add to conmon's exec struct
// TODO this may want to be less hardcoded/more configurable in the future
func (r *ConmonOCIRuntime) configureConmonEnv(ctr *Container, runtimeDir string) []string {
func (r *ConmonOCIRuntime) configureConmonEnv(runtimeDir string) []string {
var env []string
for _, e := range os.Environ() {
if strings.HasPrefix(e, "LC_") {

View File

@ -167,7 +167,7 @@ func NewRuntime(ctx context.Context, options ...RuntimeOption) (*Runtime, error)
if err != nil {
return nil, err
}
return newRuntimeFromConfig(ctx, conf, options...)
return newRuntimeFromConfig(conf, options...)
}
// NewRuntimeFromConfig creates a new container runtime using the given
@ -176,10 +176,10 @@ func NewRuntime(ctx context.Context, options ...RuntimeOption) (*Runtime, error)
// An error will be returned if the configuration file at the given path does
// not exist or cannot be loaded
func NewRuntimeFromConfig(ctx context.Context, userConfig *config.Config, options ...RuntimeOption) (*Runtime, error) {
return newRuntimeFromConfig(ctx, userConfig, options...)
return newRuntimeFromConfig(userConfig, options...)
}
func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...RuntimeOption) (*Runtime, error) {
func newRuntimeFromConfig(conf *config.Config, options ...RuntimeOption) (*Runtime, error) {
runtime := new(Runtime)
if conf.Engine.OCIRuntime == "" {
@ -224,7 +224,7 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
return nil, errors.Wrapf(err, "error starting shutdown signal handler")
}
if err := makeRuntime(ctx, runtime); err != nil {
if err := makeRuntime(runtime); err != nil {
return nil, err
}
@ -292,7 +292,7 @@ func getLockManager(runtime *Runtime) (lock.Manager, error) {
// Make a new runtime based on the given configuration
// Sets up containers/storage, state store, OCI runtime
func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
func makeRuntime(runtime *Runtime) (retErr error) {
// Find a working conmon binary
cPath, err := findConmon(runtime.config.Engine.ConmonPath)
if err != nil {
@ -598,7 +598,7 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
runtime.valid = true
if runtime.doMigrate {
if err := runtime.migrate(ctx); err != nil {
if err := runtime.migrate(); err != nil {
return err
}
}

View File

@ -501,7 +501,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
volOptions = append(volOptions, parsedOptions...)
}
}
newVol, err := r.newVolume(ctx, volOptions...)
newVol, err := r.newVolume(volOptions...)
if err != nil {
return nil, errors.Wrapf(err, "error creating named volume %q", vol.Name)
}

View File

@ -4,7 +4,6 @@
package libpod
import (
"context"
"fmt"
"io/ioutil"
"os"
@ -46,7 +45,7 @@ func (r *Runtime) stopPauseProcess() error {
return nil
}
func (r *Runtime) migrate(ctx context.Context) error {
func (r *Runtime) migrate() error {
runningContainers, err := r.GetRunningContainers()
if err != nil {
return err

View File

@ -25,11 +25,11 @@ func (r *Runtime) NewVolume(ctx context.Context, options ...VolumeCreateOption)
if !r.valid {
return nil, define.ErrRuntimeStopped
}
return r.newVolume(ctx, options...)
return r.newVolume(options...)
}
// newVolume creates a new empty volume
func (r *Runtime) newVolume(ctx context.Context, options ...VolumeCreateOption) (_ *Volume, deferredErr error) {
func (r *Runtime) newVolume(options ...VolumeCreateOption) (_ *Volume, deferredErr error) {
volume := newVolume(r)
for _, option := range options {
if err := option(volume); err != nil {

View File

@ -209,7 +209,7 @@ func autoUpdateRegistry(ctx context.Context, image *libimage.Image, ctr *libpod.
}
authfile := getAuthfilePath(ctr, options)
needsUpdate, err := newerRemoteImageAvailable(ctx, runtime, image, rawImageName, authfile)
needsUpdate, err := newerRemoteImageAvailable(ctx, image, rawImageName, authfile)
if err != nil {
return report, errors.Wrapf(err, "registry auto-updating container %q: image check for %q failed", cid, rawImageName)
}
@ -399,7 +399,7 @@ func getAuthfilePath(ctr *libpod.Container, options *entities.AutoUpdateOptions)
// newerRemoteImageAvailable returns true if there corresponding image on the remote
// registry is newer.
func newerRemoteImageAvailable(ctx context.Context, runtime *libpod.Runtime, img *libimage.Image, origName string, authfile string) (bool, error) {
func newerRemoteImageAvailable(ctx context.Context, img *libimage.Image, origName string, authfile string) (bool, error) {
remoteRef, err := docker.ParseReference("//" + origName)
if err != nil {
return false, err

View File

@ -114,7 +114,7 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, options
return nil, errors.Wrap(err, "unable to read YAML as Kube PersistentVolumeClaim")
}
r, err := ic.playKubePVC(ctx, &pvcYAML, options)
r, err := ic.playKubePVC(ctx, &pvcYAML)
if err != nil {
return nil, err
}
@ -592,7 +592,7 @@ func (ic *ContainerEngine) getImageAndLabelInfo(ctx context.Context, cwd string,
}
// playKubePVC creates a podman volume from a kube persistent volume claim.
func (ic *ContainerEngine) playKubePVC(ctx context.Context, pvcYAML *v1.PersistentVolumeClaim, options entities.PlayKubeOptions) (*entities.PlayKubeReport, error) {
func (ic *ContainerEngine) playKubePVC(ctx context.Context, pvcYAML *v1.PersistentVolumeClaim) (*entities.PlayKubeReport, error) {
var report entities.PlayKubeReport
opts := make(map[string]string)

View File

@ -139,7 +139,7 @@ func getStreamURL(streamType string) url2.URL {
// This should get Exported and stay put as it will apply to all fcos downloads
// getFCOS parses fedoraCoreOS's stream and returns the image download URL and the release version
func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) { // nolint:staticcheck
func getFCOSDownload(imageStream string) (*fcosDownloadInfo, error) { // nolint:staticcheck,unparam
var (
fcosstable stream.Stream
altMeta release.Release

View File

@ -146,13 +146,13 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
options = append(options, libpod.WithHostUsers(s.HostUsers))
}
command, err := makeCommand(ctx, s, imageData, rtc)
command, err := makeCommand(s, imageData, rtc)
if err != nil {
return nil, nil, nil, err
}
infraVol := (len(compatibleOptions.Mounts) > 0 || len(compatibleOptions.Volumes) > 0 || len(compatibleOptions.ImageVolumes) > 0 || len(compatibleOptions.OverlayVolumes) > 0)
opts, err := createContainerOptions(ctx, rt, s, pod, finalVolumes, finalOverlays, imageData, command, infraVol, *compatibleOptions)
opts, err := createContainerOptions(rt, s, pod, finalVolumes, finalOverlays, imageData, command, infraVol, *compatibleOptions)
if err != nil {
return nil, nil, nil, err
}
@ -251,7 +251,7 @@ func isCDIDevice(device string) bool {
return cdi.IsQualifiedName(device)
}
func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGenerator, pod *libpod.Pod, volumes []*specgen.NamedVolume, overlays []*specgen.OverlayVolume, imageData *libimage.ImageData, command []string, infraVolumes bool, compatibleOptions libpod.InfraInherit) ([]libpod.CtrCreateOption, error) {
func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *libpod.Pod, volumes []*specgen.NamedVolume, overlays []*specgen.OverlayVolume, imageData *libimage.ImageData, command []string, infraVolumes bool, compatibleOptions libpod.InfraInherit) ([]libpod.CtrCreateOption, error) {
var options []libpod.CtrCreateOption
var err error
@ -453,7 +453,7 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
options = append(options, libpod.WithPrivileged(s.Privileged))
// Get namespace related options
namespaceOpts, err := namespaceOptions(ctx, s, rt, pod, imageData)
namespaceOpts, err := namespaceOptions(s, rt, pod, imageData)
if err != nil {
return nil, err
}

View File

@ -1,7 +1,6 @@
package generate
import (
"context"
"fmt"
"os"
"strings"
@ -80,7 +79,7 @@ func GetDefaultNamespaceMode(nsType string, cfg *config.Config, pod *libpod.Pod)
// joining a pod.
// TODO: Consider grouping options that are not directly attached to a namespace
// elsewhere.
func namespaceOptions(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runtime, pod *libpod.Pod, imageData *libimage.ImageData) ([]libpod.CtrCreateOption, error) {
func namespaceOptions(s *specgen.SpecGenerator, rt *libpod.Runtime, pod *libpod.Pod, imageData *libimage.ImageData) ([]libpod.CtrCreateOption, error) {
toReturn := []libpod.CtrCreateOption{}
// If pod is not nil, get infra container.
@ -256,7 +255,7 @@ func namespaceOptions(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.
}
toReturn = append(toReturn, libpod.WithNetNSFrom(netCtr))
case specgen.Slirp:
portMappings, expose, err := createPortMappings(ctx, s, imageData)
portMappings, expose, err := createPortMappings(s, imageData)
if err != nil {
return nil, err
}
@ -268,7 +267,7 @@ func namespaceOptions(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.
case specgen.Private:
fallthrough
case specgen.Bridge:
portMappings, expose, err := createPortMappings(ctx, s, imageData)
portMappings, expose, err := createPortMappings(s, imageData)
if err != nil {
return nil, err
}

View File

@ -32,7 +32,7 @@ func setProcOpts(s *specgen.SpecGenerator, g *generate.Generator) {
}
}
func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) error {
func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) {
var (
isRootless = rootless.IsRootless()
nofileSet = false
@ -41,7 +41,7 @@ func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) error {
if s.Rlimits == nil {
g.Config.Process.Rlimits = nil
return nil
return
}
for _, u := range s.Rlimits {
@ -91,12 +91,10 @@ func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) error {
}
g.AddProcessRlimits("RLIMIT_NPROC", max, current)
}
return nil
}
// Produce the final command for the container.
func makeCommand(ctx context.Context, s *specgen.SpecGenerator, imageData *libimage.ImageData, rtc *config.Config) ([]string, error) {
func makeCommand(s *specgen.SpecGenerator, imageData *libimage.ImageData, rtc *config.Config) ([]string, error) {
finalCommand := []string{}
entrypoint := s.Entrypoint
@ -388,9 +386,7 @@ func SpecGenToOCI(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Runt
g.AddProcessEnv(name, val)
}
if err := addRlimits(s, &g); err != nil {
return nil, err
}
addRlimits(s, &g)
// NAMESPACES
if err := specConfigureNamespaces(s, &g, rt, pod); err != nil {

View File

@ -119,7 +119,7 @@ func MakePod(p *entities.PodSpec, rt *libpod.Runtime) (*libpod.Pod, error) {
}
}
options, err := createPodOptions(&p.PodSpecGen, rt, p.PodSpecGen.InfraContainerSpec)
options, err := createPodOptions(&p.PodSpecGen)
if err != nil {
return nil, err
}
@ -161,11 +161,11 @@ func MakePod(p *entities.PodSpec, rt *libpod.Runtime) (*libpod.Pod, error) {
return pod, nil
}
func createPodOptions(p *specgen.PodSpecGenerator, rt *libpod.Runtime, infraSpec *specgen.SpecGenerator) ([]libpod.PodCreateOption, error) {
func createPodOptions(p *specgen.PodSpecGenerator) ([]libpod.PodCreateOption, error) {
var (
options []libpod.PodCreateOption
)
if !p.NoInfra { //&& infraSpec != nil {
if !p.NoInfra {
options = append(options, libpod.WithInfraContainer())
if p.ShareParent == nil || (p.ShareParent != nil && *p.ShareParent) {
options = append(options, libpod.WithPodParent())

View File

@ -1,7 +1,6 @@
package generate
import (
"context"
"fmt"
"net"
"sort"
@ -338,7 +337,7 @@ func appendProtocolsNoDuplicates(slice []string, protocols []string) []string {
}
// Make final port mappings for the container
func createPortMappings(ctx context.Context, s *specgen.SpecGenerator, imageData *libimage.ImageData) ([]types.PortMapping, map[uint16][]string, error) {
func createPortMappings(s *specgen.SpecGenerator, imageData *libimage.ImageData) ([]types.PortMapping, map[uint16][]string, error) {
expose := make(map[uint16]string)
var err error
if imageData != nil {

View File

@ -136,7 +136,7 @@ func LimitToSwap(memory *specs.LinuxMemory, swap string, ml int64) {
}
}
func getMemoryLimits(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions) (*specs.LinuxMemory, error) {
func getMemoryLimits(c *entities.ContainerCreateOptions) (*specs.LinuxMemory, error) {
var err error
memory := &specs.LinuxMemory{}
hasLimits := false
@ -497,7 +497,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
}
if s.ResourceLimits.Memory == nil || (len(c.Memory) != 0 || len(c.MemoryReservation) != 0 || len(c.MemorySwap) != 0 || c.MemorySwappiness != 0) {
s.ResourceLimits.Memory, err = getMemoryLimits(s, c)
s.ResourceLimits.Memory, err = getMemoryLimits(c)
if err != nil {
return err
}

View File

@ -1047,7 +1047,7 @@ var IPRegex = `(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01
// digShort execs into the given container and does a dig lookup with a timeout
// backoff. If it gets a response, it ensures that the output is in the correct
// format and iterates a string array for match
func digShort(container, lookupName string, matchNames []string, p *PodmanTestIntegration) string {
func digShort(container, lookupName string, matchNames []string, p *PodmanTestIntegration) {
digInterval := time.Millisecond * 250
for i := 0; i < 6; i++ {
time.Sleep(digInterval * time.Duration(i))
@ -1059,9 +1059,9 @@ func digShort(container, lookupName string, matchNames []string, p *PodmanTestIn
for _, name := range matchNames {
Expect(output).To(Equal(name))
}
return output
// success
return
}
}
Fail("dns is not responding")
return ""
}

View File

@ -680,7 +680,7 @@ func generateMultiDocKubeYaml(kubeObjects []string, pathname string) error {
return writeYaml(multiKube, pathname)
}
func createSecret(podmanTest *PodmanTestIntegration, name string, value []byte) {
func createSecret(podmanTest *PodmanTestIntegration, name string, value []byte) { //nolint:unparam
secretFilePath := filepath.Join(podmanTest.TempDir, "secret")
err := ioutil.WriteFile(secretFilePath, value, 0755)
Expect(err).To(BeNil())
@ -1078,7 +1078,7 @@ func withVolumeMount(mountPath string, readonly bool) ctrOption {
}
}
func withEnv(name, value, valueFrom, refName, refKey string, optional bool) ctrOption {
func withEnv(name, value, valueFrom, refName, refKey string, optional bool) ctrOption { //nolint:unparam
return func(c *Ctr) {
e := Env{
Name: name,

View File

@ -54,7 +54,7 @@ var _ = Describe("Podman run networking", func() {
cip := ctrIP.OutputToString()
Expect(cip).To(MatchRegexp(IPRegex))
_ = digShort(cid, "aone", []string{cip}, podmanTest)
digShort(cid, "aone", []string{cip}, podmanTest)
reverseLookup := podmanTest.Podman([]string{"exec", cid, "dig", "+short", "-x", cip})
reverseLookup.WaitWithDefaultTimeout()
@ -95,9 +95,9 @@ var _ = Describe("Podman run networking", func() {
cip2 := ctrIP2.OutputToString()
Expect(cip2).To(MatchRegexp(IPRegex))
_ = digShort("aone", "atwo", []string{cip2}, podmanTest)
digShort("aone", "atwo", []string{cip2}, podmanTest)
_ = digShort("atwo", "aone", []string{cip1}, podmanTest)
digShort("atwo", "aone", []string{cip1}, podmanTest)
reverseLookup12 := podmanTest.Podman([]string{"exec", cid1, "dig", "+short", "-x", cip2})
reverseLookup12.WaitWithDefaultTimeout()
@ -144,17 +144,17 @@ var _ = Describe("Podman run networking", func() {
cip2 := ctrIP2.OutputToString()
Expect(cip2).To(MatchRegexp(IPRegex))
_ = digShort("aone", "atwo", []string{cip2}, podmanTest)
digShort("aone", "atwo", []string{cip2}, podmanTest)
_ = digShort("aone", "alias_a2", []string{cip2}, podmanTest)
digShort("aone", "alias_a2", []string{cip2}, podmanTest)
_ = digShort("aone", "alias_2a", []string{cip2}, podmanTest)
digShort("aone", "alias_2a", []string{cip2}, podmanTest)
_ = digShort("atwo", "aone", []string{cip1}, podmanTest)
digShort("atwo", "aone", []string{cip1}, podmanTest)
_ = digShort("atwo", "alias_a1", []string{cip1}, podmanTest)
digShort("atwo", "alias_a1", []string{cip1}, podmanTest)
_ = digShort("atwo", "alias_1a", []string{cip1}, podmanTest)
digShort("atwo", "alias_1a", []string{cip1}, podmanTest)
})
@ -251,13 +251,13 @@ var _ = Describe("Podman run networking", func() {
cipA2B22 := ctrIPA2B22.OutputToString()
Expect(cipA2B22).To(MatchRegexp(IPRegex))
_ = digShort("aone", "atwobtwo", []string{cipA2B21}, podmanTest)
digShort("aone", "atwobtwo", []string{cipA2B21}, podmanTest)
_ = digShort("bone", "atwobtwo", []string{cipA2B22}, podmanTest)
digShort("bone", "atwobtwo", []string{cipA2B22}, podmanTest)
_ = digShort("atwobtwo", "aone", []string{cipA1}, podmanTest)
digShort("atwobtwo", "aone", []string{cipA1}, podmanTest)
_ = digShort("atwobtwo", "bone", []string{cipB1}, podmanTest)
digShort("atwobtwo", "bone", []string{cipB1}, podmanTest)
})
It("Aardvark Test 6: Three subnets, first container on 1/2 and second on 2/3, w/ network aliases", func() {
@ -305,9 +305,9 @@ var _ = Describe("Podman run networking", func() {
Expect(ctrIPCB2).Should(Exit(0))
cipCB2 := ctrIPCB2.OutputToString()
_ = digShort("aone", "testB2_nw", []string{cipCB2}, podmanTest)
digShort("aone", "testB2_nw", []string{cipCB2}, podmanTest)
_ = digShort("cone", "testB1_nw", []string{cipAB1}, podmanTest)
digShort("cone", "testB1_nw", []string{cipAB1}, podmanTest)
})

View File

@ -86,10 +86,7 @@ func startServer(socketPath string) error {
}
}
handle, err := makeDirDriver(config.path)
if err != nil {
return errors.Wrapf(err, "error making volume driver")
}
handle := makeDirDriver(config.path)
logrus.Infof("Using %s for volume path", config.path)
server := volume.NewHandler(handle)
@ -116,12 +113,12 @@ type dirVol struct {
}
// Make a new DirDriver.
func makeDirDriver(path string) (volume.Driver, error) {
func makeDirDriver(path string) volume.Driver {
drv := new(DirDriver)
drv.volumesPath = path
drv.volumes = make(map[string]*dirVol)
return drv, nil
return drv
}
// Capabilities returns the capabilities of the driver.