mirror of
https://github.com/containers/podman.git
synced 2025-09-28 01:04:28 +08:00
Fix problems reported by staticcheck
`staticcheck` is a golang code analysis tool. https://staticcheck.io/ This commit fixes a lot of problems found in our code. Common problems are: - unnecessary use of fmt.Sprintf - duplicated imports with different names - unnecessary check that a key exists before a delete call There are still a lot of reported problems in the test files but I have not looked at those. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
@ -1,7 +1,6 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/containers/common/pkg/auth"
|
"github.com/containers/common/pkg/auth"
|
||||||
@ -181,7 +180,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
|
|||||||
createFlags.StringSliceVar(
|
createFlags.StringSliceVar(
|
||||||
&cf.Devices,
|
&cf.Devices,
|
||||||
deviceFlagName, devices(),
|
deviceFlagName, devices(),
|
||||||
fmt.Sprintf("Add a host device to the container"),
|
"Add a host device to the container",
|
||||||
)
|
)
|
||||||
_ = cmd.RegisterFlagCompletionFunc(deviceFlagName, completion.AutocompleteDefault)
|
_ = cmd.RegisterFlagCompletionFunc(deviceFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
@ -359,7 +358,7 @@ func DefineCreateFlags(cmd *cobra.Command, cf *ContainerCLIOpts) {
|
|||||||
&cf.InitPath,
|
&cf.InitPath,
|
||||||
initPathFlagName, initPath(),
|
initPathFlagName, initPath(),
|
||||||
// Do not use the Value field for setting the default value to determine user input (i.e., non-empty string)
|
// Do not use the Value field for setting the default value to determine user input (i.e., non-empty string)
|
||||||
fmt.Sprintf("Path to the container-init binary"),
|
"Path to the container-init binary",
|
||||||
)
|
)
|
||||||
_ = cmd.RegisterFlagCompletionFunc(initPathFlagName, completion.AutocompleteDefault)
|
_ = cmd.RegisterFlagCompletionFunc(initPathFlagName, completion.AutocompleteDefault)
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pruneDescription = fmt.Sprintf(`podman container prune
|
pruneDescription = `podman container prune
|
||||||
|
|
||||||
Removes all non running containers`)
|
Removes all non running containers`
|
||||||
pruneCommand = &cobra.Command{
|
pruneCommand = &cobra.Command{
|
||||||
Use: "prune [options]",
|
Use: "prune [options]",
|
||||||
Short: "Remove all non running containers",
|
Short: "Remove all non running containers",
|
||||||
|
@ -127,23 +127,23 @@ func kube(cmd *cobra.Command, args []string) error {
|
|||||||
|
|
||||||
for _, pod := range report.Pods {
|
for _, pod := range report.Pods {
|
||||||
for _, l := range pod.Logs {
|
for _, l := range pod.Logs {
|
||||||
fmt.Fprintf(os.Stderr, l)
|
fmt.Fprint(os.Stderr, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrsFailed := 0
|
ctrsFailed := 0
|
||||||
|
|
||||||
for _, pod := range report.Pods {
|
for _, pod := range report.Pods {
|
||||||
fmt.Printf("Pod:\n")
|
fmt.Println("Pod:")
|
||||||
fmt.Println(pod.ID)
|
fmt.Println(pod.ID)
|
||||||
|
|
||||||
switch len(pod.Containers) {
|
switch len(pod.Containers) {
|
||||||
case 0:
|
case 0:
|
||||||
continue
|
continue
|
||||||
case 1:
|
case 1:
|
||||||
fmt.Printf("Container:\n")
|
fmt.Println("Container:")
|
||||||
default:
|
default:
|
||||||
fmt.Printf("Containers:\n")
|
fmt.Println("Containers:")
|
||||||
}
|
}
|
||||||
for _, ctr := range pod.Containers {
|
for _, ctr := range pod.Containers {
|
||||||
fmt.Println(ctr)
|
fmt.Println(ctr)
|
||||||
@ -154,7 +154,7 @@ func kube(cmd *cobra.Command, args []string) error {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
for _, err := range pod.ContainerErrors {
|
for _, err := range pod.ContainerErrors {
|
||||||
fmt.Fprintf(os.Stderr, err+"\n")
|
fmt.Fprintln(os.Stderr, err)
|
||||||
}
|
}
|
||||||
// Empty line for space for next block
|
// Empty line for space for next block
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
@ -2,7 +2,6 @@ package pods
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"text/template"
|
"text/template"
|
||||||
@ -21,9 +20,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
inspectDescription = fmt.Sprintf(`Display the configuration for a pod by name or id
|
inspectDescription = `Display the configuration for a pod by name or id
|
||||||
|
|
||||||
By default, this will render all results in a JSON array.`)
|
By default, this will render all results in a JSON array.`
|
||||||
|
|
||||||
inspectCmd = &cobra.Command{
|
inspectCmd = &cobra.Command{
|
||||||
Use: "inspect [options] POD [POD...]",
|
Use: "inspect [options] POD [POD...]",
|
||||||
|
@ -20,7 +20,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pruneDescription = fmt.Sprintf(`podman pod prune Removes all exited pods`)
|
pruneDescription = `podman pod prune Removes all exited pods`
|
||||||
|
|
||||||
pruneCommand = &cobra.Command{
|
pruneCommand = &cobra.Command{
|
||||||
Use: "prune [options]",
|
Use: "prune [options]",
|
||||||
|
@ -25,9 +25,9 @@ type podRmOptionsWrapper struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
rmOptions = podRmOptionsWrapper{}
|
rmOptions = podRmOptionsWrapper{}
|
||||||
podRmDescription = fmt.Sprintf(`podman rm will remove one or more stopped pods and their containers from the host.
|
podRmDescription = `podman rm will remove one or more stopped pods and their containers from the host.
|
||||||
|
|
||||||
The pod name or ID can be used. A pod with containers will not be removed without --force. If --force is specified, all containers will be stopped, then removed.`)
|
The pod name or ID can be used. A pod with containers will not be removed without --force. If --force is specified, all containers will be stopped, then removed.`
|
||||||
rmCommand = &cobra.Command{
|
rmCommand = &cobra.Command{
|
||||||
Use: "rm [options] POD [POD...]",
|
Use: "rm [options] POD [POD...]",
|
||||||
Short: "Remove one or more pods",
|
Short: "Remove one or more pods",
|
||||||
|
@ -20,11 +20,11 @@ import (
|
|||||||
var (
|
var (
|
||||||
pruneOptions = entities.SystemPruneOptions{}
|
pruneOptions = entities.SystemPruneOptions{}
|
||||||
filters []string
|
filters []string
|
||||||
pruneDescription = fmt.Sprintf(`
|
pruneDescription = `
|
||||||
podman system prune
|
podman system prune
|
||||||
|
|
||||||
Remove unused data
|
Remove unused data
|
||||||
`)
|
`
|
||||||
|
|
||||||
pruneCommand = &cobra.Command{
|
pruneCommand = &cobra.Command{
|
||||||
Use: "prune [options]",
|
Use: "prune [options]",
|
||||||
|
@ -80,7 +80,7 @@ func service(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// socket activation uses a unix:// socket in the shipped unit files but apiURI is coded as "" at this layer.
|
// socket activation uses a unix:// socket in the shipped unit files but apiURI is coded as "" at this layer.
|
||||||
if "unix" == uri.Scheme && !registry.IsRemote() {
|
if uri.Scheme == "unix" && !registry.IsRemote() {
|
||||||
if err := syscall.Unlink(uri.Path); err != nil && !os.IsNotExist(err) {
|
if err := syscall.Unlink(uri.Path); err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ import (
|
|||||||
"github.com/containers/storage/pkg/idtools"
|
"github.com/containers/storage/pkg/idtools"
|
||||||
securejoin "github.com/cyphar/filepath-securejoin"
|
securejoin "github.com/cyphar/filepath-securejoin"
|
||||||
runcuser "github.com/opencontainers/runc/libcontainer/user"
|
runcuser "github.com/opencontainers/runc/libcontainer/user"
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
|
||||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/opencontainers/runtime-tools/generate"
|
"github.com/opencontainers/runtime-tools/generate"
|
||||||
"github.com/opencontainers/selinux/go-selinux/label"
|
"github.com/opencontainers/selinux/go-selinux/label"
|
||||||
@ -284,7 +283,7 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
g := generate.NewFromSpec(c.config.Spec)
|
g := generate.Generator{Config: c.config.Spec}
|
||||||
|
|
||||||
// If network namespace was requested, add it now
|
// If network namespace was requested, add it now
|
||||||
if c.config.CreateNetNS {
|
if c.config.CreateNetNS {
|
||||||
@ -400,7 +399,7 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
|
|||||||
return nil, errors.Wrapf(err, "failed to create TempDir in the %s directory", c.config.StaticDir)
|
return nil, errors.Wrapf(err, "failed to create TempDir in the %s directory", c.config.StaticDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
var overlayMount specs.Mount
|
var overlayMount spec.Mount
|
||||||
if volume.ReadWrite {
|
if volume.ReadWrite {
|
||||||
overlayMount, err = overlay.Mount(contentDir, mountPoint, volume.Dest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
|
overlayMount, err = overlay.Mount(contentDir, mountPoint, volume.Dest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
|
||||||
} else {
|
} else {
|
||||||
@ -1482,18 +1481,14 @@ func (c *Container) makeBindMounts() error {
|
|||||||
}
|
}
|
||||||
if newPasswd != "" {
|
if newPasswd != "" {
|
||||||
// Make /etc/passwd
|
// Make /etc/passwd
|
||||||
if _, ok := c.state.BindMounts["/etc/passwd"]; ok {
|
|
||||||
// If it already exists, delete so we can recreate
|
// If it already exists, delete so we can recreate
|
||||||
delete(c.state.BindMounts, "/etc/passwd")
|
delete(c.state.BindMounts, "/etc/passwd")
|
||||||
}
|
|
||||||
c.state.BindMounts["/etc/passwd"] = newPasswd
|
c.state.BindMounts["/etc/passwd"] = newPasswd
|
||||||
}
|
}
|
||||||
if newGroup != "" {
|
if newGroup != "" {
|
||||||
// Make /etc/group
|
// Make /etc/group
|
||||||
if _, ok := c.state.BindMounts["/etc/group"]; ok {
|
|
||||||
// If it already exists, delete so we can recreate
|
// If it already exists, delete so we can recreate
|
||||||
delete(c.state.BindMounts, "/etc/group")
|
delete(c.state.BindMounts, "/etc/group")
|
||||||
}
|
|
||||||
c.state.BindMounts["/etc/group"] = newGroup
|
c.state.BindMounts["/etc/group"] = newGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import (
|
|||||||
"github.com/containers/common/pkg/retry"
|
"github.com/containers/common/pkg/retry"
|
||||||
cp "github.com/containers/image/v5/copy"
|
cp "github.com/containers/image/v5/copy"
|
||||||
"github.com/containers/image/v5/directory"
|
"github.com/containers/image/v5/directory"
|
||||||
"github.com/containers/image/v5/docker/archive"
|
|
||||||
dockerarchive "github.com/containers/image/v5/docker/archive"
|
dockerarchive "github.com/containers/image/v5/docker/archive"
|
||||||
"github.com/containers/image/v5/docker/reference"
|
"github.com/containers/image/v5/docker/reference"
|
||||||
"github.com/containers/image/v5/image"
|
"github.com/containers/image/v5/image"
|
||||||
@ -37,7 +36,6 @@ import (
|
|||||||
"github.com/containers/podman/v2/pkg/util"
|
"github.com/containers/podman/v2/pkg/util"
|
||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
digest "github.com/opencontainers/go-digest"
|
digest "github.com/opencontainers/go-digest"
|
||||||
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
ociv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -185,7 +183,7 @@ func (ir *Runtime) SaveImages(ctx context.Context, namesOrIDs []string, format s
|
|||||||
|
|
||||||
sys := GetSystemContext("", "", false)
|
sys := GetSystemContext("", "", false)
|
||||||
|
|
||||||
archWriter, err := archive.NewWriter(sys, outputFile)
|
archWriter, err := dockerarchive.NewWriter(sys, outputFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -291,7 +289,7 @@ func (ir *Runtime) LoadAllImagesFromDockerArchive(ctx context.Context, fileName
|
|||||||
}
|
}
|
||||||
|
|
||||||
sc := GetSystemContext(signaturePolicyPath, "", false)
|
sc := GetSystemContext(signaturePolicyPath, "", false)
|
||||||
reader, err := archive.NewReader(sc, fileName)
|
reader, err := dockerarchive.NewReader(sc, fileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -1148,7 +1146,7 @@ func (i *Image) GetLabel(ctx context.Context, label string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for k, v := range labels {
|
for k, v := range labels {
|
||||||
if strings.ToLower(k) == strings.ToLower(label) {
|
if strings.EqualFold(k, label) {
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1326,7 +1324,7 @@ func (ir *Runtime) Import(ctx context.Context, path, reference string, writer io
|
|||||||
|
|
||||||
annotations := make(map[string]string)
|
annotations := make(map[string]string)
|
||||||
|
|
||||||
// config imgspecv1.Image
|
// config ociv1.Image
|
||||||
err = updater.ConfigUpdate(imageConfig, annotations)
|
err = updater.ConfigUpdate(imageConfig, annotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error updating image config")
|
return nil, errors.Wrapf(err, "error updating image config")
|
||||||
@ -1435,7 +1433,7 @@ func (i *Image) IsParent(ctx context.Context) (bool, error) {
|
|||||||
|
|
||||||
// historiesMatch returns the number of entries in the histories which have the
|
// historiesMatch returns the number of entries in the histories which have the
|
||||||
// same contents
|
// same contents
|
||||||
func historiesMatch(a, b []imgspecv1.History) int {
|
func historiesMatch(a, b []ociv1.History) int {
|
||||||
i := 0
|
i := 0
|
||||||
for i < len(a) && i < len(b) {
|
for i < len(a) && i < len(b) {
|
||||||
if a[i].Created != nil && b[i].Created == nil {
|
if a[i].Created != nil && b[i].Created == nil {
|
||||||
@ -1468,7 +1466,7 @@ func historiesMatch(a, b []imgspecv1.History) int {
|
|||||||
|
|
||||||
// areParentAndChild checks diff ID and history in the two images and return
|
// areParentAndChild checks diff ID and history in the two images and return
|
||||||
// true if the second should be considered to be directly based on the first
|
// true if the second should be considered to be directly based on the first
|
||||||
func areParentAndChild(parent, child *imgspecv1.Image) bool {
|
func areParentAndChild(parent, child *ociv1.Image) bool {
|
||||||
// the child and candidate parent should share all of the
|
// the child and candidate parent should share all of the
|
||||||
// candidate parent's diff IDs, which together would have
|
// candidate parent's diff IDs, which together would have
|
||||||
// controlled which layers were used
|
// controlled which layers were used
|
||||||
@ -1621,7 +1619,7 @@ func (i *Image) Save(ctx context.Context, source, format, output string, moreTag
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "error getting the OCI directory ImageReference for (%q, %q)", output, destImageName)
|
return errors.Wrapf(err, "error getting the OCI directory ImageReference for (%q, %q)", output, destImageName)
|
||||||
}
|
}
|
||||||
manifestType = imgspecv1.MediaTypeImageManifest
|
manifestType = ociv1.MediaTypeImageManifest
|
||||||
case "docker-dir":
|
case "docker-dir":
|
||||||
destRef, err = directory.NewReference(output)
|
destRef, err = directory.NewReference(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -29,7 +29,7 @@ func generatePruneFilterFuncs(filter, filterValue string) (ImageFilter, error) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for labelKey, labelValue := range labels {
|
for labelKey, labelValue := range labels {
|
||||||
if labelKey == filterKey && ("" == filterValue || labelValue == filterValue) {
|
if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
cp "github.com/containers/image/v5/copy"
|
cp "github.com/containers/image/v5/copy"
|
||||||
"github.com/containers/image/v5/directory"
|
"github.com/containers/image/v5/directory"
|
||||||
"github.com/containers/image/v5/docker"
|
"github.com/containers/image/v5/docker"
|
||||||
"github.com/containers/image/v5/docker/archive"
|
|
||||||
dockerarchive "github.com/containers/image/v5/docker/archive"
|
dockerarchive "github.com/containers/image/v5/docker/archive"
|
||||||
ociarchive "github.com/containers/image/v5/oci/archive"
|
ociarchive "github.com/containers/image/v5/oci/archive"
|
||||||
oci "github.com/containers/image/v5/oci/layout"
|
oci "github.com/containers/image/v5/oci/layout"
|
||||||
@ -130,7 +129,7 @@ func (ir *Runtime) getSinglePullRefPairGoal(srcRef types.ImageReference, destNam
|
|||||||
|
|
||||||
// getPullRefPairsFromDockerArchiveReference returns a slice of pullRefPairs
|
// getPullRefPairsFromDockerArchiveReference returns a slice of pullRefPairs
|
||||||
// for the specified docker reference and the corresponding archive.Reader.
|
// for the specified docker reference and the corresponding archive.Reader.
|
||||||
func (ir *Runtime) getPullRefPairsFromDockerArchiveReference(ctx context.Context, reader *archive.Reader, ref types.ImageReference, sc *types.SystemContext) ([]pullRefPair, error) {
|
func (ir *Runtime) getPullRefPairsFromDockerArchiveReference(ctx context.Context, reader *dockerarchive.Reader, ref types.ImageReference, sc *types.SystemContext) ([]pullRefPair, error) {
|
||||||
destNames, err := reader.ManifestTagsForReference(ref)
|
destNames, err := reader.ManifestTagsForReference(ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -178,7 +177,7 @@ func (ir *Runtime) pullGoalFromImageReference(ctx context.Context, srcRef types.
|
|||||||
// supports pulling from docker-archive, oci, and registries
|
// supports pulling from docker-archive, oci, and registries
|
||||||
switch srcRef.Transport().Name() {
|
switch srcRef.Transport().Name() {
|
||||||
case DockerArchive:
|
case DockerArchive:
|
||||||
reader, readerRef, err := archive.NewReaderForReference(sc, srcRef)
|
reader, readerRef, err := dockerarchive.NewReaderForReference(sc, srcRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -432,7 +431,7 @@ func checkRemoteImageForLabel(ctx context.Context, label string, imageInfo pullR
|
|||||||
}
|
}
|
||||||
// Labels are case insensitive; so we iterate instead of simple lookup
|
// Labels are case insensitive; so we iterate instead of simple lookup
|
||||||
for k := range remoteInspect.Labels {
|
for k := range remoteInspect.Labels {
|
||||||
if strings.ToLower(label) == strings.ToLower(k) {
|
if strings.EqualFold(label, k) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -437,12 +437,8 @@ func (s *InMemoryState) RemoveContainer(ctr *Container) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove our network aliases
|
// Remove our network aliases
|
||||||
if _, ok := s.ctrNetworkAliases[ctr.ID()]; ok {
|
|
||||||
delete(s.ctrNetworkAliases, ctr.ID())
|
delete(s.ctrNetworkAliases, ctr.ID())
|
||||||
}
|
|
||||||
if _, ok := s.ctrNetworks[ctr.ID()]; ok {
|
|
||||||
delete(s.ctrNetworks, ctr.ID())
|
delete(s.ctrNetworks, ctr.ID())
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -680,9 +676,7 @@ func (s *InMemoryState) NetworkDisconnect(ctr *Container, network string) error
|
|||||||
ctrAliases = make(map[string][]string)
|
ctrAliases = make(map[string][]string)
|
||||||
s.ctrNetworkAliases[ctr.ID()] = ctrAliases
|
s.ctrNetworkAliases[ctr.ID()] = ctrAliases
|
||||||
}
|
}
|
||||||
if _, ok := ctrAliases[network]; ok {
|
|
||||||
delete(ctrAliases, network)
|
delete(ctrAliases, network)
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -1523,12 +1517,8 @@ func (s *InMemoryState) RemoveContainerFromPod(pod *Pod, ctr *Container) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove our network aliases
|
// Remove our network aliases
|
||||||
if _, ok := s.ctrNetworkAliases[ctr.ID()]; ok {
|
|
||||||
delete(s.ctrNetworkAliases, ctr.ID())
|
delete(s.ctrNetworkAliases, ctr.ID())
|
||||||
}
|
|
||||||
if _, ok := s.ctrNetworks[ctr.ID()]; ok {
|
|
||||||
delete(s.ctrNetworks, ctr.ID())
|
delete(s.ctrNetworks, ctr.ID())
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ func IfPassesFilter(netconf *libcni.NetworkConfigList, filters map[string][]stri
|
|||||||
filterValue = ""
|
filterValue = ""
|
||||||
}
|
}
|
||||||
for labelKey, labelValue := range labels {
|
for labelKey, labelValue := range labels {
|
||||||
if labelKey == filterKey && ("" == filterValue || labelValue == filterValue) {
|
if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) {
|
||||||
result = true
|
result = true
|
||||||
continue outer
|
continue outer
|
||||||
}
|
}
|
||||||
|
@ -1374,6 +1374,7 @@ func (r *ConmonOCIRuntime) sharedConmonArgs(ctr *Container, cuuid, bundlePath, p
|
|||||||
logDriverArg = define.NoLogging
|
logDriverArg = define.NoLogging
|
||||||
case define.JSONLogging:
|
case define.JSONLogging:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
//lint:ignore ST1015 the default case has to be here
|
||||||
default: //nolint-stylecheck
|
default: //nolint-stylecheck
|
||||||
// No case here should happen except JSONLogging, but keep this here in case the options are extended
|
// No case here should happen except JSONLogging, but keep this here in case the options are extended
|
||||||
logrus.Errorf("%s logging specified but not supported. Choosing k8s-file logging instead", ctr.LogDriver())
|
logrus.Errorf("%s logging specified but not supported. Choosing k8s-file logging instead", ctr.LogDriver())
|
||||||
|
@ -910,7 +910,7 @@ func WithUserNSFrom(nsCtr *Container) CtrCreateOption {
|
|||||||
ctr.config.UserNsCtr = nsCtr.ID()
|
ctr.config.UserNsCtr = nsCtr.ID()
|
||||||
ctr.config.IDMappings = nsCtr.config.IDMappings
|
ctr.config.IDMappings = nsCtr.config.IDMappings
|
||||||
|
|
||||||
g := generate.NewFromSpec(ctr.config.Spec)
|
g := generate.Generator{Config: ctr.config.Spec}
|
||||||
|
|
||||||
g.ClearLinuxUIDMappings()
|
g.ClearLinuxUIDMappings()
|
||||||
for _, uidmap := range nsCtr.config.IDMappings.UIDMap {
|
for _, uidmap := range nsCtr.config.IDMappings.UIDMap {
|
||||||
|
@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/containers/podman/v2/libpod"
|
"github.com/containers/podman/v2/libpod"
|
||||||
"github.com/containers/podman/v2/libpod/define"
|
"github.com/containers/podman/v2/libpod/define"
|
||||||
"github.com/containers/podman/v2/libpod/image"
|
"github.com/containers/podman/v2/libpod/image"
|
||||||
image2 "github.com/containers/podman/v2/libpod/image"
|
|
||||||
"github.com/containers/podman/v2/pkg/api/handlers"
|
"github.com/containers/podman/v2/pkg/api/handlers"
|
||||||
"github.com/containers/podman/v2/pkg/api/handlers/utils"
|
"github.com/containers/podman/v2/pkg/api/handlers/utils"
|
||||||
"github.com/containers/podman/v2/pkg/auth"
|
"github.com/containers/podman/v2/pkg/auth"
|
||||||
@ -524,7 +523,7 @@ func CommitContainer(w http.ResponseWriter, r *http.Request) {
|
|||||||
utils.Error(w, "failed to get runtime config", http.StatusInternalServerError, errors.Wrap(err, "failed to get runtime config"))
|
utils.Error(w, "failed to get runtime config", http.StatusInternalServerError, errors.Wrap(err, "failed to get runtime config"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
sc := image2.GetSystemContext(rtc.Engine.SignaturePolicyPath, "", false)
|
sc := image.GetSystemContext(rtc.Engine.SignaturePolicyPath, "", false)
|
||||||
tag := "latest"
|
tag := "latest"
|
||||||
options := libpod.ContainerCommitOptions{
|
options := libpod.ContainerCommitOptions{
|
||||||
Pause: true,
|
Pause: true,
|
||||||
|
@ -35,7 +35,7 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
|
|||||||
filterValue = ""
|
filterValue = ""
|
||||||
}
|
}
|
||||||
for labelKey, labelValue := range labels {
|
for labelKey, labelValue := range labels {
|
||||||
if labelKey == filterKey && ("" == filterValue || labelValue == filterValue) {
|
if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) {
|
||||||
matched = true
|
matched = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func GeneratePodFilterFunc(filter string, filterValues []string) (
|
|||||||
filterValue = ""
|
filterValue = ""
|
||||||
}
|
}
|
||||||
for labelKey, labelValue := range labels {
|
for labelKey, labelValue := range labels {
|
||||||
if labelKey == filterKey && ("" == filterValue || labelValue == filterValue) {
|
if labelKey == filterKey && (filterValue == "" || labelValue == filterValue) {
|
||||||
matched = true
|
matched = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) {
|
|||||||
}
|
}
|
||||||
vf = append(vf, func(v *libpod.Volume) bool {
|
vf = append(vf, func(v *libpod.Volume) bool {
|
||||||
for labelKey, labelValue := range v.Labels() {
|
for labelKey, labelValue := range v.Labels() {
|
||||||
if labelKey == filterKey && ("" == filterVal || labelValue == filterVal) {
|
if labelKey == filterKey && (filterVal == "" || labelValue == filterVal) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) {
|
|||||||
}
|
}
|
||||||
vf = append(vf, func(v *libpod.Volume) bool {
|
vf = append(vf, func(v *libpod.Volume) bool {
|
||||||
for labelKey, labelValue := range v.Options() {
|
for labelKey, labelValue := range v.Options() {
|
||||||
if labelKey == filterKey && ("" == filterVal || labelValue == filterVal) {
|
if labelKey == filterKey && (filterVal == "" || labelValue == filterVal) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,15 +113,7 @@ func (ic *ContainerEngine) ContainerWait(ctx context.Context, namesOrIds []strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
|
func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
|
||||||
var (
|
ctrs, err := getContainersByContext(options.All, false, namesOrIds, ic.Libpod)
|
||||||
err error
|
|
||||||
)
|
|
||||||
ctrs := []*libpod.Container{} //nolint
|
|
||||||
if options.All {
|
|
||||||
ctrs, err = ic.Libpod.GetAllContainers()
|
|
||||||
} else {
|
|
||||||
ctrs, err = getContainersByContext(false, false, namesOrIds, ic.Libpod)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -134,15 +126,7 @@ func (ic *ContainerEngine) ContainerPause(ctx context.Context, namesOrIds []stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ic *ContainerEngine) ContainerUnpause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
|
func (ic *ContainerEngine) ContainerUnpause(ctx context.Context, namesOrIds []string, options entities.PauseUnPauseOptions) ([]*entities.PauseUnpauseReport, error) {
|
||||||
var (
|
ctrs, err := getContainersByContext(options.All, false, namesOrIds, ic.Libpod)
|
||||||
err error
|
|
||||||
)
|
|
||||||
ctrs := []*libpod.Container{} //nolint
|
|
||||||
if options.All {
|
|
||||||
ctrs, err = ic.Libpod.GetAllContainers()
|
|
||||||
} else {
|
|
||||||
ctrs, err = getContainersByContext(false, false, namesOrIds, ic.Libpod)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/containers/image/v5/types"
|
"github.com/containers/image/v5/types"
|
||||||
"github.com/containers/podman/v2/libpod/define"
|
"github.com/containers/podman/v2/libpod/define"
|
||||||
"github.com/containers/podman/v2/libpod/image"
|
"github.com/containers/podman/v2/libpod/image"
|
||||||
libpodImage "github.com/containers/podman/v2/libpod/image"
|
|
||||||
"github.com/containers/podman/v2/pkg/domain/entities"
|
"github.com/containers/podman/v2/pkg/domain/entities"
|
||||||
"github.com/containers/podman/v2/pkg/domain/entities/reports"
|
"github.com/containers/podman/v2/pkg/domain/entities/reports"
|
||||||
domainUtils "github.com/containers/podman/v2/pkg/domain/utils"
|
domainUtils "github.com/containers/podman/v2/pkg/domain/utils"
|
||||||
@ -206,7 +205,7 @@ func (ir *ImageEngine) Unmount(ctx context.Context, nameOrIDs []string, options
|
|||||||
return reports, nil
|
return reports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToDomainHistoryLayer(layer *libpodImage.History) entities.ImageHistoryLayer {
|
func ToDomainHistoryLayer(layer *image.History) entities.ImageHistoryLayer {
|
||||||
l := entities.ImageHistoryLayer{}
|
l := entities.ImageHistoryLayer{}
|
||||||
l.ID = layer.ID
|
l.ID = layer.ID
|
||||||
l.Created = *layer.Created
|
l.Created = *layer.Created
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
|
|
||||||
"github.com/containers/buildah/manifests"
|
"github.com/containers/buildah/manifests"
|
||||||
buildahManifests "github.com/containers/buildah/pkg/manifests"
|
buildahManifests "github.com/containers/buildah/pkg/manifests"
|
||||||
"github.com/containers/buildah/util"
|
|
||||||
buildahUtil "github.com/containers/buildah/util"
|
buildahUtil "github.com/containers/buildah/util"
|
||||||
cp "github.com/containers/image/v5/copy"
|
cp "github.com/containers/image/v5/copy"
|
||||||
"github.com/containers/image/v5/docker"
|
"github.com/containers/image/v5/docker"
|
||||||
@ -60,7 +59,7 @@ func (ir *ImageEngine) ManifestInspect(ctx context.Context, name string) ([]byte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sc := ir.Libpod.SystemContext()
|
sc := ir.Libpod.SystemContext()
|
||||||
refs, err := util.ResolveNameToReferences(ir.Libpod.GetStore(), sc, name)
|
refs, err := buildahUtil.ResolveNameToReferences(ir.Libpod.GetStore(), sc, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -162,11 +162,6 @@ func movePauseProcessToScope(r *libpod.Runtime) error {
|
|||||||
return utils.RunUnderSystemdScope(int(pid), "user.slice", "podman-pause.scope")
|
return utils.RunUnderSystemdScope(int(pid), "user.slice", "podman-pause.scope")
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkInput can be used to verify any of the globalopt values
|
|
||||||
func checkInput() error { // nolint:deadcode,unused
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images.
|
// SystemPrune removes unused data from the system. Pruning pods, containers, volumes and images.
|
||||||
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
|
func (ic *ContainerEngine) SystemPrune(ctx context.Context, options entities.SystemPruneOptions) (*entities.SystemPruneReport, error) {
|
||||||
var systemPruneReport = new(entities.SystemPruneReport)
|
var systemPruneReport = new(entities.SystemPruneReport)
|
||||||
|
@ -21,9 +21,6 @@ var (
|
|||||||
errNotADevice = errors.New("not a device node")
|
errNotADevice = errors.New("not a device node")
|
||||||
)
|
)
|
||||||
|
|
||||||
func u32Ptr(i int64) *uint32 { u := uint32(i); return &u }
|
|
||||||
func fmPtr(i int64) *os.FileMode { fm := os.FileMode(i); return &fm }
|
|
||||||
|
|
||||||
func addPrivilegedDevices(g *generate.Generator) error {
|
func addPrivilegedDevices(g *generate.Generator) error {
|
||||||
hostDevices, err := getDevices("/dev")
|
hostDevices, err := getDevices("/dev")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -110,7 +110,7 @@ func makeCommand(ctx context.Context, s *specgen.SpecGenerator, img *image.Image
|
|||||||
// Only use image command if the user did not manually set an
|
// Only use image command if the user did not manually set an
|
||||||
// entrypoint.
|
// entrypoint.
|
||||||
command := s.Command
|
command := s.Command
|
||||||
if (command == nil || len(command) == 0) && img != nil && (s.Entrypoint == nil || len(s.Entrypoint) == 0) {
|
if len(command) == 0 && img != nil && len(s.Entrypoint) == 0 {
|
||||||
newCmd, err := img.Cmd(ctx)
|
newCmd, err := img.Cmd(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -124,15 +124,11 @@ func finalizeMounts(ctx context.Context, s *specgen.SpecGenerator, rt *libpod.Ru
|
|||||||
// named volumes, and vice versa.
|
// named volumes, and vice versa.
|
||||||
// We'll delete the conflicts here as we supersede.
|
// We'll delete the conflicts here as we supersede.
|
||||||
for dest := range unifiedMounts {
|
for dest := range unifiedMounts {
|
||||||
if _, ok := baseVolumes[dest]; ok {
|
|
||||||
delete(baseVolumes, dest)
|
delete(baseVolumes, dest)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for dest := range unifiedVolumes {
|
for dest := range unifiedVolumes {
|
||||||
if _, ok := baseMounts[dest]; ok {
|
|
||||||
delete(baseMounts, dest)
|
delete(baseMounts, dest)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Supersede volumes-from/image volumes with unified volumes from above.
|
// Supersede volumes-from/image volumes with unified volumes from above.
|
||||||
// This is an unconditional replacement.
|
// This is an unconditional replacement.
|
||||||
|
@ -48,7 +48,7 @@ func verifyContainerResourcesCgroupV1(s *specgen.SpecGenerator) ([]string, error
|
|||||||
warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, or the cgroup is not mounted. Memory swappiness discarded.")
|
warnings = append(warnings, "Your kernel does not support memory swappiness capabilities, or the cgroup is not mounted. Memory swappiness discarded.")
|
||||||
memory.Swappiness = nil
|
memory.Swappiness = nil
|
||||||
} else {
|
} else {
|
||||||
if *memory.Swappiness < 0 || *memory.Swappiness > 100 {
|
if *memory.Swappiness > 100 {
|
||||||
return warnings, errors.Errorf("invalid value: %v, valid memory swappiness range is 0-100", *memory.Swappiness)
|
return warnings, errors.Errorf("invalid value: %v, valid memory swappiness range is 0-100", *memory.Swappiness)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user