summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/pods/create.go7
-rw-r--r--docs/source/markdown/podman-pod-create.1.md4
-rw-r--r--go.mod2
-rw-r--r--go.sum6
-rw-r--r--libpod/options.go26
-rw-r--r--libpod/pod.go1
-rw-r--r--libpod/runtime_pod_infra_linux.go6
-rw-r--r--pkg/api/handlers/types.go1
-rw-r--r--pkg/domain/entities/pods.go2
-rw-r--r--pkg/domain/infra/abi/containers.go47
-rw-r--r--pkg/domain/infra/tunnel/containers.go26
-rw-r--r--pkg/specgen/generate/pod_create.go4
-rw-r--r--pkg/specgen/pod_validate.go3
-rw-r--r--pkg/specgen/podspecgen.go6
-rw-r--r--test/e2e/start_test.go1
-rw-r--r--test/system/200-pod.bats17
-rw-r--r--vendor/modules.txt4
17 files changed, 128 insertions, 35 deletions
diff --git a/cmd/podman/pods/create.go b/cmd/podman/pods/create.go
index 0d299bb9c..abc47164b 100644
--- a/cmd/podman/pods/create.go
+++ b/cmd/podman/pods/create.go
@@ -86,6 +86,10 @@ func init() {
flags.String(infraCommandFlagName, containerConfig.Engine.InfraCommand, "The command to run on the infra container when the pod is started")
_ = createCommand.RegisterFlagCompletionFunc(infraCommandFlagName, completion.AutocompleteNone)
+ infraNameFlagName := "infra-name"
+ flags.StringVarP(&createOptions.InfraName, infraNameFlagName, "", "", "The name used as infra container name")
+ _ = createCommand.RegisterFlagCompletionFunc(infraNameFlagName, completion.AutocompleteNone)
+
labelFileFlagName := "label-file"
flags.StringSliceVar(&labelFile, labelFileFlagName, []string{}, "Read in a line delimited file of labels")
_ = createCommand.RegisterFlagCompletionFunc(labelFileFlagName, completion.AutocompleteDefault)
@@ -148,6 +152,9 @@ func create(cmd *cobra.Command, args []string) error {
return errors.New("cannot set infra-image without an infra container")
}
createOptions.InfraImage = ""
+ if createOptions.InfraName != "" {
+ return errors.New("cannot set infra-name without an infra container")
+ }
if cmd.Flag("share").Changed && share != "none" && share != "" {
return fmt.Errorf("cannot set share(%s) namespaces without an infra container", cmd.Flag("share").Value)
diff --git a/docs/source/markdown/podman-pod-create.1.md b/docs/source/markdown/podman-pod-create.1.md
index fecdd8494..441995cb6 100644
--- a/docs/source/markdown/podman-pod-create.1.md
+++ b/docs/source/markdown/podman-pod-create.1.md
@@ -75,6 +75,10 @@ The command that will be run to start the infra container. Default: "/pause".
The image that will be created for the infra container. Default: "k8s.gcr.io/pause:3.1".
+#### **--infra-name**=*name*
+
+The name that will be used for the pod's infra container.
+
#### **--ip**=*ipaddr*
Set a static IP for the pod's shared network.
diff --git a/go.mod b/go.mod
index dd8e1acb2..6a54d363c 100644
--- a/go.mod
+++ b/go.mod
@@ -67,5 +67,5 @@ require (
golang.org/x/sys v0.0.0-20210603125802-9665404d3644
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.21.2
- k8s.io/apimachinery v0.21.2
+ k8s.io/apimachinery v0.21.3
)
diff --git a/go.sum b/go.sum
index 6cf29e438..395a0eb41 100644
--- a/go.sum
+++ b/go.sum
@@ -1432,8 +1432,9 @@ k8s.io/api v0.21.2/go.mod h1:Lv6UGJZ1rlMI1qusN8ruAp9PUBFyBwpEHAdG24vIsiU=
k8s.io/apimachinery v0.20.1/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apimachinery v0.20.4/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU=
k8s.io/apimachinery v0.20.6/go.mod h1:ejZXtW1Ra6V1O5H8xPBGz+T3+4gfkTCeExAHKU57MAc=
-k8s.io/apimachinery v0.21.2 h1:vezUc/BHqWlQDnZ+XkrpXSmnANSLbpnlpwo0Lhk0gpc=
k8s.io/apimachinery v0.21.2/go.mod h1:CdTY8fU/BlvAbJ2z/8kBwimGki5Zp8/fbVuLY8gJumM=
+k8s.io/apimachinery v0.21.3 h1:3Ju4nvjCngxxMYby0BimUk+pQHPOQp3eCGChk5kfVII=
+k8s.io/apimachinery v0.21.3/go.mod h1:H/IM+5vH9kZRNJ4l3x/fXP/5bOPJaVP/guptnZPeCFI=
k8s.io/apiserver v0.20.1/go.mod h1:ro5QHeQkgMS7ZGpvf4tSMx6bBOgPfE+f52KwvXfScaU=
k8s.io/apiserver v0.20.4/go.mod h1:Mc80thBKOyy7tbvFtB4kJv1kbdD0eIH8k8vianJcbFM=
k8s.io/apiserver v0.20.6/go.mod h1:QIJXNt6i6JB+0YQRNcS0hdRHJlMhflFmsBDeSgT1r8Q=
@@ -1465,8 +1466,9 @@ sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.14/go.mod h1:LEScyz
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.15/go.mod h1:LEScyzhFmoF5pso/YSeBstl57mOzx9xlU9n85RGrDQg=
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.0.3/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
-sigs.k8s.io/structured-merge-diff/v4 v4.1.0 h1:C4r9BgJ98vrKnnVCjwCSXcWjWe0NKcUQkmzDXZXGwH8=
sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
+sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3nu+sPzynno=
+sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
diff --git a/libpod/options.go b/libpod/options.go
index bc563d60c..17a36008d 100644
--- a/libpod/options.go
+++ b/libpod/options.go
@@ -459,6 +459,19 @@ func WithDefaultInfraCommand(cmd string) RuntimeOption {
}
}
+// WithDefaultInfraName sets the infra container name for a single pod.
+func WithDefaultInfraName(name string) RuntimeOption {
+ return func(rt *Runtime) error {
+ if rt.valid {
+ return define.ErrRuntimeFinalized
+ }
+
+ rt.config.Engine.InfraImage = name
+
+ return nil
+ }
+}
+
// WithRenumber instructs libpod to perform a lock renumbering while
// initializing. This will handle migrations from early versions of libpod with
// file locks to newer versions with SHM locking, as well as changes in the
@@ -1787,6 +1800,19 @@ func WithInfraCommand(cmd []string) PodCreateOption {
}
}
+// WithInfraName sets the infra container name for a single pod.
+func WithInfraName(name string) PodCreateOption {
+ return func(pod *Pod) error {
+ if pod.valid {
+ return define.ErrPodFinalized
+ }
+
+ pod.config.InfraContainer.InfraName = name
+
+ return nil
+ }
+}
+
// WithPodName sets the name of the pod.
func WithPodName(name string) PodCreateOption {
return func(pod *Pod) error {
diff --git a/libpod/pod.go b/libpod/pod.go
index c03059c82..62f5c9e5b 100644
--- a/libpod/pod.go
+++ b/libpod/pod.go
@@ -112,6 +112,7 @@ type InfraContainerConfig struct {
ExitCommand []string `json:"exitCommand,omitempty"`
InfraImage string `json:"infraImage,omitempty"`
InfraCommand []string `json:"infraCommand,omitempty"`
+ InfraName string `json:"infraName,omitempty"`
Slirp4netns bool `json:"slirp4netns,omitempty"`
NetworkOptions map[string][]string `json:"network_options,omitempty"`
ResourceLimits *specs.LinuxResources `json:"resource_limits,omitempty"`
diff --git a/libpod/runtime_pod_infra_linux.go b/libpod/runtime_pod_infra_linux.go
index 8342352ec..d4f861118 100644
--- a/libpod/runtime_pod_infra_linux.go
+++ b/libpod/runtime_pod_infra_linux.go
@@ -201,7 +201,11 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, rawIm
g.AddLinuxSysctl(sysctlKey, sysctlVal)
}
- containerName := p.ID()[:IDTruncLength] + "-infra"
+ containerName := p.config.InfraContainer.InfraName
+ if containerName == "" {
+ containerName = p.ID()[:IDTruncLength] + "-infra"
+ }
+ logrus.Infof("Infra container name %s", containerName)
options = append(options, r.WithPod(p))
options = append(options, WithRootFSFromImage(imgID, imgName, rawImageName))
options = append(options, WithName(containerName))
diff --git a/pkg/api/handlers/types.go b/pkg/api/handlers/types.go
index 59f948567..3cc10d70f 100644
--- a/pkg/api/handlers/types.go
+++ b/pkg/api/handlers/types.go
@@ -133,6 +133,7 @@ type PodCreateConfig struct {
Infra bool `json:"infra"`
InfraCommand string `json:"infra-command"`
InfraImage string `json:"infra-image"`
+ InfraName string `json:"infra-name"`
Labels []string `json:"labels"`
Publish []string `json:"publish"`
Share string `json:"share"`
diff --git a/pkg/domain/entities/pods.go b/pkg/domain/entities/pods.go
index a0a2a1790..68e335f8d 100644
--- a/pkg/domain/entities/pods.go
+++ b/pkg/domain/entities/pods.go
@@ -112,6 +112,7 @@ type PodCreateOptions struct {
Hostname string
Infra bool
InfraImage string
+ InfraName string
InfraCommand string
InfraConmonPidFile string
Labels map[string]string
@@ -172,6 +173,7 @@ func (p *PodCreateOptions) ToPodSpecGen(s *specgen.PodSpecGenerator) error {
s.InfraConmonPidFile = p.InfraConmonPidFile
}
s.InfraImage = p.InfraImage
+ s.InfraName = p.InfraName
s.SharedNamespaces = p.Share
s.PodCreateCommand = p.CreateCommand
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 2c5300ccb..50751aa12 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -261,6 +261,24 @@ func (ic *ContainerEngine) ContainerRestart(ctx context.Context, namesOrIds []st
return reports, nil
}
+func (ic *ContainerEngine) removeContainer(ctx context.Context, ctr *libpod.Container, options entities.RmOptions) error {
+ err := ic.Libpod.RemoveContainer(ctx, ctr, options.Force, options.Volumes)
+ if err == nil {
+ return nil
+ }
+ logrus.Debugf("Failed to remove container %s: %s", ctr.ID(), err.Error())
+ switch errors.Cause(err) {
+ case define.ErrNoSuchCtr:
+ if options.Ignore {
+ logrus.Debugf("Ignoring error (--allow-missing): %v", err)
+ return nil
+ }
+ case define.ErrCtrRemoved:
+ return nil
+ }
+ return err
+}
+
func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string, options entities.RmOptions) ([]*entities.RmReport, error) {
reports := []*entities.RmReport{}
@@ -318,21 +336,7 @@ func (ic *ContainerEngine) ContainerRm(ctx context.Context, namesOrIds []string,
}
errMap, err := parallelctr.ContainerOp(ctx, ctrs, func(c *libpod.Container) error {
- err := ic.Libpod.RemoveContainer(ctx, c, options.Force, options.Volumes)
- if err == nil {
- return nil
- }
- logrus.Debugf("Failed to remove container %s: %s", c.ID(), err.Error())
- switch errors.Cause(err) {
- case define.ErrNoSuchCtr:
- if options.Ignore {
- logrus.Debugf("Ignoring error (--allow-missing): %v", err)
- return nil
- }
- case define.ErrCtrRemoved:
- return nil
- }
- return err
+ return ic.removeContainer(ctx, c, options)
})
if err != nil {
return nil, err
@@ -791,6 +795,11 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
Err: err,
ExitCode: exitCode,
})
+ if ctr.AutoRemove() {
+ if err := ic.removeContainer(ctx, ctr, entities.RmOptions{}); err != nil {
+ logrus.Errorf("Error removing container %s: %v", ctr.ID(), err)
+ }
+ }
return reports, errors.Wrapf(err, "unable to start container %s", ctr.ID())
}
@@ -827,9 +836,6 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
ExitCode: 125,
}
if err := ctr.Start(ctx, true); err != nil {
- // if lastError != nil {
- // fmt.Fprintln(os.Stderr, lastError)
- // }
report.Err = err
if errors.Cause(err) == define.ErrWillDeadlock {
report.Err = errors.Wrapf(err, "please run 'podman system renumber' to resolve deadlocks")
@@ -838,6 +844,11 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
}
report.Err = errors.Wrapf(err, "unable to start container %q", ctr.ID())
reports = append(reports, report)
+ if ctr.AutoRemove() {
+ if err := ic.removeContainer(ctx, ctr, entities.RmOptions{}); err != nil {
+ logrus.Errorf("Error removing container %s: %v", ctr.ID(), err)
+ }
+ }
continue
}
report.ExitCode = 0
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index 56315f46f..c17d7b54f 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -541,6 +541,17 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
return nil, err
}
removeOptions := new(containers.RemoveOptions).WithVolumes(true).WithForce(false)
+ removeContainer := func(id string) {
+ if err := containers.Remove(ic.ClientCtx, id, removeOptions); err != nil {
+ if errorhandling.Contains(err, define.ErrNoSuchCtr) ||
+ errorhandling.Contains(err, define.ErrCtrRemoved) {
+ logrus.Debugf("Container %s does not exist: %v", id, err)
+ } else {
+ logrus.Errorf("Error removing container %s: %v", id, err)
+ }
+ }
+ }
+
// There can only be one container if attach was used
for i, ctr := range ctrs {
name := ctr.ID
@@ -568,6 +579,9 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
}
if err != nil {
+ if ctr.AutoRemove {
+ removeContainer(ctr.ID)
+ }
report.ExitCode = define.ExitCode(report.Err)
report.Err = err
reports = append(reports, &report)
@@ -582,16 +596,10 @@ func (ic *ContainerEngine) ContainerStart(ctx context.Context, namesOrIds []stri
logrus.Errorf("Failed to check if %s should restart: %v", ctr.ID, err)
return
}
+ logrus.Errorf("Should restart: %v", shouldRestart)
- if !shouldRestart {
- if err := containers.Remove(ic.ClientCtx, ctr.ID, removeOptions); err != nil {
- if errorhandling.Contains(err, define.ErrNoSuchCtr) ||
- errorhandling.Contains(err, define.ErrCtrRemoved) {
- logrus.Debugf("Container %s does not exist: %v", ctr.ID, err)
- } else {
- logrus.Errorf("Error removing container %s: %v", ctr.ID, err)
- }
- }
+ if !shouldRestart && ctr.AutoRemove {
+ removeContainer(ctr.ID)
}
}()
}
diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go
index 4ffd8a37f..aab29499e 100644
--- a/pkg/specgen/generate/pod_create.go
+++ b/pkg/specgen/generate/pod_create.go
@@ -98,6 +98,10 @@ func createPodOptions(p *specgen.PodSpecGenerator, rt *libpod.Runtime) ([]libpod
options = append(options, libpod.WithInfraImage(p.InfraImage))
}
+ if len(p.InfraName) > 0 {
+ options = append(options, libpod.WithInfraName(p.InfraName))
+ }
+
if len(p.InfraCommand) > 0 {
options = append(options, libpod.WithInfraCommand(p.InfraCommand))
}
diff --git a/pkg/specgen/pod_validate.go b/pkg/specgen/pod_validate.go
index c746bcd1a..bca7b6dbe 100644
--- a/pkg/specgen/pod_validate.go
+++ b/pkg/specgen/pod_validate.go
@@ -36,6 +36,9 @@ func (p *PodSpecGenerator) Validate() error {
if len(p.InfraImage) > 0 {
return exclusivePodOptions("NoInfra", "InfraImage")
}
+ if len(p.InfraName) > 0 {
+ return exclusivePodOptions("NoInfra", "InfraName")
+ }
if len(p.SharedNamespaces) > 0 {
return exclusivePodOptions("NoInfra", "SharedNamespaces")
}
diff --git a/pkg/specgen/podspecgen.go b/pkg/specgen/podspecgen.go
index 319345c71..02237afe9 100644
--- a/pkg/specgen/podspecgen.go
+++ b/pkg/specgen/podspecgen.go
@@ -43,6 +43,12 @@ type PodBasicConfig struct {
// Conflicts with NoInfra=true.
// Optional.
InfraImage string `json:"infra_image,omitempty"`
+ // InfraName is the name that will be used for the infra container.
+ // If not set, the default set in the Libpod configuration file will be
+ // used.
+ // Conflicts with NoInfra=true.
+ // Optional.
+ InfraName string `json:"infra_name,omitempty"`
// SharedNamespaces instructs the pod to share a set of namespaces.
// Shared namespaces will be joined (by default) by every container
// which joins the pod.
diff --git a/test/e2e/start_test.go b/test/e2e/start_test.go
index 7799055d9..073631ef7 100644
--- a/test/e2e/start_test.go
+++ b/test/e2e/start_test.go
@@ -65,7 +65,6 @@ var _ = Describe("Podman start", func() {
})
It("podman start --rm --attach removed on failure", func() {
- Skip("FIXME: #10935, race condition removing container")
session := podmanTest.Podman([]string{"create", "--rm", ALPINE, "foo"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
diff --git a/test/system/200-pod.bats b/test/system/200-pod.bats
index 054eda908..266f91298 100644
--- a/test/system/200-pod.bats
+++ b/test/system/200-pod.bats
@@ -205,6 +205,7 @@ function random_ip() {
# entrypoint to confirm that --infra-command will override.
local infra_image="infra_$(random_string 10 | tr A-Z a-z)"
local infra_command="/pause_$(random_string 10)"
+ local infra_name="infra_container_$(random_string 10 | tr A-Z a-z)"
run_podman build -t $infra_image - << EOF
FROM $IMAGE
RUN ln /home/podman/pause $infra_command
@@ -225,7 +226,8 @@ EOF
--publish "$port_out:$port_in" \
--label "${labelname}=${labelvalue}" \
--infra-image "$infra_image" \
- --infra-command "$infra_command"
+ --infra-command "$infra_command" \
+ --infra-name "$infra_name"
pod_id="$output"
# Check --pod-id-file
@@ -237,6 +239,9 @@ EOF
# confirm that entrypoint is what we set
run_podman container inspect --format '{{.Config.Entrypoint}}' $infra_cid
is "$output" "$infra_command" "infra-command took effect"
+ # confirm that infra container name is set
+ run_podman container inspect --format '{{.Name}}' $infra_cid
+ is "$output" "$infra_name" "infra-name took effect"
# Check each of the options
if [ -n "$mac_option" ]; then
@@ -310,6 +315,16 @@ EOF
run_podman rm $cid
run_podman pod rm -f mypod
run_podman rmi $infra_image
+
+}
+
+@test "podman pod create should fail when infra-name is already in use" {
+ local infra_name="infra_container_$(random_string 10 | tr A-Z a-z)"
+ run_podman pod create --infra-name "$infra_name"
+ run_podman '?' pod create --infra-name "$infra_name"
+ if [ $status -eq 0 ]; then
+ die "Podman should fail when user try to create two pods with the same infra-name value"
+ fi
}
# vim: filetype=sh
diff --git a/vendor/modules.txt b/vendor/modules.txt
index a8f85bd9a..30459a32a 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -796,7 +796,7 @@ gopkg.in/yaml.v3
# k8s.io/api v0.21.2
k8s.io/api/apps/v1
k8s.io/api/core/v1
-# k8s.io/apimachinery v0.21.2
+# k8s.io/apimachinery v0.21.3
k8s.io/apimachinery/pkg/api/resource
k8s.io/apimachinery/pkg/apis/meta/v1
k8s.io/apimachinery/pkg/conversion
@@ -820,5 +820,5 @@ k8s.io/apimachinery/pkg/watch
k8s.io/apimachinery/third_party/forked/golang/reflect
# k8s.io/klog/v2 v2.8.0
k8s.io/klog/v2
-# sigs.k8s.io/structured-merge-diff/v4 v4.1.0
+# sigs.k8s.io/structured-merge-diff/v4 v4.1.2
sigs.k8s.io/structured-merge-diff/v4/value