Skip to content

Commit 4267f2a

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 4267f2a

File tree

6 files changed

+740
-270
lines changed

6 files changed

+740
-270
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

+57
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,58 @@ 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+
type errBadReference struct {
213+
kind string
214+
namespace string
215+
name string
216+
targetKind string
217+
reference string
218+
reason string
219+
}
220+
221+
func newErrBadReferenceToImage(reference string, obj *kapi.ObjectReference, reason string) error {
222+
kind := "<UnknownType>"
223+
namespace := ""
224+
name := "<unknown-name>"
225+
if obj != nil {
226+
kind = obj.Kind
227+
namespace = obj.Namespace
228+
name = obj.Name
229+
}
230+
231+
return &errBadReference{
232+
kind: kind,
233+
namespace: namespace,
234+
name: name,
235+
reference: reference,
236+
reason: reason,
237+
}
238+
}
239+
240+
func newErrBadReferenceTo(targetKind, reference string, obj *kapi.ObjectReference, reason string) error {
241+
return &errBadReference{
242+
kind: obj.Kind,
243+
namespace: obj.Namespace,
244+
name: obj.Name,
245+
targetKind: targetKind,
246+
reference: reference,
247+
reason: reason,
248+
}
249+
}
250+
251+
func (e *errBadReference) Error() string {
252+
return e.String()
253+
}
254+
255+
func (e *errBadReference) String() string {
256+
name := e.name
257+
if len(e.namespace) > 0 {
258+
name = e.namespace + "/" + name
259+
}
260+
targetKind := "docker image"
261+
if len(e.targetKind) > 0 {
262+
targetKind = e.targetKind
263+
}
264+
return fmt.Sprintf("%s[%s]: invalid %s reference %q: %s", e.kind, name, targetKind, e.reference, e.reason)
265+
}

0 commit comments

Comments
 (0)