Skip to content

Commit cc695ab

Browse files
author
Michal Minář
committed
image-pruning: derefence imagestreamtags
Create strong references to images for each pod/bc/dc/etc that uses <host>/<repo>:tag reference. Resolves [bz#1498604](https://bugzilla.redhat.com/show_bug.cgi?id=1498604) Signed-off-by: Michal Minář <[email protected]>
1 parent d61dcb0 commit cc695ab

File tree

8 files changed

+1803
-1137
lines changed

8 files changed

+1803
-1137
lines changed

pkg/image/graph/nodes/nodes.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ func EnsureAllImageStreamTagNodes(g osgraph.MutableUniqueGraph, is *imageapi.Ima
3636
return ret
3737
}
3838

39-
func FindImage(g osgraph.MutableUniqueGraph, imageName string) graph.Node {
40-
return g.Find(ImageNodeName(&imageapi.Image{ObjectMeta: metav1.ObjectMeta{Name: imageName}}))
39+
func FindImage(g osgraph.MutableUniqueGraph, imageName string) *ImageNode {
40+
n := g.Find(ImageNodeName(&imageapi.Image{ObjectMeta: metav1.ObjectMeta{Name: imageName}}))
41+
if imageNode, ok := n.(*ImageNode); ok {
42+
return imageNode
43+
}
44+
return nil
4145
}
4246

4347
// EnsureDockerRepositoryNode adds the named Docker repository tag reference to the graph if it does

pkg/image/prune/helper.go

+59
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"sort"
88
"strings"
99

10+
kapi "k8s.io/kubernetes/pkg/api"
11+
1012
"github.com/docker/distribution/registry/api/errcode"
1113
"github.com/golang/glog"
1214

@@ -206,3 +208,60 @@ func TryProtocolsWithRegistryURL(registry string, allowInsecure bool, action fun
206208
type retryPath struct{ err error }
207209

208210
func (rp *retryPath) Error() string { return rp.err.Error() }
211+
212+
// ErrBadReference denotes an invalid reference to image, imagestreamtag or imagestreamimage stored in a
213+
// particular object. The object is identified by kind, namespace and name.
214+
type ErrBadReference struct {
215+
kind string
216+
namespace string
217+
name string
218+
targetKind string
219+
reference string
220+
reason string
221+
}
222+
223+
func newErrBadReferenceToImage(reference string, obj *kapi.ObjectReference, reason string) error {
224+
kind := "<UnknownType>"
225+
namespace := ""
226+
name := "<unknown-name>"
227+
if obj != nil {
228+
kind = obj.Kind
229+
namespace = obj.Namespace
230+
name = obj.Name
231+
}
232+
233+
return &ErrBadReference{
234+
kind: kind,
235+
namespace: namespace,
236+
name: name,
237+
reference: reference,
238+
reason: reason,
239+
}
240+
}
241+
242+
func newErrBadReferenceTo(targetKind, reference string, obj *kapi.ObjectReference, reason string) error {
243+
return &ErrBadReference{
244+
kind: obj.Kind,
245+
namespace: obj.Namespace,
246+
name: obj.Name,
247+
targetKind: targetKind,
248+
reference: reference,
249+
reason: reason,
250+
}
251+
}
252+
253+
func (e *ErrBadReference) Error() string {
254+
return e.String()
255+
}
256+
257+
func (e *ErrBadReference) String() string {
258+
name := e.name
259+
if len(e.namespace) > 0 {
260+
name = e.namespace + "/" + name
261+
}
262+
targetKind := "docker image"
263+
if len(e.targetKind) > 0 {
264+
targetKind = e.targetKind
265+
}
266+
return fmt.Sprintf("%s[%s]: invalid %s reference %q: %s", e.kind, name, targetKind, e.reference, e.reason)
267+
}

0 commit comments

Comments
 (0)