Skip to content

Commit

Permalink
Image size needs to add a size of manifest config file
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Minář <[email protected]>
  • Loading branch information
Michal Minář committed Sep 2, 2016
1 parent ba54dcf commit f8e5a5a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
10 changes: 7 additions & 3 deletions pkg/cmd/admin/top/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,18 @@ func (o TopImagesOptions) imagesTop() []Info {

func getStorage(image *imageapi.Image) int64 {
storage := int64(0)
layerSet := sets.NewString()
blobSet := sets.NewString()
for _, layer := range image.DockerImageLayers {
if layerSet.Has(layer.Name) {
if blobSet.Has(layer.Name) {
continue
}
layerSet.Insert(layer.Name)
blobSet.Insert(layer.Name)
storage += layer.LayerSize
}
if len(image.DockerImageConfig) > 0 && !blobSet.Has(image.DockerImageMetadata.ID) {
blobSet.Insert(image.DockerImageMetadata.ID)
storage += int64(len(image.DockerImageConfig))
}
return storage
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/cmd/admin/top/imagestreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func getImageStreamSize(g graph.Graph, node *imagegraph.ImageStreamNode) (int64,
storage := int64(0)
images := len(imageEdges)
layers := 0
layerSet := sets.NewString()
blobSet := sets.NewString()
for _, e := range imageEdges {
imageNode, ok := e.To().(*imagegraph.ImageNode)
if !ok {
Expand All @@ -154,12 +154,16 @@ func getImageStreamSize(g graph.Graph, node *imagegraph.ImageStreamNode) (int64,
layers += len(image.DockerImageLayers)
// we're counting only unique layers per the entire stream
for _, layer := range image.DockerImageLayers {
if layerSet.Has(layer.Name) {
if blobSet.Has(layer.Name) {
continue
}
layerSet.Insert(layer.Name)
blobSet.Insert(layer.Name)
storage += layer.LayerSize
}
if len(image.DockerImageConfig) > 0 && !blobSet.Has(image.DockerImageMetadata.ID) {
blobSet.Insert(image.DockerImageMetadata.ID)
storage += int64(len(image.DockerImageConfig))
}
}

return storage, images, layers
Expand Down
10 changes: 7 additions & 3 deletions pkg/dockerregistry/server/repositorymiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ func (r *repository) signedManifestFillImageMetadata(manifest *schema1.SignedMan

refs := manifest.References()

layerSet := sets.NewString()
blobSet := sets.NewString()
image.DockerImageMetadata.Size = int64(0)

blobs := r.Blobs(r.ctx)
Expand All @@ -473,11 +473,15 @@ func (r *repository) signedManifestFillImageMetadata(manifest *schema1.SignedMan
}
layer.LayerSize = desc.Size
// count empty layer just once (empty layer may actually have non-zero size)
if !layerSet.Has(layer.Name) {
if !blobSet.Has(layer.Name) {
image.DockerImageMetadata.Size += desc.Size
layerSet.Insert(layer.Name)
blobSet.Insert(layer.Name)
}
}
if len(image.DockerImageConfig) > 0 && !blobSet.Has(image.DockerImageMetadata.ID) {
blobSet.Insert(image.DockerImageMetadata.ID)
image.DockerImageMetadata.Size += int64(len(image.DockerImageConfig))
}

return nil
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/image/importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,15 @@ func formatRepositoryError(repository *importRepository, refName string, refID s
func (isi *ImageStreamImporter) calculateImageSize(ctx gocontext.Context, repo distribution.Repository, image *api.Image) error {
bs := repo.Blobs(ctx)

layerSet := sets.NewString()
blobSet := sets.NewString()
size := int64(0)
for i := range image.DockerImageLayers {
layer := &image.DockerImageLayers[i]

if layerSet.Has(layer.Name) {
if blobSet.Has(layer.Name) {
continue
}
layerSet.Insert(layer.Name)
blobSet.Insert(layer.Name)

if layerSize, ok := isi.digestToLayerSizeCache[layer.Name]; ok {
size += layerSize
Expand All @@ -335,6 +335,11 @@ func (isi *ImageStreamImporter) calculateImageSize(ctx gocontext.Context, repo d
size += desc.Size
}

if len(image.DockerImageConfig) > 0 && !blobSet.Has(image.DockerImageMetadata.ID) {
blobSet.Insert(image.DockerImageMetadata.ID)
size += int64(len(image.DockerImageConfig))
}

image.DockerImageMetadata.Size = size
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ os::cmd::expect_success "oc tag cache/hello-world@${imagedigest} cross:namespace
os::cmd::expect_success "docker pull ${DOCKER_REGISTRY}/custom/cross:namespace-pull-id"
echo "[INFO] Cross namespace pull successful"

# check to make sure an image-pusher can push an image and pull any image
# check to make sure an image-pusher can push an image
os::cmd::expect_success "oc project ${CLUSTER_ADMIN_CONTEXT}"
os::cmd::expect_success 'oc policy add-role-to-user system:image-pusher pusher'
os::cmd::expect_success 'oc policy add-role-to-user -n test admin pusher'
Expand Down

0 comments on commit f8e5a5a

Please sign in to comment.