Skip to content

Commit

Permalink
image-pruner: prune images in their own jobs
Browse files Browse the repository at this point in the history
Instead of pruning in phases:

    all streams -> all layers -> all blobs -> manifests -> images

Prune individual images in parallel jobs:

    all streams -> parallel [
       image1's layers -> image1's blobs -> ... -> image1,
       image2's layers -> image2's blobs -> ... -> image2,
       ...
    ]

A failure in streams prune phase is not fatal anymore.

Signed-off-by: Michal Minář <[email protected]>
  • Loading branch information
Michal Minář committed Apr 23, 2018
1 parent bb34ae4 commit 99829b9
Show file tree
Hide file tree
Showing 8 changed files with 1,245 additions and 229 deletions.
37 changes: 37 additions & 0 deletions pkg/oc/admin/prune/imageprune/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"sort"
"strings"

kmeta "k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api/legacyscheme"
kapiref "k8s.io/kubernetes/pkg/api/ref"
kapi "k8s.io/kubernetes/pkg/apis/core"

"github.com/docker/distribution/registry/api/errcode"
Expand Down Expand Up @@ -265,3 +269,36 @@ func (e *ErrBadReference) String() string {
}
return fmt.Sprintf("%s[%s]: invalid %s reference %q: %s", e.kind, name, targetKind, e.reference, e.reason)
}

func getName(obj runtime.Object) string {
accessor, err := kmeta.Accessor(obj)
if err != nil {
glog.V(4).Infof("Error getting accessor for %#v", obj)
return "<unknown>"
}
ns := accessor.GetNamespace()
if len(ns) == 0 {
return accessor.GetName()
}
return fmt.Sprintf("%s/%s", ns, accessor.GetName())
}

func getKindName(obj *kapi.ObjectReference) string {
if obj == nil {
return "unknown object"
}
name := obj.Name
if len(obj.Namespace) > 0 {
name = obj.Namespace + "/" + name
}
return fmt.Sprintf("%s[%s]", obj.Kind, name)
}

func getRef(obj runtime.Object) *kapi.ObjectReference {
ref, err := kapiref.GetReference(legacyscheme.Scheme, obj)
if err != nil {
glog.Errorf("failed to get reference to object %T: %v", obj, err)
return nil
}
return ref
}
Loading

0 comments on commit 99829b9

Please sign in to comment.