lint: fix warnings found by perfsprint

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2023-10-20 16:21:12 +02:00
parent 64f43fed4d
commit 29273cda10
24 changed files with 62 additions and 53 deletions

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"strconv"
tm "github.com/buger/goterm" tm "github.com/buger/goterm"
"github.com/containers/common/pkg/completion" "github.com/containers/common/pkg/completion"
@ -222,7 +223,7 @@ func (s *containerStats) BlockIO() string {
} }
func (s *containerStats) PIDS() string { func (s *containerStats) PIDS() string {
return fmt.Sprintf("%d", s.PIDs) return strconv.FormatUint(s.PIDs, 10)
} }
func (s *containerStats) MemUsage() string { func (s *containerStats) MemUsage() string {

View File

@ -547,7 +547,7 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
} }
g.SetRootPath(c.state.Mountpoint) g.SetRootPath(c.state.Mountpoint)
g.AddAnnotation("org.opencontainers.image.stopSignal", fmt.Sprintf("%d", c.config.StopSignal)) g.AddAnnotation("org.opencontainers.image.stopSignal", strconv.FormatUint(uint64(c.config.StopSignal), 10))
if _, exists := g.Config.Annotations[annotations.ContainerManager]; !exists { if _, exists := g.Config.Annotations[annotations.ContainerManager]; !exists {
g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod) g.AddAnnotation(annotations.ContainerManager, annotations.ContainerManagerLibpod)
@ -2599,11 +2599,11 @@ func (c *Container) generateUserPasswdEntry(addedUID int) (string, error) {
} }
if c.config.PasswdEntry != "" { if c.config.PasswdEntry != "" {
entry := c.passwdEntry(fmt.Sprintf("%d", uid), fmt.Sprintf("%d", uid), fmt.Sprintf("%d", gid), "container user", c.WorkingDir()) entry := c.passwdEntry(strconv.FormatUint(uid, 10), strconv.FormatUint(uid, 10), strconv.FormatInt(int64(gid), 10), "container user", c.WorkingDir())
return entry, nil return entry, nil
} }
u, err := user.LookupId(fmt.Sprintf("%d", uid)) u, err := user.LookupId(strconv.FormatUint(uid, 10))
if err == nil { if err == nil {
return fmt.Sprintf("%s:*:%d:%d:%s:%s:/bin/sh\n", u.Username, uid, gid, u.Name, c.WorkingDir()), nil return fmt.Sprintf("%s:*:%d:%d:%s:%s:/bin/sh\n", u.Username, uid, gid, u.Name, c.WorkingDir()), nil
} }

View File

@ -155,7 +155,7 @@ func (c *Container) readFromLogFile(ctx context.Context, options *logs.LogOption
// before stopping the file logger (see #10675). // before stopping the file logger (see #10675).
time.Sleep(watch.POLL_DURATION) time.Sleep(watch.POLL_DURATION)
tailError := t.StopAtEOF() tailError := t.StopAtEOF()
if tailError != nil && fmt.Sprintf("%v", tailError) != "tail: stop at eof" { if tailError != nil && tailError.Error() != "tail: stop at eof" {
logrus.Errorf("Stopping logger: %v", tailError) logrus.Errorf("Stopping logger: %v", tailError)
} }
}() }()

View File

