forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dc_pipeline.go
84 lines (64 loc) · 3.22 KB
/
dc_pipeline.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
package graphview
import (
"sort"
appsedges "github.com/openshift/origin/pkg/oc/lib/graph/appsgraph"
appsgraph "github.com/openshift/origin/pkg/oc/lib/graph/appsgraph/nodes"
osgraph "github.com/openshift/origin/pkg/oc/lib/graph/genericgraph"
kubegraph "github.com/openshift/origin/pkg/oc/lib/graph/kubegraph/nodes"
)
type DeploymentConfigPipeline struct {
DeploymentConfig *appsgraph.DeploymentConfigNode
ActiveDeployment *kubegraph.ReplicationControllerNode
InactiveDeployments []*kubegraph.ReplicationControllerNode
Images []ImagePipeline
}
// AllDeploymentConfigPipelines returns all the DCPipelines that aren't in the excludes set and the set of covered NodeIDs
func AllDeploymentConfigPipelines(g osgraph.Graph, excludeNodeIDs IntSet) ([]DeploymentConfigPipeline, IntSet) {
covered := IntSet{}
dcPipelines := []DeploymentConfigPipeline{}
for _, uncastNode := range g.NodesByKind(appsgraph.DeploymentConfigNodeKind) {
if excludeNodeIDs.Has(uncastNode.ID()) {
continue
}
pipeline, covers := NewDeploymentConfigPipeline(g, uncastNode.(*appsgraph.DeploymentConfigNode))
covered.Insert(covers.List()...)
dcPipelines = append(dcPipelines, pipeline)
}
sort.Sort(SortedDeploymentConfigPipeline(dcPipelines))
return dcPipelines, covered
}
// NewDeploymentConfigPipeline returns the DeploymentConfigPipeline and a set of all the NodeIDs covered by the DeploymentConfigPipeline
func NewDeploymentConfigPipeline(g osgraph.Graph, dcNode *appsgraph.DeploymentConfigNode) (DeploymentConfigPipeline, IntSet) {
covered := IntSet{}
covered.Insert(dcNode.ID())
dcPipeline := DeploymentConfigPipeline{}
dcPipeline.DeploymentConfig = dcNode
// for everything that can trigger a deployment, create an image pipeline and add it to the list
for _, istNode := range g.PredecessorNodesByEdgeKind(dcNode, appsedges.TriggersDeploymentEdgeKind) {
imagePipeline, covers := NewImagePipelineFromImageTagLocation(g, istNode, istNode.(ImageTagLocation))
covered.Insert(covers.List()...)
dcPipeline.Images = append(dcPipeline.Images, imagePipeline)
}
// for image that we use, create an image pipeline and add it to the list
for _, tagNode := range g.PredecessorNodesByEdgeKind(dcNode, appsedges.UsedInDeploymentEdgeKind) {
imagePipeline, covers := NewImagePipelineFromImageTagLocation(g, tagNode, tagNode.(ImageTagLocation))
covered.Insert(covers.List()...)
dcPipeline.Images = append(dcPipeline.Images, imagePipeline)
}
dcPipeline.ActiveDeployment, dcPipeline.InactiveDeployments = appsedges.RelevantDeployments(g, dcNode)
for _, rc := range dcPipeline.InactiveDeployments {
_, covers := NewReplicationController(g, rc)
covered.Insert(covers.List()...)
}
if dcPipeline.ActiveDeployment != nil {
_, covers := NewReplicationController(g, dcPipeline.ActiveDeployment)
covered.Insert(covers.List()...)
}
return dcPipeline, covered
}
type SortedDeploymentConfigPipeline []DeploymentConfigPipeline
func (m SortedDeploymentConfigPipeline) Len() int { return len(m) }
func (m SortedDeploymentConfigPipeline) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
func (m SortedDeploymentConfigPipeline) Less(i, j int) bool {
return CompareObjectMeta(&m[i].DeploymentConfig.DeploymentConfig.ObjectMeta, &m[j].DeploymentConfig.DeploymentConfig.ObjectMeta)
}