Skip to content

Commit d43f32f

Browse files
committed
update liveness probe check
1 parent 92c5fb5 commit d43f32f

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

pkg/api/kubegraph/analysis/podspec.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,23 @@ func FindMissingLivenessProbes(g osgraph.Graph, f osgraph.Namer, setProbeCommand
8282

8383
for _, uncastPodSpecNode := range g.NodesByKind(kubegraph.PodSpecNodeKind) {
8484
podSpecNode := uncastPodSpecNode.(*kubegraph.PodSpecNode)
85-
topLevelNode := osgraph.GetTopLevelContainerNode(g, podSpecNode)
86-
8785
if hasLivenessProbe(podSpecNode) {
8886
continue
8987
}
88+
89+
topLevelNode := osgraph.GetTopLevelContainerNode(g, podSpecNode)
90+
91+
// skip any podSpec nodes that are managed by other nodes.
92+
// Liveness probes should only be applied to a controlling
93+
// podSpec node, and not to any of its children.
9094
if hasControllerRefEdge(g, topLevelNode) {
9195
continue
9296
}
9397

9498
topLevelString := f.ResourceName(topLevelNode)
9599
markers = append(markers, osgraph.Marker{
96-
Node: podSpecNode,
100+
Node: podSpecNode,
101+
RelatedNodes: []graph.Node{topLevelNode},
97102

98103
Severity: osgraph.WarningSeverity,
99104
Key: MissingLivenessProbeWarning,
@@ -117,17 +122,10 @@ func hasLivenessProbe(podSpecNode *kubegraph.PodSpecNode) bool {
117122
return false
118123
}
119124

120-
// hasControllerRefEdge returns true if a given node contains a "ManagedByController" edge between itself and any of its "To" nodes.
125+
// hasControllerRefEdge returns true if a given node contains one or more "ManagedByController" outbound edges
121126
func hasControllerRefEdge(g osgraph.Graph, node graph.Node) bool {
122-
children := g.From(node)
123-
for _, child := range children {
124-
edge := g.Edge(node, child)
125-
edgeKinds := g.EdgeKinds(edge)
126-
if edgeKinds.Has(kubeedges.ManagedByControllerEdgeKind) {
127-
return true
128-
}
129-
}
130-
return false
127+
managedEdges := g.OutboundEdges(node, kubeedges.ManagedByControllerEdgeKind)
128+
return len(managedEdges) > 0
131129
}
132130

133131
// CheckForUnmountableSecrets checks to be sure that all the referenced secrets are mountable (by service account)

0 commit comments

Comments
 (0)