@ -69,7 +69,7 @@ func (c *Container) newContainerEventWithInspectData(status events.Status, inspe
if status == events.HealthStatus { if status == events.HealthStatus {
containerHealthStatus, err := c.healthCheckStatus() containerHealthStatus, err := c.healthCheckStatus()
if err != nil { if err != nil {
e.HealthStatus = fmt.Sprintf("%v", err) e.HealthStatus = err.Error()
} }
e.HealthStatus = containerHealthStatus e.HealthStatus = containerHealthStatus
} }

View File

@ -1,10 +1,10 @@
package file package file
import ( import (
"fmt"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -58,7 +58,7 @@ func TestLockAndUnlock(t *testing.T) {
lslocks, err := exec.LookPath("lslocks") lslocks, err := exec.LookPath("lslocks")
if err == nil { if err == nil {
lockPath := l.getLockPath(lock) lockPath := l.getLockPath(lock)
out, err := exec.Command(lslocks, "--json", "-p", fmt.Sprintf("%d", os.Getpid())).CombinedOutput() out, err := exec.Command(lslocks, "--json", "-p", strconv.Itoa(os.Getpid())).CombinedOutput()
assert.NoError(t, err) assert.NoError(t, err)
assert.Contains(t, string(out), lockPath) assert.Contains(t, string(out), lockPath)

View File

@ -375,9 +375,9 @@ func (r *ConmonOCIRuntime) killContainer(ctr *Container, signal uint, all, captu
var args []string var args []string
args = append(args, r.runtimeFlags...) args = append(args, r.runtimeFlags...)
if all { if all {
args = append(args, "kill", "--all", ctr.ID(), fmt.Sprintf("%d", signal)) args = append(args, "kill", "--all", ctr.ID(), strconv.FormatUint(uint64(signal), 10))
} else { } else {
args = append(args, "kill", ctr.ID(), fmt.Sprintf("%d", signal)) args = append(args, "kill", ctr.ID(), strconv.FormatUint(uint64(signal), 10))
} }
var ( var (
stderr io.Writer = os.Stderr stderr io.Writer = os.Stderr
@ -1128,7 +1128,7 @@ func (r *ConmonOCIRuntime) createOCIContainer(ctr *Container, restoreOptions *Co
} }
if preserveFDs > 0 { if preserveFDs > 0 {
args = append(args, formatRuntimeOpts("--preserve-fds", fmt.Sprintf("%d", preserveFDs))...) args = append(args, formatRuntimeOpts("--preserve-fds", strconv.FormatUint(uint64(preserveFDs), 10))...)
} }
if restoreOptions != nil { if restoreOptions != nil {
@ -1388,7 +1388,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
size = ctr.config.LogSize size = ctr.config.LogSize
} }
if size > 0 { if size > 0 {
args = append(args, "--log-size-max", fmt.Sprintf("%v", size)) args = append(args, "--log-size-max", strconv.FormatInt(size, 10))
} }
if ociLogPath != "" { if ociLogPath != "" {

View File

@ -7,6 +7,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
"syscall" "syscall"
"time" "time"
@ -387,7 +388,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
args := r.sharedConmonArgs(c, sessionID, c.execBundlePath(sessionID), c.execPidPath(sessionID), c.execLogPath(sessionID), c.execExitFileDir(sessionID), ociLog, define.NoLogging, c.config.LogTag) args := r.sharedConmonArgs(c, sessionID, c.execBundlePath(sessionID), c.execPidPath(sessionID), c.execLogPath(sessionID), c.execExitFileDir(sessionID), ociLog, define.NoLogging, c.config.LogTag)
if options.PreserveFDs > 0 { if options.PreserveFDs > 0 {
args = append(args, formatRuntimeOpts("--preserve-fds", fmt.Sprintf("%d", options.PreserveFDs))...) args = append(args, formatRuntimeOpts("--preserve-fds", strconv.FormatUint(uint64(options.PreserveFDs), 10))...)
} }
if options.Terminal { if options.Terminal {
@ -410,7 +411,7 @@ func (r *ConmonOCIRuntime) startExec(c *Container, sessionID string, options *Ex
args = append(args, []string{"--exit-command-arg", arg}...) args = append(args, []string{"--exit-command-arg", arg}...)
} }
if options.ExitCommandDelay > 0 { if options.ExitCommandDelay > 0 {
args = append(args, []string{"--exit-delay", fmt.Sprintf("%d", options.ExitCommandDelay)}...) args = append(args, []string{"--exit-delay", strconv.FormatUint(uint64(options.ExitCommandDelay), 10)}...)
} }
} }

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
"strconv"
"strings" "strings"
"time" "time"
@ -232,7 +233,7 @@ func makeInspectPorts(bindings []types.PortMapping, expose map[uint16][]string)
hostPorts := portBindings[key] hostPorts := portBindings[key]
hostPorts = append(hostPorts, define.InspectHostPort{ hostPorts = append(hostPorts, define.InspectHostPort{
HostIP: port.HostIP, HostIP: port.HostIP,
HostPort: fmt.Sprintf("%d", port.HostPort+i), HostPort: strconv.FormatUint(uint64(port.HostPort+i), 10),
}) })
portBindings[key] = hostPorts portBindings[key] = hostPorts
} }

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"strconv"
"github.com/containers/common/pkg/cgroups" "github.com/containers/common/pkg/cgroups"
"github.com/containers/podman/v4/libpod" "github.com/containers/podman/v4/libpod"
@ -90,5 +91,5 @@ func pidsToString(pid uint64) string {
// If things go bazinga, return a safe value // If things go bazinga, return a safe value
return "--" return "--"
} }
return fmt.Sprintf("%d", pid) return strconv.FormatUint(pid, 10)
} }

View File

@ -64,10 +64,10 @@ func IsRootless() bool {
if err := os.Setenv("_CONTAINERS_USERNS_CONFIGURED", "done"); err != nil { if err := os.Setenv("_CONTAINERS_USERNS_CONFIGURED", "done"); err != nil {
logrus.Errorf("Failed to set environment variable %s as %s", "_CONTAINERS_USERNS_CONFIGURED", "done") logrus.Errorf("Failed to set environment variable %s as %s", "_CONTAINERS_USERNS_CONFIGURED", "done")
} }
if err := os.Setenv("_CONTAINERS_ROOTLESS_UID", fmt.Sprintf("%d", rootlessUIDInit)); err != nil { if err := os.Setenv("_CONTAINERS_ROOTLESS_UID", strconv.Itoa(rootlessUIDInit)); err != nil {
logrus.Errorf("Failed to set environment variable %s as %d", "_CONTAINERS_ROOTLESS_UID", rootlessUIDInit) logrus.Errorf("Failed to set environment variable %s as %d", "_CONTAINERS_ROOTLESS_UID", rootlessUIDInit)
} }
if err := os.Setenv("_CONTAINERS_ROOTLESS_GID", fmt.Sprintf("%d", rootlessGIDInit)); err != nil { if err := os.Setenv("_CONTAINERS_ROOTLESS_GID", strconv.Itoa(rootlessGIDInit)); err != nil {
logrus.Errorf("Failed to set environment variable %s as %d", "_CONTAINERS_ROOTLESS_GID", rootlessGIDInit) logrus.Errorf("Failed to set environment variable %s as %d", "_CONTAINERS_ROOTLESS_GID", rootlessGIDInit)
} }
} }
@ -132,7 +132,7 @@ func tryMappingTool(uid bool, pid int, hostID int, mappings []idtools.IDMap) err
return append(l, strconv.Itoa(a), strconv.Itoa(b), strconv.Itoa(c)) return append(l, strconv.Itoa(a), strconv.Itoa(b), strconv.Itoa(c))
} }
args := []string{path, fmt.Sprintf("%d", pid)} args := []string{path, strconv.Itoa(pid)}
args = appendTriplet(args, 0, hostID, 1) args = appendTriplet(args, 0, hostID, 1)
for _, i := range mappings { for _, i := range mappings {
if hostID >= i.HostID && hostID < i.HostID+i.Size { if hostID >= i.HostID && hostID < i.HostID+i.Size {

View File

@ -867,7 +867,7 @@ func setupSecurityContext(s *specgen.SpecGenerator, securityContext *v1.Security
runAsUser = podSecurityContext.RunAsUser runAsUser = podSecurityContext.RunAsUser
} }
if runAsUser != nil { if runAsUser != nil {
s.User = fmt.Sprintf("%d", *runAsUser) s.User = strconv.FormatInt(*runAsUser, 10)
} }
runAsGroup := securityContext.RunAsGroup runAsGroup := securityContext.RunAsGroup
@ -881,7 +881,7 @@ func setupSecurityContext(s *specgen.SpecGenerator, securityContext *v1.Security
s.User = fmt.Sprintf("%s:%d", s.User, *runAsGroup) s.User = fmt.Sprintf("%s:%d", s.User, *runAsGroup)
} }
for _, group := range podSecurityContext.SupplementalGroups { for _, group := range podSecurityContext.SupplementalGroups {
s.Groups = append(s.Groups, fmt.Sprintf("%d", group)) s.Groups = append(s.Groups, strconv.FormatInt(group, 10))
} }
} }

View File

@ -1,8 +1,8 @@
package systemd package systemd
import ( import (
"fmt"
"os" "os"
"strconv"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -18,7 +18,7 @@ func TestSocketActivated(t *testing.T) {
assert.False(SocketActivated()) assert.False(SocketActivated())
// same pid no fds // same pid no fds
assert.NoError(os.Setenv("LISTEN_PID", fmt.Sprintf("%d", os.Getpid()))) assert.NoError(os.Setenv("LISTEN_PID", strconv.Itoa(os.Getpid())))
assert.NoError(os.Setenv("LISTEN_FDS", "0")) assert.NoError(os.Setenv("LISTEN_FDS", "0"))
assert.False(SocketActivated()) assert.False(SocketActivated())

View File

@ -500,7 +500,7 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst
} }
if info.GenerateTimestamp { if info.GenerateTimestamp {
info.TimeStamp = fmt.Sprintf("%v", time.Now().Format(time.UnixDate)) info.TimeStamp = time.Now().Format(time.UnixDate)
} }
// Sort the slices to assure a deterministic output. // Sort the slices to assure a deterministic output.
sort.Strings(info.BoundToServices) sort.Strings(info.BoundToServices)

View File

@ -384,7 +384,7 @@ func executePodTemplate(info *podInfo, options entities.GenerateSystemdOptions)
} }
if info.GenerateTimestamp { if info.GenerateTimestamp {
info.TimeStamp = fmt.Sprintf("%v", time.Now().Format(time.UnixDate)) info.TimeStamp = time.Now().Format(time.UnixDate)
} }
// Sort the slices to assure a deterministic output. // Sort the slices to assure a deterministic output.

