mirror of
https://github.com/containers/podman.git
synced 2025-07-03 17:27:18 +08:00
Merge pull request #26491 from ArthurWuTW/25389
Pod YAML: Add support for `lifecycle.stopSignal`
This commit is contained in:
@ -112,6 +112,7 @@ Note: **N/A** means that the option cannot be supported in a single-node Podman
|
||||
| resources\.requests | ✅ |
|
||||
| lifecycle\.postStart | no |
|
||||
| lifecycle\.preStop | no |
|
||||
| lifecycle\.stopSignal | ✅ |
|
||||
| terminationMessagePath | no |
|
||||
| terminationMessagePolicy | no |
|
||||
| livenessProbe | ✅ |
|
||||
|
@ -1331,6 +1331,13 @@ type Lifecycle struct {
|
||||
// More info: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#container-hooks
|
||||
// +optional
|
||||
PreStop *Handler `json:"preStop,omitempty"`
|
||||
// StopSignal defines the signal to be sent to the container when stopping.
|
||||
// This value is configured via the container's Lifecycle and overrides any
|
||||
// stop signal defined in the container image. If no StopSignal is specified,
|
||||
// the default signal (SIGTERM) will be used.
|
||||
// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#defining-custom-stop-signals
|
||||
// +optional
|
||||
StopSignal *string `json:"stopSignal,omitempty"`
|
||||
}
|
||||
|
||||
type ConditionStatus string
|
||||
|
@ -656,6 +656,14 @@ func ToSpecGen(ctx context.Context, opts *CtrSpecGenOptions) (*specgen.SpecGener
|
||||
s.StopTimeout = &timeout
|
||||
}
|
||||
|
||||
if lifecycle := opts.Container.Lifecycle; lifecycle != nil && lifecycle.StopSignal != nil {
|
||||
stopSignal, err := util.ParseSignal(*lifecycle.StopSignal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.StopSignal = &stopSignal
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
@ -1444,6 +1444,32 @@ items:
|
||||
restartPolicy: Never
|
||||
`
|
||||
|
||||
var stopSignalSIGUSR1 = `
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: testpod
|
||||
spec:
|
||||
containers:
|
||||
- name: testctr
|
||||
image: ` + CITEST_IMAGE + `
|
||||
lifecycle:
|
||||
stopSignal: SIGUSR1
|
||||
`
|
||||
|
||||
var stopSignalNosuchSignal = `
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: noSuchSigTest
|
||||
spec:
|
||||
containers:
|
||||
- name: test1
|
||||
image: ` + CITEST_IMAGE + `
|
||||
lifecycle:
|
||||
stopSignal: noSuchSignal
|
||||
`
|
||||
|
||||
var (
|
||||
defaultCtrName = "testCtr"
|
||||
defaultCtrCmd = []string{"top"}
|
||||
@ -6223,4 +6249,35 @@ spec:
|
||||
exec := podmanTest.PodmanExitCleanly("exec", "testPod-"+defaultCtrName, "cat", "/sys/fs/cgroup/cpuset.mems.effective")
|
||||
Expect(exec.OutputToString()).To(Equal("0"))
|
||||
})
|
||||
|
||||
It("test Lifecycle stopSignal", func() {
|
||||
|
||||
// Default StopSignal SIGTERM
|
||||
err = writeYaml(simplePodYaml, kubeYaml)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
podmanTest.PodmanExitCleanly("kube", "play", kubeYaml)
|
||||
inspect := podmanTest.PodmanExitCleanly("inspect", "libpod-test-")
|
||||
|
||||
ctr := inspect.InspectContainerToJSON()
|
||||
Expect(ctr[0].Config).To(HaveField("StopSignal", "SIGTERM"))
|
||||
|
||||
// Custom StopSignal SIGUSR1
|
||||
err = writeYaml(stopSignalSIGUSR1, kubeYaml)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
podmanTest.PodmanExitCleanly("kube", "play", kubeYaml)
|
||||
inspect = podmanTest.PodmanExitCleanly("inspect", "testpod-testctr")
|
||||
|
||||
ctr = inspect.InspectContainerToJSON()
|
||||
Expect(ctr[0].Config).To(HaveField("StopSignal", "SIGUSR1"))
|
||||
|
||||
// No such StopSignal
|
||||
err = writeYaml(stopSignalNosuchSignal, kubeYaml)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
session := podmanTest.Podman([]string{"kube", "play", kubeYaml})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(ExitWithError(125, "invalid signal: noSuchSignal"))
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user