Skip to content

Commit 6742838

Browse files
authored
Merge pull request #16646 from vrothberg/v4.2-BZ-2144754
[v4.2.0-rhel] container restart: clean up healthcheck state
2 parents 2f3d148 + c7ea09b commit 6742838

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

libpod/container_internal.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,15 @@ func (c *Container) init(ctx context.Context, retainRetries bool) error {
10811081
c.state.RestartCount = 0
10821082
}
10831083

1084+
// bugzilla.redhat.com/show_bug.cgi?id=2144754:
1085+
// In case of a restart, make sure to remove the healthcheck log to
1086+
// have a clean state.
1087+
if path := c.healthCheckLogPath(); path != "" {
1088+
if err := os.Remove(path); err != nil && !errors.Is(err, os.ErrNotExist) {
1089+
logrus.Error(err)
1090+
}
1091+
}
1092+
10841093
if err := c.save(); err != nil {
10851094
return err
10861095
}

test/e2e/search_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ registries = ['{{.Host}}:{{.Port}}']`
7777
search.WaitWithDefaultTimeout()
7878
Expect(search).Should(Exit(0))
7979
Expect(len(search.OutputToStringArray())).To(BeNumerically(">", 1))
80-
Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine"))
80+
Expect(search.OutputToString()).To(ContainSubstring("alpine"))
8181
})
8282

8383
It("podman search single registry flag", func() {
@@ -130,13 +130,13 @@ registries = ['{{.Host}}:{{.Port}}']`
130130
})
131131

132132
It("podman search format json list tags", func() {
133-
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", "alpine"})
133+
search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", ALPINE})
134134
search.WaitWithDefaultTimeout()
135135
Expect(search).Should(Exit(0))
136136
Expect(search.OutputToString()).To(BeValidJSON())
137-
Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine"))
138-
Expect(search.OutputToString()).To(ContainSubstring("3.10"))
139-
Expect(search.OutputToString()).To(ContainSubstring("2.7"))
137+
Expect(search.OutputToString()).To(ContainSubstring("quay.io/libpod/alpine"))
138+
Expect(search.OutputToString()).To(ContainSubstring("3.10.2"))
139+
Expect(search.OutputToString()).To(ContainSubstring("3.2"))
140140
})
141141

142142
// Test for https://github.com/containers/podman/issues/11894

test/system/220-healthcheck.bats

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,34 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\"
7676
run_podman rmi healthcheck_i
7777
}
7878

79+
@test "podman healthcheck - restart cleans up old state" {
80+
ctr="healthcheck_c"
81+
img="healthcheck_i"
82+
83+
_build_health_check_image $img cleanfile
84+
run_podman run -d --name $ctr \
85+
--health-cmd /healthcheck \
86+
--health-retries=2 \
87+
--health-interval=disable \
88+
$img
89+
90+
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
91+
is "$output" "0" "Failing streak of fresh container should be 0"
92+
93+
# Get the healthcheck to fail
94+
run_podman exec $ctr touch /uh-oh
95+
run_podman 1 healthcheck run $ctr
96+
is "$output" "unhealthy" "output from 'podman healthcheck run'"
97+
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
98+
is "$output" "1" "Failing streak after one failed healthcheck should be 1"
99+
100+
run_podman container restart $ctr
101+
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
102+
is "$output" "0" "Failing streak of restarted container should be 0 again"
103+
104+
run_podman rm -f -t0 $ctr
105+
}
106+
79107
@test "podman healthcheck --health-on-failure" {
80108
run_podman 125 create --health-on-failure=kill $IMAGE
81109
is "$output" "Error: cannot set on-failure action to kill without a health check"
@@ -114,6 +142,8 @@ Log[-1].Output | \"Uh-oh on stdout!\\\nUh-oh on stderr!\"
114142
if [[ $policy == "restart" ]];then
115143
# Container has been restarted and health check works again
116144
is "$output" "running $policy" "container has been restarted"
145+
run_podman container inspect $ctr --format "{{.State.Healthcheck.FailingStreak}}"
146+
is "$output" "0" "Failing streak of restarted container should be 0 again"
117147
run_podman healthcheck run $ctr
118148
elif [[ $policy == "none" ]];then
119149
# Container is still running and health check still broken

0 commit comments

Comments
 (0)