Merge pull request #90554 from vboulineau/vboulineau/fix_win_stats_init_containers

kubelet: fix `/stats/summary` endpoint on Windows when init-containers are present on the node
This commit is contained in:
Kubernetes Prow Robot 2020-05-13 15:58:51 -07:00 committed by GitHub
commit 4339ac30a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -55,8 +55,9 @@ func (ds *dockerService) ListContainerStats(ctx context.Context, r *runtimeapi.L
if err != nil {
return nil, err
}
stats = append(stats, containerStats)
if containerStats != nil {
stats = append(stats, containerStats)
}
}
return &runtimeapi.ListContainerStatsResponse{Stats: stats}, nil

View File

@ -35,7 +35,13 @@ func (ds *dockerService) getContainerStats(containerID string) (*runtimeapi.Cont
hcsshim_container, err := hcsshim.OpenContainer(containerID)
if err != nil {
return nil, err
// As we moved from using Docker stats to hcsshim directly, we may query HCS with already exited container IDs.
// That will typically happen with init-containers in Exited state. Docker still knows about them but the HCS does not.
// As we don't want to block stats retrieval for other containers, we only log errors.
if !hcsshim.IsNotExist(err) && !hcsshim.IsAlreadyStopped(err) {
klog.Errorf("Error opening container (stats will be missing) '%s': %v", containerID, err)
}
return nil, nil
}
defer func() {
closeErr := hcsshim_container.Close()

View File

@ -146,7 +146,17 @@ func newKubeletStatsTestPods(numPods int, image imageutils.Config, nodeName stri
},
},
},
InitContainers: []v1.Container{
{
Image: image.GetE2EImage(),
Name: podName,
Command: []string{
"powershell.exe",
"-Command",
"sleep -Seconds 1",
},
},
},
NodeName: nodeName,
},
}