forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodes.go
205 lines (179 loc) · 7.21 KB
/
nodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package nodes
import (
"github.com/gonum/graph"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
imageapi "github.com/openshift/origin/pkg/image/apis/image"
osgraph "github.com/openshift/origin/pkg/oc/lib/graph/genericgraph"
)
func EnsureImageNode(g osgraph.MutableUniqueGraph, img *imageapi.Image) graph.Node {
return osgraph.EnsureUnique(g,
ImageNodeName(img),
func(node osgraph.Node) graph.Node {
return &ImageNode{node, img}
},
)
}
// EnsureAllImageStreamTagNodes creates all the ImageStreamTagNodes that are guaranteed to be present based on the ImageStream.
// This is different than inferring the presence of an object, since the IST is an object derived from a join between the ImageStream
// and the Image it references.
func EnsureAllImageStreamTagNodes(g osgraph.MutableUniqueGraph, is *imageapi.ImageStream) []*ImageStreamTagNode {
ret := []*ImageStreamTagNode{}
for tag := range is.Status.Tags {
ist := &imageapi.ImageStreamTag{}
ist.Namespace = is.Namespace
ist.Name = imageapi.JoinImageStreamTag(is.Name, tag)
istNode := EnsureImageStreamTagNode(g, ist)
ret = append(ret, istNode)
}
return ret
}
func FindImage(g osgraph.MutableUniqueGraph, imageName string) *ImageNode {
n := g.Find(ImageNodeName(&imageapi.Image{ObjectMeta: metav1.ObjectMeta{Name: imageName}}))
if imageNode, ok := n.(*ImageNode); ok {
return imageNode
}
return nil
}
// EnsureDockerRepositoryNode adds the named Docker repository tag reference to the graph if it does
// not already exist. If the reference is invalid, the Name field of the graph will be used directly.
func EnsureDockerRepositoryNode(g osgraph.MutableUniqueGraph, name, tag string) graph.Node {
ref, err := imageapi.ParseDockerImageReference(name)
if err == nil {
if len(tag) != 0 {
ref.Tag = tag
}
ref = ref.DockerClientDefaults()
} else {
ref = imageapi.DockerImageReference{Name: name}
}
return osgraph.EnsureUnique(g,
DockerImageRepositoryNodeName(ref),
func(node osgraph.Node) graph.Node {
return &DockerImageRepositoryNode{node, ref}
},
)
}
// MakeImageStreamTagObjectMeta returns an ImageStreamTag that has enough information to join the graph, but it is not
// based on a full IST object. This can be used to properly initialize the graph without having to retrieve all ISTs
func MakeImageStreamTagObjectMeta(namespace, name, tag string) *imageapi.ImageStreamTag {
return &imageapi.ImageStreamTag{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: imageapi.JoinImageStreamTag(name, tag),
},
}
}
// MakeImageStreamTagObjectMeta2 returns an ImageStreamTag that has enough information to join the graph, but it is not
// based on a full IST object. This can be used to properly initialize the graph without having to retrieve all ISTs
func MakeImageStreamTagObjectMeta2(namespace, name string) *imageapi.ImageStreamTag {
return &imageapi.ImageStreamTag{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
}
}
// EnsureImageStreamTagNode adds a graph node for the specific tag in an Image Stream if it does not already exist.
func EnsureImageStreamTagNode(g osgraph.MutableUniqueGraph, ist *imageapi.ImageStreamTag) *ImageStreamTagNode {
return osgraph.EnsureUnique(g,
ImageStreamTagNodeName(ist),
func(node osgraph.Node) graph.Node {
return &ImageStreamTagNode{node, ist, true}
},
).(*ImageStreamTagNode)
}
// FindOrCreateSyntheticImageStreamTagNode returns the existing ISTNode or creates a synthetic node in its place
func FindOrCreateSyntheticImageStreamTagNode(g osgraph.MutableUniqueGraph, ist *imageapi.ImageStreamTag) *ImageStreamTagNode {
return osgraph.EnsureUnique(g,
ImageStreamTagNodeName(ist),
func(node osgraph.Node) graph.Node {
return &ImageStreamTagNode{node, ist, false}
},
).(*ImageStreamTagNode)
}
// MakeImageStreamImageObjectMeta returns an ImageStreamImage that has enough information to join the graph, but it is not
// based on a full ISI object. This can be used to properly initialize the graph without having to retrieve all ISIs
func MakeImageStreamImageObjectMeta(namespace, name string) *imageapi.ImageStreamImage {
return &imageapi.ImageStreamImage{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
}
}
// EnsureImageStreamImageNode adds a graph node for the specific ImageStreamImage if it
// does not already exist.
func EnsureImageStreamImageNode(g osgraph.MutableUniqueGraph, namespace, name string) graph.Node {
isi := &imageapi.ImageStreamImage{
ObjectMeta: metav1.ObjectMeta{
Namespace: namespace,
Name: name,
},
}
return osgraph.EnsureUnique(g,
ImageStreamImageNodeName(isi),
func(node osgraph.Node) graph.Node {
return &ImageStreamImageNode{node, isi, true}
},
)
}
// FindOrCreateSyntheticImageStreamImageNode returns the existing ISINode or creates a synthetic node in its place
func FindOrCreateSyntheticImageStreamImageNode(g osgraph.MutableUniqueGraph, isi *imageapi.ImageStreamImage) *ImageStreamImageNode {
return osgraph.EnsureUnique(g,
ImageStreamImageNodeName(isi),
func(node osgraph.Node) graph.Node {
return &ImageStreamImageNode{node, isi, false}
},
).(*ImageStreamImageNode)
}
// EnsureImageStreamNode adds a graph node for the Image Stream if it does not already exist.
func EnsureImageStreamNode(g osgraph.MutableUniqueGraph, is *imageapi.ImageStream) graph.Node {
return osgraph.EnsureUnique(g,
ImageStreamNodeName(is),
func(node osgraph.Node) graph.Node {
return &ImageStreamNode{node, is, true}
},
)
}
// FindOrCreateSyntheticImageStreamNode returns the existing ISNode or creates a synthetic node in its place
func FindOrCreateSyntheticImageStreamNode(g osgraph.MutableUniqueGraph, is *imageapi.ImageStream) *ImageStreamNode {
return osgraph.EnsureUnique(g,
ImageStreamNodeName(is),
func(node osgraph.Node) graph.Node {
return &ImageStreamNode{node, is, false}
},
).(*ImageStreamNode)
}
func ensureImageComponentNode(g osgraph.MutableUniqueGraph, name string, t ImageComponentType) graph.Node {
node := osgraph.EnsureUnique(g,
ImageComponentNodeName(name),
func(node osgraph.Node) graph.Node {
return &ImageComponentNode{
Node: node,
Component: name,
Type: t,
}
},
)
// If at least one image referers to the blob as its config, treat it as a config even if it is a layer of
// some other image.
if t == ImageComponentTypeConfig {
cn := node.(*ImageComponentNode)
if cn.Type != ImageComponentTypeConfig {
cn.Type = ImageComponentTypeConfig
}
}
return node
}
// EnsureImageComponentConfigNode adds a graph node for the image config if it does not already exist.
func EnsureImageComponentConfigNode(g osgraph.MutableUniqueGraph, name string) graph.Node {
return ensureImageComponentNode(g, name, ImageComponentTypeConfig)
}
// EnsureImageComponentLayerNode adds a graph node for the image layer if it does not already exist.
func EnsureImageComponentLayerNode(g osgraph.MutableUniqueGraph, name string) graph.Node {
return ensureImageComponentNode(g, name, ImageComponentTypeLayer)
}
// EnsureImageComponentLayerNode adds a graph node for the image layer if it does not already exist.
func EnsureImageComponentManifestNode(g osgraph.MutableUniqueGraph, name string) graph.Node {
return ensureImageComponentNode(g, name, ImageComponentTypeManifest)
}