kubelet/stats: update cadvisor stats provider with new log location

in https://github.com/kubernetes/kubernetes/pull/74441,
the namespace and name were added to the pod log location.

However, cAdvisor stats provider wasn't correspondingly updated.

since CRI-O uses cAdvisor stats provider by default, despite being a CRI implementation,
eviction with ephemeral storage and container logs doesn't work as expected, until now!

Signed-off-by: Peter Hunt <pehunt@redhat.com>
This commit is contained in:
Peter Hunt 2022-02-14 17:55:55 -05:00
parent 4e30fe40df
commit ab0f274a6f
2 changed files with 14 additions and 1 deletions

View File

@ -125,7 +125,17 @@ func (p *cadvisorStatsProvider) ListPodStats() ([]statsapi.PodStats, error) {
// the user and has network stats.
podStats.Network = cadvisorInfoToNetworkStats(&cinfo)
} else {
podStats.Containers = append(podStats.Containers, *cadvisorInfoToContainerStats(containerName, &cinfo, &rootFsInfo, &imageFsInfo))
containerStat := cadvisorInfoToContainerStats(containerName, &cinfo, &rootFsInfo, &imageFsInfo)
// NOTE: This doesn't support the old pod log path, `/var/log/pods/UID`. For containers
// using old log path, they will be populated by cadvisorInfoToContainerStats.
podUID := types.UID(podStats.PodRef.UID)
logs, err := p.hostStatsProvider.getPodContainerLogStats(podStats.PodRef.Namespace, podStats.PodRef.Name, podUID, containerName, &rootFsInfo)
if err != nil {
klog.ErrorS(err, "Unable to fetch container log stats", "containerName", containerName)
} else {
containerStat.Logs = logs
}
podStats.Containers = append(podStats.Containers, *containerStat)
}
}

View File

@ -94,6 +94,9 @@ func cadvisorInfoToContainerStats(name string, info *cadvisorapiv2.ContainerInfo
result.CPU = cpu
result.Memory = memory
// NOTE: if they can be found, log stats will be overwritten
// by the caller, as it knows more information about the pod,
// which is needed to determine log size.
if rootFs != nil {
// The container logs live on the node rootfs device
result.Logs = buildLogsStats(cstat, rootFs)