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 May 30, 2018
1 parent 0a478b4 commit 39bffa5
Show file tree
Hide file tree
Showing 11 changed files with 2,016 additions and 396 deletions.
2 changes: 1 addition & 1 deletion pkg/cmd/server/bootstrappolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func GetOpenshiftBootstrapClusterRoles() []rbac.ClusterRole {
rbac.NewRule("get", "list").Groups(appsGroup, extensionsGroup).Resources("replicasets").RuleOrDie(),

rbac.NewRule("delete").Groups(imageGroup, legacyImageGroup).Resources("images").RuleOrDie(),
rbac.NewRule("get", "list").Groups(imageGroup, legacyImageGroup).Resources("images", "imagestreams").RuleOrDie(),
rbac.NewRule("get", "list", "watch").Groups(imageGroup, legacyImageGroup).Resources("images", "imagestreams").RuleOrDie(),
rbac.NewRule("update").Groups(imageGroup, legacyImageGroup).Resources("imagestreams/status").RuleOrDie(),
},
},
Expand Down
40 changes: 38 additions & 2 deletions pkg/oc/admin/prune/imageprune/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import (
"sort"
"strings"

kapi "k8s.io/kubernetes/pkg/apis/core"

"github.com/docker/distribution/registry/api/errcode"
"github.com/golang/glog"

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

imageapi "github.com/openshift/origin/pkg/image/apis/image"
"github.com/openshift/origin/pkg/util/netutils"
Expand Down Expand Up @@ -265,3 +268,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 39bffa5

Please sign in to comment.