MCPcopy
hub / github.com/containerd/containerd / execToExistingContainer

Function execToExistingContainer

integration/release_upgrade_linux_test.go:338–395  ·  view source on GitHub ↗
(t *testing.T, _ int,
	rSvc *remote.RuntimeService, iSvc *remote.ImageService)

Source from the content-addressed store, hash-verified

336}
337
338func execToExistingContainer(t *testing.T, _ int,
339 rSvc *remote.RuntimeService, iSvc *remote.ImageService) ([]upgradeVerifyCaseFunc, beforeUpgradeHookFunc) {
340
341 var busyboxImage = images.Get(images.BusyBox)
342
343 pullImagesByCRI(t, iSvc, busyboxImage)
344
345 podLogDir := t.TempDir()
346 podCtx := newPodTCtx(t, rSvc, "running", "sandbox", WithPodLogDirectory(podLogDir))
347
348 cntrLogName := "running#0.log"
349 cnID := podCtx.createContainer("running", busyboxImage,
350 criruntime.ContainerState_CONTAINER_RUNNING,
351 WithCommand("sh", "-c", "while true; do date; sleep 1; done"),
352 WithLogPath(cntrLogName),
353 )
354
355 // NOTE: Wait for containerd to flush data into log
356 time.Sleep(2 * time.Second)
357
358 verifyFunc := func(t *testing.T, rSvc *remote.RuntimeService, _ *remote.ImageService) {
359 pods, err := rSvc.ListPodSandbox(nil)
360 require.NoError(t, err)
361 require.Len(t, pods, 1)
362
363 cntrs, err := rSvc.ListContainers(&criruntime.ContainerFilter{
364 PodSandboxId: pods[0].Id,
365 })
366 require.NoError(t, err)
367 require.Equal(t, 1, len(cntrs))
368 assert.Equal(t, criruntime.ContainerState_CONTAINER_RUNNING, cntrs[0].State)
369 assert.Equal(t, cnID, cntrs[0].Id)
370
371 logPath := filepath.Join(podLogDir, cntrLogName)
372
373 // NOTE: containerd should recover container's IO as well
374 t.Logf("Check container's log %s", logPath)
375
376 logSizeChange := false
377 curSize := getFileSize(t, logPath)
378 for range 30 {
379 time.Sleep(1 * time.Second)
380
381 if curSize < getFileSize(t, logPath) {
382 logSizeChange = true
383 break
384 }
385 }
386 require.True(t, logSizeChange)
387
388 t.Log("Run ExecSync")
389 stdout, stderr, err := rSvc.ExecSync(cntrs[0].Id, []string{"echo", "-n", "true"}, 0)
390 require.NoError(t, err)
391 require.Len(t, stderr, 0)
392 require.Equal(t, "true", string(stdout))
393 }
394 return []upgradeVerifyCaseFunc{verifyFunc}, nil
395}

Callers

nothing calls this directly

Calls 13

GetFunction · 0.92
pullImagesByCRIFunction · 0.85
newPodTCtxFunction · 0.85
WithPodLogDirectoryFunction · 0.85
WithCommandFunction · 0.85
WithLogPathFunction · 0.85
getFileSizeFunction · 0.85
LogMethod · 0.80
ListContainersMethod · 0.65
createContainerMethod · 0.45
ListPodSandboxMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…