Skip to content

Commit f75c638

Browse files
committed
Address PR comments
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent f12e708 commit f75c638

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

cmd/nerdctl/container/container_health_check_linux_test.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package container
1919
import (
2020
"encoding/json"
2121
"errors"
22+
"fmt"
2223
"strings"
2324
"testing"
2425
"time"
@@ -138,10 +139,6 @@ func TestContainerHealthCheckBasic(t *testing.T) {
138139
}
139140

140141
func TestContainerHealthCheckAdvance(t *testing.T) {
141-
if rootlessutil.IsRootless() {
142-
t.Skip("healthcheck tests are skipped in rootless environment")
143-
}
144-
145142
testCase := nerdtest.Setup()
146143

147144
// Docker CLI does not provide a standalone healthcheck command.
@@ -399,6 +396,43 @@ func TestContainerHealthCheckAdvance(t *testing.T) {
399396
}
400397
},
401398
},
399+
{
400+
Description: "Healthcheck emits large output repeatedly",
401+
Setup: func(data test.Data, helpers test.Helpers) {
402+
helpers.Ensure("run", "-d", "--name", data.Identifier(),
403+
"--health-cmd", "yes X | head -c 60000",
404+
"--health-interval", "1s", "--health-timeout", "2s",
405+
testutil.CommonImage, "sleep", nerdtest.Infinity)
406+
nerdtest.EnsureContainerStarted(helpers, data.Identifier())
407+
},
408+
Cleanup: func(data test.Data, helpers test.Helpers) {
409+
helpers.Anyhow("rm", "-f", data.Identifier())
410+
},
411+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
412+
for i := 0; i < 3; i++ {
413+
helpers.Ensure("container", "healthcheck", data.Identifier())
414+
time.Sleep(2 * time.Second)
415+
}
416+
return helpers.Command("inspect", data.Identifier())
417+
},
418+
Expected: func(data test.Data, helpers test.Helpers) *test.Expected {
419+
return &test.Expected{
420+
ExitCode: 0,
421+
Output: expect.All(func(_ string, t tig.T) {
422+
inspect := nerdtest.InspectContainer(helpers, data.Identifier())
423+
h := inspect.State.Health
424+
debug, _ := json.MarshalIndent(h, "", " ")
425+
t.Log(string(debug))
426+
assert.Assert(t, h != nil, "expected health state")
427+
assert.Equal(t, h.Status, healthcheck.Healthy)
428+
assert.Assert(t, len(h.Log) >= 3, "expected at least 3 health log entries")
429+
for _, log := range h.Log {
430+
assert.Assert(t, len(log.Output) >= 1024, fmt.Sprintf("each output should be >= 1024 bytes, was: %s", log.Output))
431+
}
432+
}),
433+
}
434+
},
435+
},
402436
{
403437
Description: "Health log in inspect keeps only the latest 5 entries",
404438
Setup: func(data test.Data, helpers test.Helpers) {

pkg/containerutil/containerutil.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,6 @@ func Stop(ctx context.Context, container containerd.Container, timeout *time.Dur
359359
}
360360
}()
361361

362-
// Clean up healthcheck units if configured.
363-
// if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, container); err != nil {
364-
// return fmt.Errorf("failed to clean up healthcheck units for container %s", container.ID())
365-
// }
366-
367362
if timeout == nil {
368363
t, ok := l[labels.StopTimeout]
369364
if !ok {
@@ -502,11 +497,6 @@ func Pause(ctx context.Context, client *containerd.Client, id string) error {
502497
return err
503498
}
504499

505-
// Clean up healthcheck units if configured.
506-
// if err := healthcheck.RemoveTransientHealthCheckFiles(ctx, container); err != nil {
507-
// return fmt.Errorf("failed to clean up healthcheck units for container %s", container.ID())
508-
// }
509-
510500
switch status.Status {
511501
case containerd.Paused:
512502
return fmt.Errorf("container %s is already paused", id)

pkg/healthcheck/healthcheck_manager_linux.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ func CreateTimer(ctx context.Context, container containerd.Container) error {
5050
logrus.Debugf("Creating healthcheck timer unit: %s", hcName)
5151

5252
cmd := []string{}
53-
if rootlessutil.IsRootless() {
54-
cmd = append(cmd, "--user")
55-
}
5653
if path := os.Getenv("PATH"); path != "" {
5754
cmd = append(cmd, "--setenv=PATH="+path)
5855
}

0 commit comments

Comments
 (0)