Skip to content

Commit

Permalink
Merge pull request #22398 from andremarianiello/graceful-kube-down
Browse files Browse the repository at this point in the history
Graceful shutdown during podman kube down
  • Loading branch information
openshift-merge-bot[bot] authored May 13, 2024
2 parents dfab103 + a2cf948 commit abfd022
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,7 @@ func sortKubeKinds(documentList [][]byte) ([][]byte, error) {

return sortedDocumentList, nil
}

func imageNamePrefix(imageName string) string {
prefix := imageName
s := strings.Split(prefix, ":")
Expand Down Expand Up @@ -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
}
Expand Down
53 changes: 51 additions & 2 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -5569,6 +5596,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")
Expand Down

1 comment on commit abfd022

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.