View File

@ -3,7 +3,7 @@ package timetype
// code adapted from https://github.com/moby/moby/blob/master/api/types/time/timestamp.go // code adapted from https://github.com/moby/moby/blob/master/api/types/time/timestamp.go
import ( import (
"fmt" "strconv"
"testing" "testing"
"time" "time"
) )
@ -47,9 +47,9 @@ func TestGetTimestamp(t *testing.T) {
{"1136073600", "1136073600", false}, {"1136073600", "1136073600", false},
{"1136073600.000000001", "1136073600.000000001", false}, {"1136073600.000000001", "1136073600.000000001", false},
// Durations // Durations
{"1m", fmt.Sprintf("%d", now.Add(-1*time.Minute).Unix()), false}, {"1m", strconv.FormatInt(now.Add(-1*time.Minute).Unix(), 10), false},
{"1.5h", fmt.Sprintf("%d", now.Add(-90*time.Minute).Unix()), false}, {"1.5h", strconv.FormatInt(now.Add(-90*time.Minute).Unix(), 10), false},
{"1h30m", fmt.Sprintf("%d", now.Add(-90*time.Minute).Unix()), false}, {"1h30m", strconv.FormatInt(now.Add(-90*time.Minute).Unix(), 10), false},
{"invalid", "", true}, {"invalid", "", true},
{"", "", true}, {"", "", true},

View File

@ -11,6 +11,7 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strconv"
"syscall" "syscall"
"github.com/containers/podman/v4/pkg/rootless" "github.com/containers/podman/v4/pkg/rootless"
@ -33,7 +34,7 @@ func GetRuntimeDir() (string, error) {
return return
} }
uid := fmt.Sprintf("%d", rootless.GetRootlessUID()) uid := strconv.Itoa(rootless.GetRootlessUID())
if runtimeDir == "" { if runtimeDir == "" {
tmpDir := filepath.Join("/run", "user", uid) tmpDir := filepath.Join("/run", "user", uid)
if err := os.MkdirAll(tmpDir, 0700); err != nil { if err := os.MkdirAll(tmpDir, 0700); err != nil {

View File

@ -1239,7 +1239,7 @@ func GetPort() int {
func ncz(port int) bool { func ncz(port int) bool {
timeout := 500 * time.Millisecond timeout := 500 * time.Millisecond
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
ncCmd := []string{"-z", "localhost", fmt.Sprintf("%d", port)} ncCmd := []string{"-z", "localhost", strconv.Itoa(port)}
GinkgoWriter.Printf("Running: nc %s\n", strings.Join(ncCmd, " ")) GinkgoWriter.Printf("Running: nc %s\n", strings.Join(ncCmd, " "))
check := SystemExec("nc", ncCmd) check := SystemExec("nc", ncCmd)
if check.ExitCode() == 0 { if check.ExitCode() == 0 {

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv"
"strings" "strings"
. "github.com/containers/podman/v4/test/utils" . "github.com/containers/podman/v4/test/utils"
@ -433,7 +434,7 @@ var _ = Describe("Podman create", func() {
numCpus := 5 numCpus := 5
nanoCPUs := numCpus * 1000000000 nanoCPUs := numCpus * 1000000000
ctrName := "testCtr" ctrName := "testCtr"
session := podmanTest.Podman([]string{"create", "-t", "--cpus", fmt.Sprintf("%d", numCpus), "--name", ctrName, ALPINE, "/bin/sh"}) session := podmanTest.Podman([]string{"create", "-t", "--cpus", strconv.Itoa(numCpus), "--name", ctrName, ALPINE, "/bin/sh"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())

View File

@ -3,6 +3,7 @@ package integration
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strconv"
"sync" "sync"
"time" "time"
@ -177,7 +178,7 @@ var _ = Describe("Podman events", func() {
// unix timestamp in 10 seconds // unix timestamp in 10 seconds
until := time.Now().Add(time.Second * 10).Unix() until := time.Now().Add(time.Second * 10).Unix()
result := podmanTest.Podman([]string{"events", "--since", "30s", "--until", fmt.Sprint(until)}) result := podmanTest.Podman([]string{"events", "--since", "30s", "--until", strconv.FormatInt(until, 10)})
result.Wait(11) result.Wait(11)
Expect(result).Should(ExitCleanly()) Expect(result).Should(ExitCleanly())
Expect(result.OutputToString()).To(ContainSubstring(name1)) Expect(result.OutputToString()).To(ContainSubstring(name1))

View File

@ -4957,7 +4957,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q
usernsInCtr = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "id", "-u"}) usernsInCtr = podmanTest.Podman([]string{"exec", getCtrNameInPod(pod), "id", "-u"})
usernsInCtr.WaitWithDefaultTimeout() usernsInCtr.WaitWithDefaultTimeout()
Expect(usernsInCtr).Should(ExitCleanly()) Expect(usernsInCtr).Should(ExitCleanly())
uid := fmt.Sprintf("%d", os.Geteuid()) uid := strconv.Itoa(os.Geteuid())
Expect(string(usernsInCtr.Out.Contents())).To(ContainSubstring(uid)) Expect(string(usernsInCtr.Out.Contents())).To(ContainSubstring(uid))
kube = podmanTest.PodmanNoCache([]string{"kube", "play", "--replace", "--userns=keep-id:uid=10,gid=12", kubeYaml}) kube = podmanTest.PodmanNoCache([]string{"kube", "play", "--replace", "--userns=keep-id:uid=10,gid=12", kubeYaml})

View File

@ -636,7 +636,7 @@ ENTRYPOINT ["sleep","99999"]
session := podmanTest.Podman([]string{"run", "--pod", podName, ALPINE, "id", "-u"}) session := podmanTest.Podman([]string{"run", "--pod", podName, ALPINE, "id", "-u"})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
uid := fmt.Sprintf("%d", os.Geteuid()) uid := strconv.Itoa(os.Geteuid())
Expect(session.OutputToString()).To(ContainSubstring(uid)) Expect(session.OutputToString()).To(ContainSubstring(uid))
// Check passwd // Check passwd

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net" "net"
"os" "os"
"strconv"
"strings" "strings"
"syscall" "syscall"
@ -494,9 +495,9 @@ EXPOSE 2004-2005/tcp`, ALPINE)
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
results := SystemExec("iptables", []string{"-t", "nat", "-nvL"}) results := SystemExec("iptables", []string{"-t", "nat", "-nvL"})
Expect(results).Should(ExitCleanly()) Expect(results).Should(ExitCleanly())
Expect(results.OutputToString()).To(ContainSubstring(fmt.Sprintf("%d", port2))) Expect(results.OutputToString()).To(ContainSubstring(strconv.Itoa(port2)))
ncBusy := SystemExec("nc", []string{"-l", "-p", fmt.Sprintf("%d", port1)}) ncBusy := SystemExec("nc", []string{"-l", "-p", strconv.Itoa(port1)})
Expect(ncBusy).To(ExitWithError()) Expect(ncBusy).To(ExitWithError())
}) })
@ -507,7 +508,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
ncBusy := SystemExec("nc", []string{"-l", "-p", fmt.Sprintf("%d", port2)}) ncBusy := SystemExec("nc", []string{"-l", "-p", strconv.Itoa(port2)})
Expect(ncBusy).To(ExitWithError()) Expect(ncBusy).To(ExitWithError())
}) })
@ -578,11 +579,11 @@ EXPOSE 2004-2005/tcp`, ALPINE)
slirp4netnsHelp := SystemExec("slirp4netns", []string{"--help"}) slirp4netnsHelp := SystemExec("slirp4netns", []string{"--help"})
Expect(slirp4netnsHelp).Should(ExitCleanly()) Expect(slirp4netnsHelp).Should(ExitCleanly())
networkConfiguration := "slirp4netns:outbound_addr=127.0.0.1,allow_host_loopback=true" networkConfiguration := "slirp4netns:outbound_addr=127.0.0.1,allow_host_loopback=true"
port := GetPort() port := strconv.Itoa(GetPort())
if strings.Contains(slirp4netnsHelp.OutputToString(), "outbound-addr") { if strings.Contains(slirp4netnsHelp.OutputToString(), "outbound-addr") {
ncListener := StartSystemExec("nc", []string{"-v", "-n", "-l", "-p", fmt.Sprintf("%d", port)}) ncListener := StartSystemExec("nc", []string{"-v", "-n", "-l", "-p", port})
session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, "-dt", ALPINE, "nc", "-w", "2", "10.0.2.2", fmt.Sprintf("%d", port)}) session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, "-dt", ALPINE, "nc", "-w", "2", "10.0.2.2", port})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
ncListener.WaitWithDefaultTimeout() ncListener.WaitWithDefaultTimeout()
@ -590,7 +591,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
Expect(ncListener).Should(Exit(0)) Expect(ncListener).Should(Exit(0))
Expect(ncListener.ErrorToString()).To(ContainSubstring("Connection from 127.0.0.1")) Expect(ncListener.ErrorToString()).To(ContainSubstring("Connection from 127.0.0.1"))
} else { } else {
session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, "-dt", ALPINE, "nc", "-w", "2", "10.0.2.2", fmt.Sprintf("%d", port)}) session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, "-dt", ALPINE, "nc", "-w", "2", "10.0.2.2", port})
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).To(ExitWithError()) Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported")) Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported"))
@ -604,15 +605,15 @@ EXPOSE 2004-2005/tcp`, ALPINE)
defer conn.Close() defer conn.Close()
ip := conn.LocalAddr().(*net.UDPAddr).IP ip := conn.LocalAddr().(*net.UDPAddr).IP
port := GetPort() port := strconv.Itoa(GetPort())
slirp4netnsHelp := SystemExec("slirp4netns", []string{"--help"}) slirp4netnsHelp := SystemExec("slirp4netns", []string{"--help"})
Expect(slirp4netnsHelp).Should(ExitCleanly()) Expect(slirp4netnsHelp).Should(ExitCleanly())
networkConfiguration := fmt.Sprintf("slirp4netns:outbound_addr=%s,allow_host_loopback=true", ip.String()) networkConfiguration := fmt.Sprintf("slirp4netns:outbound_addr=%s,allow_host_loopback=true", ip.String())
if strings.Contains(slirp4netnsHelp.OutputToString(), "outbound-addr") { if strings.Contains(slirp4netnsHelp.OutputToString(), "outbound-addr") {
ncListener := StartSystemExec("nc", []string{"-v", "-n", "-l", "-p", fmt.Sprintf("%d", port)}) ncListener := StartSystemExec("nc", []string{"-v", "-n", "-l", "-p", port})
session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, ALPINE, "nc", "-w", "2", "10.0.2.2", fmt.Sprintf("%d", port)}) session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, ALPINE, "nc", "-w", "2", "10.0.2.2", port})
session.Wait(30) session.Wait(30)
ncListener.Wait(30) ncListener.Wait(30)
@ -620,7 +621,7 @@ EXPOSE 2004-2005/tcp`, ALPINE)
Expect(ncListener).Should(Exit(0)) Expect(ncListener).Should(Exit(0))
Expect(ncListener.ErrorToString()).To(ContainSubstring("Connection from " + ip.String())) Expect(ncListener.ErrorToString()).To(ContainSubstring("Connection from " + ip.String()))
} else { } else {
session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, ALPINE, "nc", "-w", "2", "10.0.2.2", fmt.Sprintf("%d", port)}) session := podmanTest.Podman([]string{"run", "--network", networkConfiguration, ALPINE, "nc", "-w", "2", "10.0.2.2", port})
session.Wait(30) session.Wait(30)
Expect(session).To(ExitWithError()) Expect(session).To(ExitWithError())
Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported")) Expect(session.ErrorToString()).To(ContainSubstring("outbound_addr not supported"))

