Waits up to 10s for a containerd container with the specified ID to appear in cAdvisor.
(containerID string, fm framework.Framework)
| 31 | |
| 32 | // Waits up to 10s for a containerd container with the specified ID to appear in cAdvisor. |
| 33 | func 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 | |
| 60 | func containsString(s, substr string) bool { |
| 61 | for i := 0; i <= len(s)-len(substr); i++ { |
no test coverage detected
searching dependent graphs…