Commit 5351602f authored by Yifan Gu's avatar Yifan Gu

rkt: Implement ImageStats() for rkt.

parent e973b5d2
......@@ -227,3 +227,17 @@ func (r *Runtime) writeDockerAuthConfig(image string, credsSlice []credentialpro
}
return nil
}
// ImageStats returns the image stat (total storage bytes).
func (r *Runtime) ImageStats() (*kubecontainer.ImageStats, error) {
var imageStat kubecontainer.ImageStats
listResp, err := r.apisvc.ListImages(context.Background(), &rktapi.ListImagesRequest{})
if err != nil {
return nil, fmt.Errorf("couldn't list images: %v", err)
}
for _, image := range listResp.Images {
imageStat.TotalStorageBytes = imageStat.TotalStorageBytes + uint64(image.Size)
}
return &imageStat, nil
}
......@@ -1771,8 +1771,3 @@ func (r *Runtime) GetPodStatus(uid types.UID, name, namespace string) (*kubecont
return podStatus, nil
}
// FIXME: I need to be implemented.
func (r *Runtime) ImageStats() (*kubecontainer.ImageStats, error) {
return &kubecontainer.ImageStats{}, nil
}
......@@ -1382,3 +1382,18 @@ func TestLifeCycleHooks(t *testing.T) {
runner.Reset()
}
}
func TestImageStats(t *testing.T) {
fr := newFakeRktInterface()
rkt := &Runtime{apisvc: fr}
fr.images = []*rktapi.Image{
{Size: 100},
{Size: 200},
{Size: 300},
}
result, err := rkt.ImageStats()
assert.NoError(t, err)
assert.Equal(t, result, &kubecontainer.ImageStats{TotalStorageBytes: 600})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment