mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Merge pull request #20620 from baude/codecleanup
Automatic code cleanups - JetBrains
This commit is contained in:
@ -39,11 +39,11 @@ func TestPodOptions(t *testing.T) {
|
||||
areEqual = podField.Interface().([]string)[i] == w
|
||||
}
|
||||
case reflect.String:
|
||||
areEqual = (podField.String() == containerField.String())
|
||||
areEqual = podField.String() == containerField.String()
|
||||
case reflect.Bool:
|
||||
areEqual = (podField.Bool() == containerField.Bool())
|
||||
areEqual = podField.Bool() == containerField.Bool()
|
||||
case reflect.Ptr:
|
||||
areEqual = (reflect.DeepEqual(podField.Elem().Interface(), containerField.Elem().Interface()))
|
||||
areEqual = reflect.DeepEqual(podField.Elem().Interface(), containerField.Elem().Interface())
|
||||
}
|
||||
}
|
||||
assert.True(t, areEqual)
|
||||
|
@ -123,7 +123,7 @@ func restore(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
}
|
||||
|
||||
notImport := (!restoreOptions.CheckpointImage && restoreOptions.Import == "")
|
||||
notImport := !restoreOptions.CheckpointImage && restoreOptions.Import == ""
|
||||
|
||||
if notImport && restoreOptions.ImportPrevious != "" {
|
||||
return fmt.Errorf("--import-previous can only be used with image or --import")
|
||||
|
@ -207,7 +207,7 @@ func (s *containerStats) AVGCPU() string {
|
||||
}
|
||||
|
||||
func (s *containerStats) Up() string {
|
||||
return (s.UpTime.String())
|
||||
return s.UpTime.String()
|
||||
}
|
||||
|
||||
func (s *containerStats) MemPerc() string {
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/containers/podman/v4/libpod/driver"
|
||||
"github.com/containers/podman/v4/pkg/util"
|
||||
"github.com/containers/storage/types"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/docker/go-units"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -120,7 +120,7 @@ func ListContainers(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
filterFuncs := make([]libpod.ContainerFilter, 0, len(*filterMap))
|
||||
all := query.All || query.Limit > 0
|
||||
if len((*filterMap)) > 0 {
|
||||
if len(*filterMap) > 0 {
|
||||
for k, v := range *filterMap {
|
||||
generatedFunc, err := filters.GenerateContainerFilterFuncs(k, v, runtime)
|
||||
if err != nil {
|
||||
|
@ -112,7 +112,7 @@ var _ = Describe("Podman images", func() {
|
||||
Expect(code).To(BeNumerically("==", http.StatusNotFound))
|
||||
|
||||
// Start a container with alpine image
|
||||
var top string = "top"
|
||||
var top = "top"
|
||||
_, err = bt.RunTopContainer(&top, nil)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// we should now have a container called "top" running
|
||||
|
@ -76,7 +76,7 @@ var _ = Describe("Podman pods", func() {
|
||||
Expect(podSummary[0].Containers).To(HaveLen(2))
|
||||
|
||||
// Add multiple pods and verify them by name and size.
|
||||
var newpod2 string = "newpod2"
|
||||
var newpod2 = "newpod2"
|
||||
bt.Podcreate(&newpod2)
|
||||
podSummary, err = pods.List(bt.conn, nil)
|
||||
Expect(err).ToNot(HaveOccurred(), "Error from pods.List")
|
||||
@ -218,7 +218,7 @@ var _ = Describe("Podman pods", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
portPublish := fmt.Sprintf("%d:%d", randomport, randomport)
|
||||
var podwithport string = "newpodwithport"
|
||||
var podwithport = "newpodwithport"
|
||||
bt.PodcreateAndExpose(&podwithport, &portPublish)
|
||||
|
||||
// Start pod and expose port 12345
|
||||
@ -226,7 +226,7 @@ var _ = Describe("Podman pods", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Start another pod and expose same port 12345
|
||||
var podwithport2 string = "newpodwithport2"
|
||||
var podwithport2 = "newpodwithport2"
|
||||
bt.PodcreateAndExpose(&podwithport2, &portPublish)
|
||||
|
||||
_, err = pods.Start(bt.conn, podwithport2, nil)
|
||||
@ -298,7 +298,7 @@ var _ = Describe("Podman pods", func() {
|
||||
// Test to validate all the pods in the stopped/exited state are pruned successfully.
|
||||
It("prune pod", func() {
|
||||
// Add a new pod
|
||||
var newpod2 string = "newpod2"
|
||||
var newpod2 = "newpod2"
|
||||
bt.Podcreate(&newpod2)
|
||||
// No pods pruned since no pod in exited state
|
||||
pruneResponse, err := pods.Prune(bt.conn, nil)
|
||||
@ -376,7 +376,7 @@ var _ = Describe("Podman pods", func() {
|
||||
|
||||
// Test validates the pod top bindings
|
||||
It("pod top", func() {
|
||||
var name string = "podA"
|
||||
var name = "podA"
|
||||
|
||||
bt.Podcreate(&name)
|
||||
_, err := pods.Start(bt.conn, name, nil)
|
||||
|
@ -40,7 +40,7 @@ func (ir *ImageEngine) fetchInfo(_ context.Context) (os, arch, variant string, n
|
||||
os, arch, variant = lplatform.Normalize(os, arch, variant)
|
||||
nativePlatform = os + "/" + arch
|
||||
if variant != "" {
|
||||
nativePlatform += ("/" + variant)
|
||||
nativePlatform += "/" + variant
|
||||
}
|
||||
emulatedPlatforms = emulation.Registered()
|
||||
return os, arch, variant, append([]string{}, nativePlatform), emulatedPlatforms, nil
|
||||
|
@ -845,7 +845,7 @@ func transferRootful(source entities.ImageScpOptions, dest entities.ImageScpOpti
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := execTransferPodman(uLoad, loadCommand, (len(dest.Tag) > 0))
|
||||
out, err := execTransferPodman(uLoad, loadCommand, len(dest.Tag) > 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/containers/podman/v4/libpod"
|
||||
"github.com/containers/podman/v4/libpod/define"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"math/big"
|
||||
"strconv"
|
||||
|
||||
inf "gopkg.in/inf.v0"
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
// Scale is used for getting and setting the base-10 scaled value.
|
||||
|
@ -19,7 +19,7 @@ package resource
|
||||
import (
|
||||
"math/big"
|
||||
|
||||
inf "gopkg.in/inf.v0"
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
inf "gopkg.in/inf.v0"
|
||||
"gopkg.in/inf.v0"
|
||||
)
|
||||
|
||||
// Quantity is a fixed-point representation of a number.
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
var originalHomeDir = os.Getenv("HOME")
|
||||
|
||||
const (
|
||||
defaultTimeout time.Duration = 90 * time.Second
|
||||
defaultTimeout = 90 * time.Second
|
||||
)
|
||||
|
||||
type machineCommand interface {
|
||||
|
@ -25,7 +25,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
const (
|
||||
defaultStream machine.FCOSStream = machine.Testing
|
||||
defaultStream = machine.Testing
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -46,7 +46,7 @@ var _ = Describe("podman machine stop", func() {
|
||||
// Stopping it again should not result in an error
|
||||
stopAgain, err := mb.setCmd(stop).run()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(stopAgain).To(Exit((0)))
|
||||
Expect(stopAgain).To(Exit(0))
|
||||
Expect(stopAgain.outputToString()).To(ContainSubstring(fmt.Sprintf("Machine \"%s\" stopped successfully", name)))
|
||||
|
||||
// Stopping a machine should update the last up time
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"github.com/coreos/stream-metadata-go/fedoracoreos"
|
||||
"github.com/coreos/stream-metadata-go/release"
|
||||
"github.com/coreos/stream-metadata-go/stream"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
@ -232,7 +232,7 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
infraVol := (len(compatibleOptions.Mounts) > 0 || len(compatibleOptions.Volumes) > 0 || len(compatibleOptions.ImageVolumes) > 0 || len(compatibleOptions.OverlayVolumes) > 0)
|
||||
infraVol := len(compatibleOptions.Mounts) > 0 || len(compatibleOptions.Volumes) > 0 || len(compatibleOptions.ImageVolumes) > 0 || len(compatibleOptions.OverlayVolumes) > 0
|
||||
opts, err := createContainerOptions(rt, s, pod, finalVolumes, finalOverlays, imageData, command, infraVol, *compatibleOptions)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
|
@ -589,7 +589,7 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
||||
}
|
||||
|
||||
if ro := opts.ReadOnly; ro != itypes.OptionalBoolUndefined {
|
||||
s.ReadOnlyFilesystem = (ro == itypes.OptionalBoolTrue)
|
||||
s.ReadOnlyFilesystem = ro == itypes.OptionalBoolTrue
|
||||
}
|
||||
// This should default to true for kubernetes yaml
|
||||
s.ReadWriteTmpfs = true
|
||||
@ -785,7 +785,7 @@ func makeHealthCheck(inCmd string, interval int32, retries int32, timeout int32,
|
||||
// kubernetes interval defaults to 10 sec and cannot be less than 1
|
||||
interval = 10
|
||||
}
|
||||
hc.Interval = (time.Duration(interval) * time.Second)
|
||||
hc.Interval = time.Duration(interval) * time.Second
|
||||
if retries < 1 {
|
||||
// kubernetes retries defaults to 3
|
||||
retries = 3
|
||||
@ -795,13 +795,13 @@ func makeHealthCheck(inCmd string, interval int32, retries int32, timeout int32,
|
||||
// kubernetes timeout defaults to 1
|
||||
timeout = 1
|
||||
}
|
||||
timeoutDuration := (time.Duration(timeout) * time.Second)
|
||||
timeoutDuration := time.Duration(timeout) * time.Second
|
||||
if timeoutDuration < time.Duration(1) {
|
||||
return nil, errors.New("healthcheck-timeout must be at least 1 second")
|
||||
}
|
||||
hc.Timeout = timeoutDuration
|
||||
|
||||
startPeriodDuration := (time.Duration(startPeriod) * time.Second)
|
||||
startPeriodDuration := time.Duration(startPeriod) * time.Second
|
||||
if startPeriodDuration < time.Duration(0) {
|
||||
return nil, errors.New("healthcheck-start-period must be 0 seconds or greater")
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ var _ = Describe("Verify podman containers.conf usage", func() {
|
||||
session = podmanTest.Podman([]string{"run", "--rm", "--net", "host", fedoraMinimal, "cat", "/proc/sys/net/ipv4/ping_group_range"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.OutputToString()).ToNot((ContainSubstring("1000")))
|
||||
Expect(session.OutputToString()).ToNot(ContainSubstring("1000"))
|
||||
})
|
||||
|
||||
It("search domain", func() {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
define "github.com/containers/podman/v4/libpod/define"
|
||||
"github.com/containers/podman/v4/libpod/define"
|
||||
. "github.com/containers/podman/v4/test/utils"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
|
@ -81,7 +81,7 @@ LABEL marge=mom
|
||||
cwd, err := os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(os.Chdir(yamlDir)).To(Succeed())
|
||||
defer func() { (Expect(os.Chdir(cwd)).To(BeNil())) }()
|
||||
defer func() { Expect(os.Chdir(cwd)).To(Succeed()) }()
|
||||
|
||||
session := podmanTest.Podman([]string{"kube", "play", "top.yaml"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
@ -118,7 +118,7 @@ LABEL marge=mom
|
||||
cwd, err := os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(os.Chdir(yamlDir)).To(Succeed())
|
||||
defer func() { (Expect(os.Chdir(cwd)).To(BeNil())) }()
|
||||
defer func() { Expect(os.Chdir(cwd)).To(Succeed()) }()
|
||||
|
||||
session := podmanTest.Podman([]string{"kube", "play", "top.yaml"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
@ -163,7 +163,7 @@ LABEL marge=mom
|
||||
cwd, err := os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(os.Chdir(yamlDir)).To(Succeed())
|
||||
defer func() { (Expect(os.Chdir(cwd)).To(BeNil())) }()
|
||||
defer func() { Expect(os.Chdir(cwd)).To(Succeed()) }()
|
||||
|
||||
// Build the image into the local store
|
||||
build := podmanTest.Podman([]string{"build", "-t", "foobar", "-f", "Containerfile"})
|
||||
@ -210,7 +210,7 @@ LABEL marge=mom
|
||||
cwd, err := os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(os.Chdir(yamlDir)).To(Succeed())
|
||||
defer func() { (Expect(os.Chdir(cwd)).To(BeNil())) }()
|
||||
defer func() { Expect(os.Chdir(cwd)).To(Succeed()) }()
|
||||
|
||||
// Build the image into the local store
|
||||
build := podmanTest.Podman([]string{"build", "-t", "foobar", "-f", "Containerfile"})
|
||||
@ -257,7 +257,7 @@ LABEL marge=mom
|
||||
cwd, err := os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(os.Chdir(yamlDir)).To(Succeed())
|
||||
defer func() { (Expect(os.Chdir(cwd)).To(BeNil())) }()
|
||||
defer func() { Expect(os.Chdir(cwd)).To(Succeed()) }()
|
||||
|
||||
// Build the image into the local store
|
||||
build := podmanTest.Podman([]string{"build", "-t", "foobar", "-f", "Containerfile"})
|
||||
@ -347,7 +347,7 @@ echo GOT-HERE
|
||||
cwd, err := os.Getwd()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(os.Chdir(yamlDir)).To(Succeed())
|
||||
defer func() { (Expect(os.Chdir(cwd)).To(BeNil())) }()
|
||||
defer func() { Expect(os.Chdir(cwd)).To(Succeed()) }()
|
||||
|
||||
session := podmanTest.Podman([]string{"kube", "play", "echo.yaml"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
|
@ -3820,11 +3820,11 @@ spec:
|
||||
podmanTest.CgroupManager = "systemd"
|
||||
|
||||
var (
|
||||
numReplicas int32 = 3
|
||||
expectedCPURequest string = "100m"
|
||||
expectedCPULimit string = "200m"
|
||||
expectedMemoryRequest string = "10000000"
|
||||
expectedMemoryLimit string = "20000000"
|
||||
numReplicas int32 = 3
|
||||
expectedCPURequest = "100m"
|
||||
expectedCPULimit = "200m"
|
||||
expectedMemoryRequest = "10000000"
|
||||
expectedMemoryLimit = "20000000"
|
||||
)
|
||||
|
||||
expectedCPUQuota := milliCPUToQuota(expectedCPULimit)
|
||||
@ -3869,7 +3869,7 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`})
|
||||
podmanTest.CgroupManager = "systemd"
|
||||
|
||||
var (
|
||||
expectedCPULimit string = "1"
|
||||
expectedCPULimit = "1"
|
||||
)
|
||||
|
||||
deployment := getDeployment(
|
||||
|
@ -424,7 +424,7 @@ var _ = Describe("Podman pod create", func() {
|
||||
session = podmanTest.Podman([]string{"pod", "inspect", "--format", "{{.NumContainers}}", session.OutputToString()})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitCleanly())
|
||||
Expect(session.OutputToString()).Should((Equal("0")))
|
||||
Expect(session.OutputToString()).Should(Equal("0"))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ var _ = Describe("Podman run device", func() {
|
||||
// verify --privileged is required
|
||||
session2 := podmanTest.Podman([]string{"run", ALPINE, "test", "-c", "/dev/kmsg"})
|
||||
session2.WaitWithDefaultTimeout()
|
||||
Expect(session2).Should((Exit(1)))
|
||||
Expect(session2).Should(Exit(1))
|
||||
})
|
||||
|
||||
It("podman run CDI device test", func() {
|
||||
|
@ -116,7 +116,7 @@ USER 1000`, ALPINE)
|
||||
run = podmanTest.Podman([]string{"run", "--passwd=false", "--user", "1234:1234", ALPINE, "cat", "/etc/passwd"})
|
||||
run.WaitWithDefaultTimeout()
|
||||
Expect(run).Should(ExitCleanly())
|
||||
Expect(run.OutputToString()).NotTo((ContainSubstring("1234:1234")))
|
||||
Expect(run.OutputToString()).NotTo(ContainSubstring("1234:1234"))
|
||||
})
|
||||
|
||||
It("podman run --passwd-entry flag", func() {
|
||||
|
@ -1584,7 +1584,7 @@ VOLUME %s`, ALPINE, volPath, volPath)
|
||||
|
||||
curCgroupsBytes, err := os.ReadFile("/proc/self/cgroup")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
var curCgroups string = string(curCgroupsBytes)
|
||||
var curCgroups = string(curCgroupsBytes)
|
||||
GinkgoWriter.Printf("Output:\n%s\n", curCgroups)
|
||||
Expect(curCgroups).To(Not(Equal("")))
|
||||
|
||||
@ -1601,7 +1601,7 @@ VOLUME %s`, ALPINE, volPath, volPath)
|
||||
|
||||
ctrCgroupsBytes, err := os.ReadFile(fmt.Sprintf("/proc/%d/cgroup", pid))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
var ctrCgroups string = string(ctrCgroupsBytes)
|
||||
var ctrCgroups = string(ctrCgroupsBytes)
|
||||
GinkgoWriter.Printf("Output\n:%s\n", ctrCgroups)
|
||||
Expect(curCgroups).To(Not(Equal(ctrCgroups)))
|
||||
})
|
||||
|
@ -182,11 +182,11 @@ var _ = Describe("Toolbox-specific testing", func() {
|
||||
SkipIfNotRootless("only meaningful when run rootless")
|
||||
var session *PodmanSessionIntegration
|
||||
|
||||
var username string = "testuser"
|
||||
var homeDir string = "/home/testuser"
|
||||
var shell string = "/bin/sh"
|
||||
var uid string = "1001"
|
||||
var gid string = "1001"
|
||||
var username = "testuser"
|
||||
var homeDir = "/home/testuser"
|
||||
var shell = "/bin/sh"
|
||||
var uid = "1001"
|
||||
var gid = "1001"
|
||||
|
||||
useradd := fmt.Sprintf("useradd --home-dir %s --shell %s --uid %s %s",
|
||||
homeDir, shell, uid, username)
|
||||
@ -222,8 +222,8 @@ var _ = Describe("Toolbox-specific testing", func() {
|
||||
SkipIfNotRootless("only meaningful when run rootless")
|
||||
var session *PodmanSessionIntegration
|
||||
|
||||
var groupName string = "testgroup"
|
||||
var gid string = "1001"
|
||||
var groupName = "testgroup"
|
||||
var gid = "1001"
|
||||
|
||||
groupadd := fmt.Sprintf("groupadd --gid %s %s", gid, groupName)
|
||||
|
||||
@ -252,15 +252,15 @@ var _ = Describe("Toolbox-specific testing", func() {
|
||||
It("podman create --userns=keep-id - entrypoint - modifying existing user with usermod - add to new group, change home/shell/uid", func() {
|
||||
SkipIfNotRootless("only meaningful when run rootless")
|
||||
var session *PodmanSessionIntegration
|
||||
var badHomeDir string = "/home/badtestuser"
|
||||
var badShell string = "/bin/sh"
|
||||
var badUID string = "1001"
|
||||
var username string = "testuser"
|
||||
var homeDir string = "/home/testuser"
|
||||
var shell string = "/bin/bash"
|
||||
var uid string = "1411"
|
||||
var groupName string = "testgroup"
|
||||
var gid string = "1422"
|
||||
var badHomeDir = "/home/badtestuser"
|
||||
var badShell = "/bin/sh"
|
||||
var badUID = "1001"
|
||||
var username = "testuser"
|
||||
var homeDir = "/home/testuser"
|
||||
var shell = "/bin/bash"
|
||||
var uid = "1411"
|
||||
var groupName = "testgroup"
|
||||
var gid = "1422"
|
||||
|
||||
// The use of bad* in the name of variables does not imply the invocation
|
||||
// of useradd should fail The user is supposed to be created successfully
|
||||
|
Reference in New Issue
Block a user