View File

@ -5,6 +5,7 @@ import (
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
"strconv"
"strings" "strings"
. "github.com/containers/podman/v4/test/utils" . "github.com/containers/podman/v4/test/utils"
@ -61,7 +62,7 @@ var _ = Describe("Podman UserNS support", func() {
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
// `1024` is the default size or length of the range of user IDs // `1024` is the default size or length of the range of user IDs
// that is mapped between the two user namespaces by --userns=auto. // that is mapped between the two user namespaces by --userns=auto.
Expect(session.OutputToString()).To(ContainSubstring(fmt.Sprintf("%d", storage.AutoUserNsMinSize))) Expect(session.OutputToString()).To(ContainSubstring(strconv.Itoa(storage.AutoUserNsMinSize)))
}) })
It("podman uidmapping and gidmapping", func() { It("podman uidmapping and gidmapping", func() {
@ -116,7 +117,7 @@ var _ = Describe("Podman UserNS support", func() {
session.WaitWithDefaultTimeout() session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly()) Expect(session).Should(ExitCleanly())
uid := fmt.Sprintf("%d", os.Geteuid()) uid := strconv.Itoa(os.Geteuid())
Expect(session.OutputToString()).To(ContainSubstring(uid)) Expect(session.OutputToString()).To(ContainSubstring(uid))
session = podmanTest.Podman([]string{"run", "--userns=keep-id:uid=10,gid=12", "alpine", "sh", "-c", "echo $(id -u):$(id -g)"}) session = podmanTest.Podman([]string{"run", "--userns=keep-id:uid=10,gid=12", "alpine", "sh", "-c", "echo $(id -u):$(id -g)"})

View File

@ -190,7 +190,7 @@ registries = []`
if !WaitContainerReady(podmanTest, "registry", "listening on", 20, 1) { if !WaitContainerReady(podmanTest, "registry", "listening on", 20, 1) {
Fail("Cannot start docker registry on port %s", port) Fail("Cannot start docker registry on port %s", port)
} }
ep := endpoint{Port: fmt.Sprintf("%d", port), Host: "localhost"} ep := endpoint{Port: strconv.Itoa(port), Host: "localhost"}
search := podmanTest.Podman([]string{"search", search := podmanTest.Podman([]string{"search",
fmt.Sprintf("%s/fake/image:andtag", ep.Address()), "--tls-verify=false"}) fmt.Sprintf("%s/fake/image:andtag", ep.Address()), "--tls-verify=false"})
search.WaitWithDefaultTimeout() search.WaitWithDefaultTimeout()
@ -215,7 +215,7 @@ registries = []`
if !WaitContainerReady(podmanTest, "registry3", "listening on", 20, 1) { if !WaitContainerReady(podmanTest, "registry3", "listening on", 20, 1) {
Fail("Cannot start docker registry on port %s", port) Fail("Cannot start docker registry on port %s", port)
} }
ep := endpoint{Port: fmt.Sprintf("%d", port), Host: "localhost"} ep := endpoint{Port: strconv.Itoa(port), Host: "localhost"}
err = podmanTest.RestoreArtifact(ALPINE) err = podmanTest.RestoreArtifact(ALPINE)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
image := fmt.Sprintf("%s/my-alpine", ep.Address()) image := fmt.Sprintf("%s/my-alpine", ep.Address())
@ -242,7 +242,7 @@ registries = []`
} }
port := GetPort() port := GetPort()
ep := endpoint{Port: fmt.Sprintf("%d", port), Host: "localhost"} ep := endpoint{Port: strconv.Itoa(port), Host: "localhost"}
registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%d:5000", port), registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%d:5000", port),
"--name", "registry4", REGISTRY_IMAGE, "/entrypoint.sh", "/etc/docker/registry/config.yml"}) "--name", "registry4", REGISTRY_IMAGE, "/entrypoint.sh", "/etc/docker/registry/config.yml"})
registry.WaitWithDefaultTimeout() registry.WaitWithDefaultTimeout()
@ -286,7 +286,7 @@ registries = []`
Skip("No registry image for ppc64le") Skip("No registry image for ppc64le")
} }
port := GetPort() port := GetPort()
ep := endpoint{Port: fmt.Sprintf("%d", port), Host: "localhost"} ep := endpoint{Port: strconv.Itoa(port), Host: "localhost"}
registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%d:5000", port), registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%d:5000", port),
"--name", "registry5", REGISTRY_IMAGE}) "--name", "registry5", REGISTRY_IMAGE})
registry.WaitWithDefaultTimeout() registry.WaitWithDefaultTimeout()
@ -326,7 +326,7 @@ registries = []`
Skip("No registry image for ppc64le") Skip("No registry image for ppc64le")
} }
port := GetPort() port := GetPort()
ep := endpoint{Port: fmt.Sprintf("%d", port), Host: "localhost"} ep := endpoint{Port: strconv.Itoa(port), Host: "localhost"}
registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%d:5000", port), registry := podmanTest.Podman([]string{"run", "-d", "-p", fmt.Sprintf("%d:5000", port),
"--name", "registry6", REGISTRY_IMAGE}) "--name", "registry6", REGISTRY_IMAGE})
registry.WaitWithDefaultTimeout() registry.WaitWithDefaultTimeout()