Skip to content

Commit

Permalink
iterate through podSpecNode kinds and filter managed nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
juanvallejo committed Oct 18, 2016
1 parent da1c400 commit 298b191
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions pkg/api/kubegraph/analysis/podspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
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"
deploygraph "github.com/openshift/origin/pkg/deploy/graph"
"k8s.io/kubernetes/pkg/util/sets"
)

Expand Down Expand Up @@ -85,7 +86,7 @@ func FindMissingLivenessProbes(g osgraph.Graph, f osgraph.Namer, setProbeCommand

for _, uncastPodSpecNode := range g.NodesByKind(kubegraph.PodSpecNodeKind) {
podSpecNode := uncastPodSpecNode.(*kubegraph.PodSpecNode)
podsWithoutLivenessProbes := CheckForLivenessProbes(g, podSpecNode)
podsWithoutLivenessProbes := CheckForLivenessProbes(podSpecNode)

topLevelNode := osgraph.GetTopLevelContainerNode(g, podSpecNode)
topLevelString := f.ResourceName(topLevelNode)
Expand Down Expand Up @@ -118,7 +119,9 @@ func FindMissingLivenessProbes(g osgraph.Graph, f osgraph.Namer, setProbeCommand
return markers
}

func CheckForLivenessProbes(g osgraph.Graph, podSpecNode *kubegraph.PodSpecNode) []*kubegraph.PodSpecNode {
// CheckForLivenessProbes iterates through all of the containers in a podSpecNode until it finds one
// with a liveness probe set. The list of nodes whose containers have no liveness probe set is returned.
func CheckForLivenessProbes(podSpecNode *kubegraph.PodSpecNode) []*kubegraph.PodSpecNode {
noLivenessProbes := []*kubegraph.PodSpecNode{}

hasLivenessProbe := false
Expand Down Expand Up @@ -184,17 +187,35 @@ func CheckMissingMountedSecrets(g osgraph.Graph, podSpecNode *kubegraph.PodSpecN
return missingSecrets
}

// findNodesManagedByController returns a list of nodes that have "controllerRef" edge kinds directed at them
func findNodesManagedByController(g osgraph.Graph) []graph.Node {
nodeFilter := osgraph.NodesOfKind()
edgeFilter := osgraph.EdgesOfKind(kubeedges.ManagedByControllerEdgeKind)

subGraph := g.Subgraph(nodeFilter, edgeFilter)
managedNodes := []graph.Node{}

// ignore all nodes "controlled" by another node
for _, edge := range subGraph.Edges() {
managedNodes = append(managedNodes, edge.To())
// find and append nodes of ManagedByController and
// Deployment edge kinds, ignoring top-level nodes.
for _, node := range g.NodesByKind(kubegraph.PodSpecNodeKind) {
topLevelNode := osgraph.GetTopLevelContainerNode(g, node)
managedNodes = append(managedNodes, findManagedNodes(g, topLevelNode, g.To(topLevelNode), false)...)
}
return managedNodes
}

// findManagedNodes traverses up from a podSpecNode until it finds parents with no "controllerRef" edge kinds
func findManagedNodes(g osgraph.Graph, node graph.Node, parents []graph.Node, previousEdgeValid bool) []graph.Node {
managedNodes := []graph.Node{}
for _, parent := range parents {
edge := g.Edge(parent, node)
kinds := g.EdgeKinds(edge)

validEdge := kinds.HasAny(kubeedges.ManagedByControllerEdgeKind, deploygraph.DeploymentEdgeKind)
if validEdge && !isNodeInList(node, managedNodes) {
managedNodes = append(managedNodes, node)
managedNodes = append(managedNodes, findManagedNodes(g, parent, g.To(parent), validEdge)...)
} else if previousEdgeValid {
return managedNodes
}
}

return managedNodes
}

Expand Down

0 comments on commit 298b191

Please sign in to comment.