Skip to content

Commit

Permalink
Merge pull request #91103 from vboulineau/automated-cherry-pick-of-#9…
Browse files Browse the repository at this point in the history
…0554-upstream-release-1.17

Automated cherry pick of #90554: kubelet: fix `/stats/summary` endpoint on Windows when
  • Loading branch information
k8s-ci-robot committed Jul 7, 2020
2 parents fdec14c + b1fe9ab commit 2d72335
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/kubelet/dockershim/docker_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,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
Expand Down
8 changes: 7 additions & 1 deletion pkg/kubelet/dockershim/docker_stats_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 11 additions & 1 deletion test/e2e/windows/kubelet_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,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,
},
}
Expand Down

0 comments on commit 2d72335

Please sign in to comment.