forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.go
56 lines (43 loc) · 1.72 KB
/
rc.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
package analysis
import (
"fmt"
"strings"
"github.com/gonum/graph"
osgraph "github.com/openshift/origin/pkg/api/graph"
kubeedges "github.com/openshift/origin/pkg/api/kubegraph"
kubegraph "github.com/openshift/origin/pkg/api/kubegraph/nodes"
)
const (
DuelingReplicationControllerWarning = "DuelingReplicationControllers"
)
func FindDuelingReplicationControllers(g osgraph.Graph, f osgraph.Namer) []osgraph.Marker {
markers := []osgraph.Marker{}
for _, uncastRCNode := range g.NodesByKind(kubegraph.ReplicationControllerNodeKind) {
rcNode := uncastRCNode.(*kubegraph.ReplicationControllerNode)
for _, uncastPodNode := range g.PredecessorNodesByEdgeKind(rcNode, kubeedges.ManagedByControllerEdgeKind) {
podNode := uncastPodNode.(*kubegraph.PodNode)
// check to see if this pod is managed by more than one RC
uncastOwningRCs := g.SuccessorNodesByEdgeKind(podNode, kubeedges.ManagedByControllerEdgeKind)
if len(uncastOwningRCs) > 1 {
involvedRCNames := []string{}
relatedNodes := []graph.Node{uncastPodNode}
for _, uncastOwningRC := range uncastOwningRCs {
if uncastOwningRC.ID() == rcNode.ID() {
continue
}
owningRC := uncastOwningRC.(*kubegraph.ReplicationControllerNode)
involvedRCNames = append(involvedRCNames, f.ResourceName(owningRC))
relatedNodes = append(relatedNodes, uncastOwningRC)
}
markers = append(markers, osgraph.Marker{
Node: rcNode,
RelatedNodes: relatedNodes,
Severity: osgraph.WarningSeverity,
Key: DuelingReplicationControllerWarning,
Message: fmt.Sprintf("%s is competing for %s with %s", f.ResourceName(rcNode), f.ResourceName(podNode), strings.Join(involvedRCNames, ", ")),
})
}
}
}
return markers
}