-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
nodes.go
172 lines (151 loc) · 6.02 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
package nodes
import (
"github.com/gonum/graph"
kapi "k8s.io/kubernetes/pkg/api"
osgraph "github.com/openshift/origin/pkg/api/graph"
imageapi "github.com/openshift/origin/pkg/image/api"
)
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) graph.Node {
return g.Find(ImageNodeName(&imageapi.Image{ObjectMeta: kapi.ObjectMeta{Name: imageName}}))
}
// 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: kapi.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: kapi.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: kapi.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: kapi.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)
}
// EnsureImageLayerNode adds a graph node for the layer if it does not already exist.
func EnsureImageLayerNode(g osgraph.MutableUniqueGraph, layer string) graph.Node {
return osgraph.EnsureUnique(g,
ImageLayerNodeName(layer),
func(node osgraph.Node) graph.Node {
return &ImageLayerNode{node, layer}
},
)
}