Skip to content

Commit

Permalink
feat: link ingress to target services
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Dec 9, 2024
1 parent 6b3657c commit 73844c0
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion scrapers/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ func ExtractResults(ctx *KubernetesContext, objs []*unstructured.Unstructured) v
}
}

if obj.GetKind() == "Pod" {
switch obj.GetKind() {
case "Pod":
nodeName := getString(obj, "spec", "nodeName")

if nodeName != "" {
Expand All @@ -305,6 +306,31 @@ func ExtractResults(ctx *KubernetesContext, objs []*unstructured.Unstructured) v
v1.ExternalID{ExternalID: nodeExternalID, ConfigType: ConfigTypePrefix + "Node"},
))
}

case "Ingress":
// Link ingress to to target service
if rules, ok, _ := unstructured.NestedSlice(obj.Object, "spec", "rules"); ok {
for _, r := range rules {
if rule, ok := r.(map[string]any); ok {
if paths, ok, _ := unstructured.NestedSlice(rule, "http", "paths"); ok {
for _, p := range paths {
if path, ok := p.(map[string]any); ok {
if service, ok, _ := unstructured.NestedString(path, "backend", "service", "name"); ok {
relationships = append(relationships, v1.RelationshipResult{
ConfigID: string(obj.GetUID()),
Relationship: "IngressService",
RelatedExternalID: v1.ExternalID{
ConfigType: ConfigTypePrefix + "Service",
ExternalID: alias("Service", obj.GetNamespace(), service),
},
})
}
}
}
}
}
}
}
}

if obj.GetNamespace() != "" {
Expand Down

0 comments on commit 73844c0

Please sign in to comment.