This repository has been archived by the owner on Jul 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.go
49 lines (38 loc) · 1.87 KB
/
helpers.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
package graph
import (
"sort"
kapi "k8s.io/kubernetes/pkg/api"
osgraph "github.com/openshift/origin/pkg/api/graph"
kubegraph "github.com/openshift/origin/pkg/api/kubegraph/nodes"
deployapi "github.com/openshift/origin/pkg/apps/apis/apps"
deploygraph "github.com/openshift/origin/pkg/apps/graph/nodes"
deployutil "github.com/openshift/origin/pkg/apps/util"
)
// RelevantDeployments returns the active deployment and a list of inactive deployments (in order from newest to oldest)
func RelevantDeployments(g osgraph.Graph, dcNode *deploygraph.DeploymentConfigNode) (*kubegraph.ReplicationControllerNode, []*kubegraph.ReplicationControllerNode) {
allDeployments := []*kubegraph.ReplicationControllerNode{}
uncastDeployments := g.SuccessorNodesByEdgeKind(dcNode, DeploymentEdgeKind)
if len(uncastDeployments) == 0 {
return nil, []*kubegraph.ReplicationControllerNode{}
}
for i := range uncastDeployments {
allDeployments = append(allDeployments, uncastDeployments[i].(*kubegraph.ReplicationControllerNode))
}
sort.Sort(RecentDeploymentReferences(allDeployments))
if dcNode.DeploymentConfig.Status.LatestVersion == deployutil.DeploymentVersionFor(allDeployments[0].ReplicationController) {
return allDeployments[0], allDeployments[1:]
}
return nil, allDeployments
}
func BelongsToDeploymentConfig(config *deployapi.DeploymentConfig, b *kapi.ReplicationController) bool {
if b.Annotations != nil {
return config.Name == deployutil.DeploymentConfigNameFor(b)
}
return false
}
type RecentDeploymentReferences []*kubegraph.ReplicationControllerNode
func (m RecentDeploymentReferences) Len() int { return len(m) }
func (m RecentDeploymentReferences) Swap(i, j int) { m[i], m[j] = m[j], m[i] }
func (m RecentDeploymentReferences) Less(i, j int) bool {
return deployutil.DeploymentVersionFor(m[i].ReplicationController) > deployutil.DeploymentVersionFor(m[j].ReplicationController)
}