Skip to content

Commit

Permalink
Merge pull request #20132 from cgiradkar/Issue-17856
Browse files Browse the repository at this point in the history
Change log level for health_check
  • Loading branch information
openshift-ci[bot] authored Oct 4, 2023
2 parents e78e76c + 7e6e267 commit 3b39d4b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
12 changes: 7 additions & 5 deletions libpod/container_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (c *Container) execStartAndAttach(sessionID string, streams *define.AttachS

logrus.Debugf("Container %s exec session %s completed with exit code %d", c.ID(), session.ID(), exitCode)

if err := justWriteExecExitCode(c, session.ID(), exitCode); err != nil {
if err := justWriteExecExitCode(c, session.ID(), exitCode, !isHealthcheck); err != nil {
if lastErr != nil {
logrus.Errorf("Container %s exec session %s error: %v", c.ID(), session.ID(), lastErr)
}
Expand Down Expand Up @@ -1114,7 +1114,7 @@ func writeExecExitCode(c *Container, sessionID string, exitCode int) error {
return fmt.Errorf("syncing container %s state to remove exec session %s: %w", c.ID(), sessionID, err)
}

return justWriteExecExitCode(c, sessionID, exitCode)
return justWriteExecExitCode(c, sessionID, exitCode, true)
}

func retrieveAndWriteExecExitCode(c *Container, sessionID string) error {
Expand All @@ -1123,12 +1123,14 @@ func retrieveAndWriteExecExitCode(c *Container, sessionID string) error {
return err
}

return justWriteExecExitCode(c, sessionID, exitCode)
return justWriteExecExitCode(c, sessionID, exitCode, true)
}

func justWriteExecExitCode(c *Container, sessionID string, exitCode int) error {
func justWriteExecExitCode(c *Container, sessionID string, exitCode int, emitEvent bool) error {
// Write an event first
c.newExecDiedEvent(sessionID, exitCode)
if emitEvent {
c.newExecDiedEvent(sessionID, exitCode)
}

session, ok := c.state.ExecSessions[sessionID]
if !ok {
Expand Down
2 changes: 1 addition & 1 deletion libpod/healthcheck_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *Container) createTimer(interval string, isStartup bool) error {
return fmt.Errorf("failed to get path for podman for a health check timer: %w", err)
}

var cmd = []string{}
var cmd = []string{"--property", "LogLevelMax=notice"}
if rootless.IsRootless() {
cmd = append(cmd, "--user")
}
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/healthcheck_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ var _ = Describe("Podman healthcheck run", func() {
Expect(ps.OutputToString()).To(ContainSubstring("hc"))
})

It("hc logs do not include exec events", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-cmd", "true", "--health-interval", "5s", "alpine", "sleep", "60"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
hc := podmanTest.Podman([]string{"healthcheck", "run", "hc"})
hc.WaitWithDefaultTimeout()
Expect(hc).Should(ExitCleanly())
hcLogs := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "container=hc", "--filter", "event=exec_died", "--filter", "event=exec", "--since", "1m"})
hcLogs.WaitWithDefaultTimeout()
Expect(hcLogs).Should(ExitCleanly())
hcLogsArray := hcLogs.OutputToStringArray()
Expect(hcLogsArray).To(BeEmpty())
})

It("stopping and then starting a container with healthcheck cmd", func() {
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-cmd", "[\"ls\", \"/foo\"]", ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expand Down

0 comments on commit 3b39d4b

Please sign in to comment.