summaryrefslogtreecommitdiff
path: root/pkg/domain/infra/abi
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/domain/infra/abi')
-rw-r--r--pkg/domain/infra/abi/containers.go9
-rw-r--r--pkg/domain/infra/abi/images.go2
-rw-r--r--pkg/domain/infra/abi/pods.go85
-rw-r--r--pkg/domain/infra/abi/terminal/sigproxy_linux.go2
-rw-r--r--pkg/domain/infra/abi/volumes.go2
5 files changed, 95 insertions, 5 deletions
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 8bd84a310..c7cd0cb56 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -1593,6 +1593,11 @@ func (ic *ContainerEngine) ContainerClone(ctx context.Context, ctrCloneOpts enti
return nil, err
}
+ conf := c.Config()
+ if conf.Spec != nil && conf.Spec.Process != nil && conf.Spec.Process.Terminal { // if we do not pass term, running ctrs exit
+ spec.Terminal = true
+ }
+
// Print warnings
if len(out) > 0 {
for _, w := range out {
@@ -1612,8 +1617,8 @@ func (ic *ContainerEngine) ContainerClone(ctx context.Context, ctrCloneOpts enti
switch {
case strings.Contains(n, "-clone"):
ind := strings.Index(n, "-clone") + 6
- num, _ := strconv.Atoi(n[ind:])
- if num == 0 { // clone1 is hard to get with this logic, just check for it here.
+ num, err := strconv.Atoi(n[ind:])
+ if num == 0 && err != nil { // clone1 is hard to get with this logic, just check for it here.
_, err = ic.Libpod.LookupContainer(n + "1")
if err != nil {
spec.Name = n + "1"
diff --git a/pkg/domain/infra/abi/images.go b/pkg/domain/infra/abi/images.go
index d469fa0ca..d63de2424 100644
--- a/pkg/domain/infra/abi/images.go
+++ b/pkg/domain/infra/abi/images.go
@@ -593,7 +593,7 @@ func (ir *ImageEngine) Remove(ctx context.Context, images []string, opts entitie
rmErrors = libimageErrors
- return //nolint
+ return
}
// Shutdown Libpod engine
diff --git a/pkg/domain/infra/abi/pods.go b/pkg/domain/infra/abi/pods.go
index 32deb20e0..8638f4783 100644
--- a/pkg/domain/infra/abi/pods.go
+++ b/pkg/domain/infra/abi/pods.go
@@ -2,12 +2,15 @@ package abi
import (
"context"
+ "strconv"
+ "strings"
"github.com/containers/podman/v4/libpod"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/domain/entities"
dfilters "github.com/containers/podman/v4/pkg/domain/filters"
"github.com/containers/podman/v4/pkg/signal"
+ "github.com/containers/podman/v4/pkg/specgen"
"github.com/containers/podman/v4/pkg/specgen/generate"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -295,6 +298,88 @@ func (ic *ContainerEngine) PodCreate(ctx context.Context, specg entities.PodSpec
return &entities.PodCreateReport{Id: pod.ID()}, nil
}
+func (ic *ContainerEngine) PodClone(ctx context.Context, podClone entities.PodCloneOptions) (*entities.PodCloneReport, error) {
+ spec := specgen.NewPodSpecGenerator()
+ p, err := generate.PodConfigToSpec(ic.Libpod, spec, &podClone.InfraOptions, podClone.ID)
+ if err != nil {
+ return nil, err
+ }
+
+ if len(podClone.CreateOpts.Name) > 0 {
+ spec.Name = podClone.CreateOpts.Name
+ } else {
+ n := p.Name()
+ _, err := ic.Libpod.LookupPod(n + "-clone")
+ if err == nil {
+ n += "-clone"
+ }
+ switch {
+ case strings.Contains(n, "-clone"): // meaning this name is taken!
+ ind := strings.Index(n, "-clone") + 6
+ num, err := strconv.Atoi(n[ind:])
+ if num == 0 && err != nil { // meaning invalid
+ _, err = ic.Libpod.LookupPod(n + "1")
+ if err != nil {
+ spec.Name = n + "1"
+ break
+ }
+ } else { // else we already have a number
+ n = n[0:ind]
+ }
+ err = nil
+ count := num
+ for err == nil { // until we cannot find a pod w/ this name, increment num and try again
+ count++
+ tempN := n + strconv.Itoa(count)
+ _, err = ic.Libpod.LookupPod(tempN)
+ }
+ n += strconv.Itoa(count)
+ spec.Name = n
+ default:
+ spec.Name = p.Name() + "-clone"
+ }
+ }
+
+ podSpec := entities.PodSpec{PodSpecGen: *spec}
+ pod, err := generate.MakePod(&podSpec, ic.Libpod)
+ if err != nil {
+ return nil, err
+ }
+
+ ctrs, err := p.AllContainers()
+ if err != nil {
+ return nil, err
+ }
+ for _, ctr := range ctrs {
+ if ctr.IsInfra() {
+ continue // already copied infra
+ }
+
+ podClone.PerContainerOptions.Pod = pod.ID()
+ _, err := ic.ContainerClone(ctx, entities.ContainerCloneOptions{ID: ctr.ID(), CreateOpts: podClone.PerContainerOptions})
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ if podClone.Destroy {
+ var timeout *uint
+ err = ic.Libpod.RemovePod(ctx, p, true, true, timeout)
+ if err != nil {
+ return &entities.PodCloneReport{Id: pod.ID()}, err
+ }
+ }
+
+ if podClone.Start {
+ _, err := ic.PodStart(ctx, []string{pod.ID()}, entities.PodStartOptions{})
+ if err != nil {
+ return &entities.PodCloneReport{Id: pod.ID()}, err
+ }
+ }
+
+ return &entities.PodCloneReport{Id: pod.ID()}, nil
+}
+
func (ic *ContainerEngine) PodTop(ctx context.Context, options entities.PodTopOptions) (*entities.StringSliceReport, error) {
var (
pod *libpod.Pod
diff --git a/pkg/domain/infra/abi/terminal/sigproxy_linux.go b/pkg/domain/infra/abi/terminal/sigproxy_linux.go
index fe2c268c0..e02c0532c 100644
--- a/pkg/domain/infra/abi/terminal/sigproxy_linux.go
+++ b/pkg/domain/infra/abi/terminal/sigproxy_linux.go
@@ -20,7 +20,7 @@ const signalBufferSize = 2048
func ProxySignals(ctr *libpod.Container) {
// Stop catching the shutdown signals (SIGINT, SIGTERM) - they're going
// to the container now.
- shutdown.Stop() // nolint: errcheck
+ shutdown.Stop() //nolint: errcheck
sigBuffer := make(chan os.Signal, signalBufferSize)
signal.CatchAll(sigBuffer)
diff --git a/pkg/domain/infra/abi/volumes.go b/pkg/domain/infra/abi/volumes.go
index f59f11e20..a9c53c140 100644
--- a/pkg/domain/infra/abi/volumes.go
+++ b/pkg/domain/infra/abi/volumes.go
@@ -172,7 +172,7 @@ func (ic *ContainerEngine) VolumeMounted(ctx context.Context, nameOrID string) (
mountCount, err := vol.MountCount()
if err != nil {
// FIXME: this error should probably be returned
- return &entities.BoolReport{Value: false}, nil // nolint: nilerr
+ return &entities.BoolReport{Value: false}, nil //nolint: nilerr
}
if mountCount > 0 {
return &entities.BoolReport{Value: true}, nil