Merge pull request #25361 from yifan-gu/imagestates

rkt: Implement ImageStats() for rkt.
This commit is contained in:
Jeff Lowdermilk 2016-05-13 15:05:48 -07:00
commit 095e262461
3 changed files with 29 additions and 5 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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})
}