Graceful shutdown during podman kube down

Signed-off-by: Andre Marianiello <andremarianiello@users.noreply.github.com>
This commit is contained in:
Andre Marianiello
2024-04-16 15:48:33 -04:00
parent 97f3f9c34e
commit a2cf948f90
2 changed files with 56 additions and 3 deletions

View File

@ -1504,6 +1504,7 @@ func sortKubeKinds(documentList [][]byte) ([][]byte, error) {
return sortedDocumentList, nil
}
func imageNamePrefix(imageName string) string {
prefix := imageName
s := strings.Split(prefix, ":")
@ -1663,7 +1664,10 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, opt
}
// Add the reports
reports.StopReport, err = ic.PodStop(ctx, podNames, entities.PodStopOptions{Ignore: true})
reports.StopReport, err = ic.PodStop(ctx, podNames, entities.PodStopOptions{
Ignore: true,
Timeout: -1,
})
if err != nil {
return nil, err
}

View File

@ -273,8 +273,11 @@ spec:
- name: testctr
image: ` + CITEST_IMAGE + `
command:
- sleep
- inf
- /bin/sh
- -c
- |
trap exit SIGTERM
while :; do sleep 0.1; done
volumeMounts:
- mountPath: /var
name: testing
@ -285,6 +288,30 @@ spec:
claimName: testvol
`
var signalTest = `
apiVersion: v1
kind: Pod
metadata:
name: testpod
spec:
containers:
- name: testctr
image: ` + CITEST_IMAGE + `
command:
- /bin/sh
- -c
- |
trap 'echo TERMINATED > /testvol/termfile; exit' SIGTERM
while true; do sleep 0.1; done
volumeMounts:
- mountPath: /testvol
name: testvol
volumes:
- name: testvol
persistentVolumeClaim:
claimName: testvol
`
var checkInfraImagePodYaml = `
apiVersion: v1
kind: Pod
@ -5568,6 +5595,28 @@ spec:
Expect(checkVol.OutputToString()).To(Equal("testvol1"))
})
It("with graceful shutdown", func() {
volumeCreate := podmanTest.Podman([]string{"volume", "create", "testvol"})
volumeCreate.WaitWithDefaultTimeout()
Expect(volumeCreate).Should(ExitCleanly())
err = writeYaml(signalTest, kubeYaml)
Expect(err).ToNot(HaveOccurred())
playKube := podmanTest.Podman([]string{"kube", "play", kubeYaml})
playKube.WaitWithDefaultTimeout()
Expect(playKube).Should(ExitCleanly())
teardown := podmanTest.Podman([]string{"kube", "down", kubeYaml})
teardown.WaitWithDefaultTimeout()
Expect(teardown).Should(ExitCleanly())
session := podmanTest.Podman([]string{"run", "--volume", "testvol:/testvol", CITEST_IMAGE, "sh", "-c", "cat /testvol/termfile"})
session.WaitWithDefaultTimeout()
Expect(session.OutputToString()).Should(ContainSubstring("TERMINATED"))
})
It("with hostPath subpaths", func() {
if !Containerized() {
Skip("something is wrong with file permissions in CI or in the yaml creation. cannot ls or cat the fs unless in a container")