MCPcopy
hub / github.com/google/cadvisor / waitForContainerdContainer

Function waitForContainerdContainer

integration/tests/api/containerd_test.go:33–58  ·  view source on GitHub ↗

Waits up to 10s for a containerd container with the specified ID to appear in cAdvisor.

(containerID string, fm framework.Framework)

Source from the content-addressed store, hash-verified

31
32// Waits up to 10s for a containerd container with the specified ID to appear in cAdvisor.
33func waitForContainerdContainer(containerID string, fm framework.Framework) {
34 err := framework.RetryForDuration(func() error {
35 // Query all containers via SubcontainersInfo - containerd containers are in "containerd" namespace
36 allInfo, err := fm.Cadvisor().Client().SubcontainersInfo("/", &info.ContainerInfoRequest{
37 NumStats: 1,
38 })
39 if err != nil {
40 return err
41 }
42
43 // Look for container by ID
44 for _, container := range allInfo {
45 for _, alias := range container.Aliases {
46 if alias == containerID {
47 return nil
48 }
49 }
50 // Also check if the container name contains the ID
51 if len(container.Name) > 0 && containsString(container.Name, containerID) {
52 return nil
53 }
54 }
55 return fmt.Errorf("container %q not found in cAdvisor", containerID)
56 }, 10*time.Second)
57 require.NoError(fm.T(), err, "Timed out waiting for containerd container %q to be available in cAdvisor", containerID)
58}
59
60func containsString(s, substr string) bool {
61 for i := 0; i <= len(s)-len(substr); i++ {

Calls 7

RetryForDurationFunction · 0.92
containsStringFunction · 0.85
ErrorfMethod · 0.80
SubcontainersInfoMethod · 0.65
ClientMethod · 0.65
CadvisorMethod · 0.65
TMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…