Check that restart count is captured in labels.
(t *testing.T)
| 434 | |
| 435 | // Check that restart count is captured in labels. |
| 436 | func TestDockerContainerRestartCount(t *testing.T) { |
| 437 | fm := framework.New(t) |
| 438 | defer fm.Cleanup() |
| 439 | |
| 440 | containerName := fmt.Sprintf("test-restart-count-%d", os.Getpid()) |
| 441 | // Run a container that runs briefly then exits with failure, with restart policy |
| 442 | // The sleep gives cAdvisor time to detect the container between restarts |
| 443 | fm.Docker().Run(framework.DockerRunArgs{ |
| 444 | Image: "registry.k8s.io/busybox:1.27", |
| 445 | Args: []string{ |
| 446 | "--name", containerName, |
| 447 | "--restart", "on-failure:5", |
| 448 | }, |
| 449 | }, "sh", "-c", "sleep 3 && exit 1") |
| 450 | |
| 451 | // Wait for container to show up initially |
| 452 | waitForContainer(containerName, fm) |
| 453 | |
| 454 | // Wait for at least one restart to occur |
| 455 | time.Sleep(5 * time.Second) |
| 456 | |
| 457 | request := &info.ContainerInfoRequest{ |
| 458 | NumStats: 1, |
| 459 | } |
| 460 | |
| 461 | // Query the container - it should still be running or restarting |
| 462 | containerInfo, err := fm.Cadvisor().Client().DockerContainer(containerName, request) |
| 463 | require.NoError(t, err, "Container should still be available during restart cycle") |
| 464 | sanityCheck(containerName, containerInfo, t) |
| 465 | |
| 466 | // Check that restart count label is present and greater than 0 |
| 467 | restartCount, ok := containerInfo.Spec.Labels["restartcount"] |
| 468 | require.True(t, ok, "restartcount label should be present") |
| 469 | count, err := strconv.Atoi(restartCount) |
| 470 | require.NoError(t, err) |
| 471 | assert.GreaterOrEqual(t, count, 1, "Restart count should be at least 1") |
| 472 | } |
| 473 | |
| 474 | // Check the DiskIo ContainerStats. |
| 475 | func TestDockerContainerDiskIoStats(t *testing.T) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…