Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: service & ingress relationships #1232

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 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 Expand Up @@ -521,6 +547,13 @@ func getKubernetesParent(ctx *KubernetesContext, obj *unstructured.Unstructured)

allParents = append(ParentLookupHooks(ctx, obj), allParents...)

if obj.GetKind() == "Endpoints" {
allParents = append([]v1.ConfigExternalKey{{
Type: ConfigTypePrefix + "Service",
ExternalID: alias("Service", obj.GetNamespace(), obj.GetName()),
}}, allParents...)
}

return allParents
}

Expand Down
Loading