aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-08-17 21:08:32 +0200
committerGitHub <noreply@github.com>2020-08-17 21:08:32 +0200
commit8caed305741c8c9e34ec767c9054e3c5e0d33576 (patch)
treea52d68931d6f620ff66ac31b7ca6629b420f7b06 /pkg
parent47108e2e093bae318773998a18f83d0504a402e0 (diff)
parentc4b2078508a45843034a86916b37a52d3e34d20d (diff)
downloadpodman-8caed305741c8c9e34ec767c9054e3c5e0d33576.tar.gz
podman-8caed305741c8c9e34ec767c9054e3c5e0d33576.tar.bz2
podman-8caed305741c8c9e34ec767c9054e3c5e0d33576.zip
Merge pull request #7283 from mheon/pod_infra_has_exit_cmd
Ensure pod infra containers have an exit command
Diffstat (limited to 'pkg')
-rw-r--r--pkg/api/handlers/libpod/pods.go9
-rw-r--r--pkg/bindings/test/pods_test.go6
-rw-r--r--pkg/specgen/generate/pod_create.go16
3 files changed, 25 insertions, 6 deletions
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go
index 10e0d4ce9..6e704fe65 100644
--- a/pkg/api/handlers/libpod/pods.go
+++ b/pkg/api/handlers/libpod/pods.go
@@ -123,10 +123,17 @@ func PodStop(w http.ResponseWriter, r *http.Request) {
} else {
responses, stopError = pod.Stop(r.Context(), false)
}
- if stopError != nil {
+ if stopError != nil && errors.Cause(stopError) != define.ErrPodPartialFail {
utils.Error(w, "Something went wrong", http.StatusInternalServerError, err)
return
}
+ // Try to clean up the pod - but only warn on failure, it's nonfatal.
+ if cleanupCtrs, cleanupErr := pod.Cleanup(r.Context()); cleanupErr != nil {
+ logrus.Errorf("Error cleaning up pod %s: %v", pod.ID(), cleanupErr)
+ for id, err := range cleanupCtrs {
+ logrus.Errorf("Error cleaning up pod %s container %s: %v", pod.ID(), id, err)
+ }
+ }
var errs []error //nolint
for _, err := range responses {
errs = append(errs, err)
diff --git a/pkg/bindings/test/pods_test.go b/pkg/bindings/test/pods_test.go
index 27f648384..8498de020 100644
--- a/pkg/bindings/test/pods_test.go
+++ b/pkg/bindings/test/pods_test.go
@@ -244,7 +244,7 @@ var _ = Describe("Podman pods", func() {
Expect(response.State).To(Equal(define.PodStateExited))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
- To(Equal(define.ContainerStateStopped))
+ To(Equal(define.ContainerStateExited))
}
// Stop an already stopped pod
@@ -309,7 +309,7 @@ var _ = Describe("Podman pods", func() {
Expect(response.State).To(Equal(define.PodStateExited))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
- To(Equal(define.ContainerStateStopped))
+ To(Equal(define.ContainerStateExited))
}
_, err = pods.Stop(bt.conn, newpod2, nil)
Expect(err).To(BeNil())
@@ -318,7 +318,7 @@ var _ = Describe("Podman pods", func() {
Expect(response.State).To(Equal(define.PodStateExited))
for _, i := range response.Containers {
Expect(define.StringToContainerStatus(i.State)).
- To(Equal(define.ContainerStateStopped))
+ To(Equal(define.ContainerStateExited))
}
_, err = pods.Prune(bt.conn)
Expect(err).To(BeNil())
diff --git a/pkg/specgen/generate/pod_create.go b/pkg/specgen/generate/pod_create.go
index 0cbfca2db..0bd39d5a4 100644
--- a/pkg/specgen/generate/pod_create.go
+++ b/pkg/specgen/generate/pod_create.go
@@ -13,14 +13,14 @@ func MakePod(p *specgen.PodSpecGenerator, rt *libpod.Runtime) (*libpod.Pod, erro
if err := p.Validate(); err != nil {
return nil, err
}
- options, err := createPodOptions(p)
+ options, err := createPodOptions(p, rt)
if err != nil {
return nil, err
}
return rt.NewPod(context.Background(), options...)
}
-func createPodOptions(p *specgen.PodSpecGenerator) ([]libpod.PodCreateOption, error) {
+func createPodOptions(p *specgen.PodSpecGenerator, rt *libpod.Runtime) ([]libpod.PodCreateOption, error) {
var (
options []libpod.PodCreateOption
)
@@ -31,6 +31,18 @@ func createPodOptions(p *specgen.PodSpecGenerator) ([]libpod.PodCreateOption, er
return nil, err
}
options = append(options, nsOptions...)
+
+ // Make our exit command
+ storageConfig := rt.StorageConfig()
+ runtimeConfig, err := rt.GetConfig()
+ if err != nil {
+ return nil, err
+ }
+ exitCommand, err := CreateExitCommandArgs(storageConfig, runtimeConfig, logrus.IsLevelEnabled(logrus.DebugLevel), false, false)
+ if err != nil {
+ return nil, errors.Wrapf(err, "error creating infra container exit command")
+ }
+ options = append(options, libpod.WithPodInfraExitCommand(exitCommand))
}
if len(p.CgroupParent) > 0 {
options = append(options, libpod.WithPodCgroupParent(p.CgroupParent))