Skip to content

Commit

Permalink
manager: Create function for getting containers info from data.
Browse files Browse the repository at this point in the history
Signed-off-by: Paweł Szulik <pawel.szulik@intel.com>
  • Loading branch information
Paweł Szulik committed Dec 6, 2021
1 parent 0d87f7b commit 5cfac3f
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,7 @@ func (m *manager) getAllNamespacedContainers(ns string) map[string]*containerDat

func (m *manager) AllDockerContainers(query *info.ContainerInfoRequest) (map[string]info.ContainerInfo, error) {
containers := m.getAllNamespacedContainers(DockerNamespace)

output := make(map[string]info.ContainerInfo, len(containers))
for name, cont := range containers {
inf, err := m.containerDataToContainerInfo(cont, query)
if err != nil {
// Ignore the error because of race condition and return best-effort result.
if err == memory.ErrDataNotFound {
klog.Warningf("Error getting data for container %s because of race condition", name)
continue
}
return nil, err
}
output[name] = *inf
}
return output, nil
return m.getContainersInfo(containers, query)
}

func (m *manager) getDockerContainer(containerName string) (*containerData, error) {
Expand Down Expand Up @@ -1374,6 +1360,23 @@ func (m *manager) getFsInfoByDeviceName(deviceName string) (v2.FsInfo, error) {
return v2.FsInfo{}, fmt.Errorf("cannot find filesystem info for device %q", deviceName)
}

func (m *manager) getContainersInfo(containers map[string]*containerData, query *info.ContainerInfoRequest) (map[string]info.ContainerInfo, error) {
output := make(map[string]info.ContainerInfo, len(containers))
for name, cont := range containers {
inf, err := m.containerDataToContainerInfo(cont, query)
if err != nil {
// Ignore the error because of race condition and return best-effort result.
if err == memory.ErrDataNotFound {
klog.Warningf("Error getting data for container %s because of race condition", name)
continue
}
return nil, err
}
output[name] = *inf
}
return output, nil
}

func getVersionInfo() (*info.VersionInfo, error) {

kernelVersion := machine.KernelVersion()
Expand Down

0 comments on commit 5cfac3f

Please sign in to comment.