TestContainerLogPath tests the container log creation logic.
(t *testing.T)
| 300 | |
| 301 | // TestContainerLogPath tests the container log creation logic. |
| 302 | func TestContainerLogPath(t *testing.T) { |
| 303 | ds, fDocker, _ := newTestDockerService() |
| 304 | podLogPath := "/pod/1" |
| 305 | containerLogPath := "0" |
| 306 | kubeletContainerLogPath := filepath.Join(podLogPath, containerLogPath) |
| 307 | sConfig := makeSandboxConfig("foo", "bar", "1", 0) |
| 308 | sConfig.LogDirectory = podLogPath |
| 309 | config := makeContainerConfig(sConfig, "pause", "iamimage", 0, nil, nil) |
| 310 | config.LogPath = containerLogPath |
| 311 | |
| 312 | req := &runtimeapi.CreateContainerRequest{ |
| 313 | PodSandboxId: sandboxID, |
| 314 | Config: config, |
| 315 | SandboxConfig: sConfig, |
| 316 | } |
| 317 | createResp, err := ds.CreateContainer(getTestCTX(), req) |
| 318 | require.NoError(t, err) |
| 319 | id := createResp.ContainerId |
| 320 | |
| 321 | // Check internal container log label |
| 322 | c, err := fDocker.InspectContainer(id) |
| 323 | assert.NoError(t, err) |
| 324 | assert.Equal(t, c.Config.Labels[containerLogPathLabelKey], kubeletContainerLogPath) |
| 325 | |
| 326 | // Set docker container log path |
| 327 | dockerContainerLogPath := "/docker/container/log" |
| 328 | c.LogPath = dockerContainerLogPath |
| 329 | |
| 330 | // Verify container log symlink creation |
| 331 | fakeOS := ds.os.(*containertest.FakeOS) |
| 332 | fakeOS.SymlinkFn = func(oldname, newname string) error { |
| 333 | assert.Equal(t, dockerContainerLogPath, oldname) |
| 334 | assert.Equal(t, kubeletContainerLogPath, newname) |
| 335 | return nil |
| 336 | } |
| 337 | _, err = ds.StartContainer(getTestCTX(), &runtimeapi.StartContainerRequest{ContainerId: id}) |
| 338 | require.NoError(t, err) |
| 339 | |
| 340 | _, err = ds.StopContainer( |
| 341 | getTestCTX(), |
| 342 | &runtimeapi.StopContainerRequest{ContainerId: id, Timeout: int64(0)}, |
| 343 | ) |
| 344 | require.NoError(t, err) |
| 345 | |
| 346 | // Verify container log symlink deletion |
| 347 | // symlink is also tentatively deleted at startup |
| 348 | _, err = ds.RemoveContainer(getTestCTX(), &runtimeapi.RemoveContainerRequest{ContainerId: id}) |
| 349 | require.NoError(t, err) |
| 350 | assert.Equal(t, []string{kubeletContainerLogPath, kubeletContainerLogPath}, fakeOS.Removes) |
| 351 | } |
| 352 | |
| 353 | // TestContainerCreationConflict tests the logic to work around docker container |
| 354 | // creation naming conflict bug. |
nothing calls this directly
no test coverage detected
searching dependent graphs…