@@ -5,23 +5,62 @@ import (
55 "sigs.k8s.io/kustomize/kyaml/yaml"
66)
77
8- // Result reports the outcome of an update. It has a
9- // file->objects->images structure, i.e., from the top level down to the
10- // most detail. Different projections (e.g., all the images) are
11- // available via the methods.
8+ // ImageRef represents the image reference used to replace a field
9+ // value in an update.
10+ type ImageRef interface {
11+ // String returns a string representation of the image ref as it
12+ // is used in the update; e.g., "helloworld:v1.0.1"
13+ String () string
14+ // Identifier returns the tag or digest; e.g., "v1.0.1"
15+ Identifier () string
16+ // Repository returns the repository component of the ImageRef,
17+ // with an implied defaults, e.g., "library/helloworld"
18+ Repository () string
19+ // Registry returns the registry component of the ImageRef, e.g.,
20+ // "index.docker.io"
21+ Registry () string
22+ // Name gives the fully-qualified reference name, e.g.,
23+ // "index.docker.io/library/helloworld:v1.0.1"
24+ Name () string
25+ }
26+
27+ type imageRef struct {
28+ name.Reference
29+ }
30+
31+ // Repository gives the repository component of the image ref.
32+ func (i imageRef ) Repository () string {
33+ return i .Context ().RepositoryStr ()
34+ }
35+
36+ // Registry gives the registry component of the image ref.
37+ func (i imageRef ) Registry () string {
38+ return i .Context ().Registry .String ()
39+ }
40+
41+ // ObjectIdentifier holds the identifying data for a particular
42+ // object. This won't always have a name (e.g., a kustomization.yaml).
43+ type ObjectIdentifier struct {
44+ yaml.ResourceIdentifier
45+ }
46+
47+ // Result reports the outcome of an automated update. It has a nested
48+ // structure file->objects->images. Different projections (e.g., all
49+ // the images, regardless of object) are available via methods.
1250type Result struct {
1351 Files map [string ]FileResult
1452}
1553
54+ // FileResult gives the updates in a particular file.
1655type FileResult struct {
17- Objects map [yaml. ResourceIdentifier ][]name. Reference
56+ Objects map [ObjectIdentifier ][]ImageRef
1857}
1958
2059// Images returns all the images that were involved in at least one
2160// update.
22- func (r Result ) Images () []name. Reference {
23- seen := make (map [name. Reference ]struct {})
24- var result []name. Reference
61+ func (r Result ) Images () []ImageRef {
62+ seen := make (map [ImageRef ]struct {})
63+ var result []ImageRef
2564 for _ , file := range r .Files {
2665 for _ , images := range file .Objects {
2766 for _ , ref := range images {
@@ -37,8 +76,8 @@ func (r Result) Images() []name.Reference {
3776
3877// Objects returns a map of all the objects against the images updated
3978// within, regardless of which file they appear in.
40- func (r Result ) Objects () map [yaml. ResourceIdentifier ][]name. Reference {
41- result := make (map [yaml. ResourceIdentifier ][]name. Reference )
79+ func (r Result ) Objects () map [ObjectIdentifier ][]ImageRef {
80+ result := make (map [ObjectIdentifier ][]ImageRef )
4281 for _ , file := range r .Files {
4382 for res , refs := range file .Objects {
4483 result [res ] = append (result [res ], refs ... )
0 commit comments